Archived

This topic is now archived and is closed to further replies.

cmdkeen

glTexSubImage2D causing artifacts

Recommended Posts

cmdkeen    166
Hello, there's a strange problem with glTexSubImage2D in my app: it seems like it doesn't properly update my texture. I have an array GLubyte pixels[width][height][3] which contains my pixels data. Each frame I change it and update my texture this way:
  
glBindTexture( GL_TEXTURE_2D, tex_handle );
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex_width, tex_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels );
  
Then a bunch of quads are rendered and textured with my texture. The problems is as follows: When the whole thing appears on the screen, some of my quads still contain the originally texture as it was when I firstly created my texture. If I replace glTexSubImage2D with gluBuild2DMipMaps everything shows up fine. Unfortunately its a bit slow then. The texture is initially created this way:
        
CreatePixelData(); // create initial pixel data

glGenTextures( 1, &tex_handle );
glBindTexture( GL_TEXTURE_2D, tex_handle );
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, tex_width, tex_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
  
For testing I make my texture yellow and then let it fade out slowly. The result is that many quads remain the originally color while others fade out. The ones that are displayed yellow change each frame. (Thus one frame quad 1 is yellow, the next frame it's dark again, some frames later being yellow again...) [I found a similar question that was asked in the DirectX forum of this board but it wasn't answered.] Can anyone help me ? Edited by - cmdkeen on January 29, 2002 2:25:42 PM

Share this post


Link to post
Share on other sites
Myopic Rhino    2315
It''s probably because you''re using mipmapping. When you update the texture with the call to glTexSubImage2D, you''re only updating the base level (0). All the other levels will remain what they were before. So, the quads that end up using mipmap level 0 will use the new texture, and the others will use the original.

Share this post


Link to post
Share on other sites
cmdkeen    166
Thanks for your reply myopic.
Yes, I thought about it but then discarded the idea because all my polygons are on one layer (vertices are made using glVertex2d). But when I reconsider it there might arise problems due to inaccuracies .

I tried updating all mipmap levels simply by calling glTexSubImage3D for levels 0-3 but it had no effect.

I''m pretty new to OpenGL so can you tell me how to disable mip mapping ? Any better way to create my texture ? I do not set any mip mapping related attributes of OpenGL. Shouldn''t it be disabled ?

Share this post


Link to post
Share on other sites
Myopic Rhino    2315
To use mipmapping, you just need to set up all the levels (gluBuild2DMipmaps does that for you, or you can do it manually) and set the filtering method to use one of the mipmap modes. There''s not a state setting for it.

If you don''t want to use mipmapping, just create your texture with glTexImage2D instead of gluBuild2DMipmaps.

Share this post


Link to post
Share on other sites