c++ - OpenGL PBO update texture wrong width height data -


i have simple program trying use pbo update sub texture data dynamic generated. problem correct order of data in texture because gets inverted or not stored in correct order.

here code initializing, data input , draw function

////////////////////////////////////////////////////////////////////////// //globals #define tex_width 512 #define tex_height 2048  gluint renderedtexture; gluint pbo_id; glubyte* pbo_memory = 0; 

initialization:

void initialize()  {     int w = 1024; //screen width     int h = 1024; //screen height      glviewport( 0, 0, w, h );     glmatrixmode( gl_projection );     glloadidentity();     gluortho2d(0, w, h, 0);      glmatrixmode( gl_modelview );     glloadidentity();      glgentextures(1, &renderedtexture);      glbindtexture(gl_texture_2d, renderedtexture);      //here internal format rgba , input format not sure.     //idea put glushort red channel input only.      glteximage2d(gl_texture_2d, 0, gl_rgba, tex_width , tex_height, 0, gl_red, gl_unsigned_short, 0);     std::cout << "error = \n" << glgeterror();      gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_nearest);     gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_nearest);      glgenbuffers(1, &pbo_id);     glbindbuffer(gl_pixel_unpack_buffer, pbo_id);      // correct initialization of buffer size , access type???     glbufferdata(gl_pixel_unpack_buffer, tex_width * tex_height * sizeof(glushort), 0, gl_stream_draw);      glbindbuffer(gl_pixel_unpack_buffer, 0); } 

and draw function. i make vertical lines rendered horizontal why?

void display() {        if(pbo_memory == 0)     {         // pointer memory         glbindbuffer(gl_pixel_unpack_buffer, pbo_id);         pbo_memory = reinterpret_cast<glubyte*>(glmapbuffer(gl_pixel_unpack_buffer,              gl_write_only /*| gl_map_flush_explicit_bit*/));         glunmapbuffer(gl_pixel_unpack_buffer);         glbindbuffer(gl_pixel_unpack_buffer, 0);     }     else     {         //make lines          /*             +-------+             | | | | |             | | | | |             | | | | | 2048             | | | | |             | | | | |             | | | | |             +-------+                512                           */         (int = 0; < tex_width; ++i)         {             if( % 64 == 0 && > 2)             {                 glubyte* _data = &pbo_memory[i*tex_height*2];                 glubyte* _data_prev = &pbo_memory[(i-1) *tex_height*2 ];                 glubyte* _data_prev1 = &pbo_memory[(i-2) *tex_height*2];                 glubyte* _data_next = &pbo_memory[(i+1) *tex_height*2];                 glubyte* _data_next1 = &pbo_memory[(i+2) *tex_height*2];                 (int j = 0; j< tex_height*2;++j)                 {                     _data[j] = 255;                     _data_prev[j] = 255;                     _data_next[j] = 255;                     _data_prev1[j] = 255;                     _data_next1[j] = 255;                 }             }             else                 memset( &pbo_memory[i*tex_height*2], 0, tex_height * 2);         }     }      glviewport(0,0,1024,1024);     glclearcolor(0,0,0.5,1);     glclear(gl_color_buffer_bit);      glenable(gl_texture_2d);       glfloat m_texwidth = 256;   //512/2     glfloat m_texheight = 1024; // 2048/2     glfloat tw = 1.0;     glfloat th = 1.0;      glbindtexture(gl_texture_2d, renderedtexture);     glbindbuffer(gl_pixel_unpack_buffer, pbo_id);      gltexsubimage2d(gl_texture_2d,              0,             0,             0,              512,              2048 ,              gl_red,             gl_unsigned_short,             0);      glbindbuffer(gl_pixel_unpack_buffer, 0);      assert(glgeterror() == 0);       glbegin(gl_quads);         gltexcoord2f(0.0f, th);         glvertex2f( (glfloat)0,             (glfloat)0 );          gltexcoord2f(tw, th);         glvertex2f( (glfloat)m_texwidth,             (glfloat)0 );          gltexcoord2f(tw, 0.0f);         glvertex2f( (glfloat)m_texwidth,             (glfloat)m_texheight);          gltexcoord2f(0.0f, 0.0f);         glvertex2f( (glfloat)0,             (glfloat)m_texheight);     glend();      // swap front , buffers     glutswapbuffers(); } 

so why vertical lines become horizontal can change data correctly uploaded graphic card. using amd radeon.


Comments

Popular posts from this blog

c# SetCompatibleTextRenderingDefault must be called before the first -

c++ - Fill runtime data at compile time with templates -

C#.NET Oracle.ManagedDataAccess ConfigSchema.xsd -