glTexSubImage2D problems

the following code is used to draw a black transparent square hole into a 2d (to simulate bits of level getting blown up!).

the problem is: the level remains unchanged

//vars: l, r, t, b (left, right, top, bottom) are long’s and are definately within the bounds of the texture

unsigned char* pixel = NULL;
for(int x=l; x<r; ++x)
{
for(int y=t; y<b; ++y)
{
pixel = &m_image->Bytes[(ym_image->Widthm_image->BytesPerPixel) + (x*m_image->BytesPerPixel)];
*(pixel+0) = 0;
*(pixel+1) = 0;
*(pixel+2) = 0;
*(pixel+3) = 0;
}
}

glBindTexture(GL_TEXTURE_2D, m_maintexture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_image->Width, m_image->Height, GL_RGBA, GL_UNSIGNED_BYTE, m_image->Bytes);
//gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, m_image->Width, m_image->Height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, m_image->Bytes);

if i use the commented gluBuild2DMipMaps line instead of texsubimage, it works (but is slooooow) which verifies the validity of m_image.

im not concerned with any optimisations for now - just getting it working at a decent speed (ie not using build2dmips func).

Why don’t you use SubImage to put that black square where you want it? Something like:

glTexSubImage2D(GL_TEXTURE_2D, 0, l, b, r-l, t-b, GL_RGBA, GL_UNSIGNED_BYTE, array-of-zeroes);

If you don’t call gluBuild2DMipmaps(), only your top-level texture will have the hole in it, and your mipmaps will remain unchanged. Chances are that you’re not seeing the change because it’s not using the top-level mipmap.

You could try copying the hole to your mipmaps with glTexSubImage2D() as well. Don’t forget to scale it, though

  • Tom

Originally posted by Won:
[b]Why don’t you use SubImage to put that black square where you want it? Something like:

glTexSubImage2D(GL_TEXTURE_2D, 0, l, b, r-l, t-b, GL_RGBA, GL_UNSIGNED_BYTE, array-of-zeroes);[/b]

the image that im blitting is different for every weapon, and is either generated at run time (eg: filled circles) of is read from a targa’s alpha channel.

i thought i could generate a small copy of the main texture, draw blackness to that then use subimage to put the new copy back on to the main texture, but it seems like a waste of time when i could simply draw directly to the main texture.

oh, btw: i am only subimaging the entire image temporarily - eventually, i will only update the part that needs updating…

If you don’t call gluBuild2DMipmaps(), only your top-level texture will have the hole in it, and your mipmaps will remain unchanged. Chances are that you’re not seeing the change because it’s not using the top-level mipmap.

i’ll try that and post the results.

Originally posted by Yorvik:
i’ll try that and post the results.

i tried using subimage on a few mipmaps, no effect

the texture is created using min/mag GL_LINEAR - and im only using gluBuild2DMipMaps because glTexImage2D produces a white (null) image (the texture data is read from a 32bit targa)

i have no need for mipmaps since the game is 2D, but im stuck using build2dmips at the moment

im stumped (its probably something real simple that i’ll kick myself for when it is solved!)

[This message has been edited by Yorvik (edited 02-15-2001).]

i posted a demo of this project here:
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/002082.html

maybe this will describe the problem better

What is the width and height of your texture? If they are not a power of 2, you will not be able to load them using glTexImage2D. gluBuild2DMipMaps will automatically resize the images to powers of two for you. So… if your image doesn’t have dimensions in a power of two, glTexImage2D won’t work but gluBuild2DMipMaps will.

640x480 - thats it! DOH i knew it would be something bollocks like that.