Archived

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

Plasmite

GL_RGBA textures

Recommended Posts

So, I have generated an texture with alpha channel. To keep things simple, the image data is full of zeros. So, it''s a black image with zero alpha all over it. For some reason, when I draw it on to the screen, it appears as completely white. I understood, that it''s enough if I enable blending, and then bind a texture with a alpha channel. Is there something else to it? Like enabling alpha channels in texture or something like that....... to be more accurate, I do it like this: glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); and the data was full of zeros. then: glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, tex); glBegin(GL_QUADS); glColor4f(1, 1, 1, 1); glTexCoord2f(......); glVertex2f(......);............ glEnd(); And the result is a completely white square. ??

Share this post


Link to post
Share on other sites
oh, I forgot. I also had this in my code:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
If that was what you meant Brother Bob.

So, what''s wrong now?

Share this post


Link to post
Share on other sites
Yup, that''s it. So, do you have an active rendering context at the time you''re creating the texture then?

And by the way, you do set the filters for the correct texture, right? I mean, first you bind the correct ID, then set it. glTexParameter are states per texture object, so the filter is set for the currently active texture on the currently active texture unit (texture units are an issue only when using multitexturing).

Share this post


Link to post
Share on other sites
I have it like in the NeHe-tutorials
glBindTexture(...
glTexParameteri(....
glTexParameteri(...
glTexImage2D(......
So filters go for correct textures.

Do I have an active rendering context at the time I''m creating my textures? ööööhhhhhh.... I guess I do. I''ve already created other textures, and my program draws them on the screen for couple of minutes before it starts to create these alpha-channel-textures.

Should that cause problems?

Share this post


Link to post
Share on other sites
Seems like we can forget about the most common mistakes at least.

Next thing to check would be the texture environment functions (glTexEnv). Make sure you combine the texture the way you want.

Try set the combine function to GL_REPLACE, and change the primary color from white to something else. If the texture is invalid for some reason, the color you get should be whatever the primary color is. If the texture is valid, you should get what''s in the texture.

You should also put lots of glGetError in your code and step through it with a debugger. If there''s an error somewhere, locate the exact function casuing the error, and look up some documentation what can cause that error.

Share this post


Link to post
Share on other sites