PDA

View Full Version : Textures draw as white when using TEXTURE_2D



Vern Jensen
01-11-2012, 03:54 PM
Not sure if this is better in the beginners or advanced area, but here goes:

My game uses GL_TEXTURE_RECTANGLE_EXT to draw textures for a 2D sprite-based game. On systems where this is not supported, it has to use GL_TEXTURE_2D instead.

I was getting blank white rectangles instead of properly drawing textures until I added these calls immediately before creating the texture *and* before drawing it each time a texture is drawn:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

My understanding of these calls is that they should be something you just "set once" and then they should stay in effect. Why is it that I'd have to call these not only before the glTexImage2D() call when first creating the texture, but also before drawing the texture?

(If I call the above calls prior to drawing each texture, they draw blank white the very first time they are drawn, but then draw properly from then on out. This results in a flash of white for each texture the first time it is used.)

This behavior seems strange to me. Was wondering if anyone else could explain it?

(BTW yes, there is code in my game's engine to use power-of-2 textures when using TEXTURE_2D, and also to use proper coordinates from 0.0 to 1.0 instead of from 0 to width/height.)

Vern Jensen
01-18-2012, 03:47 PM
*bump* Anyone?

Forgot to mention, this is while using SDL 1.3. Not sure if that might affect things.

mobeen
01-18-2012, 09:08 PM
My understanding of these calls is that they should be something you just "set once" and then they should stay in effect.

That is correct.



Why is it that I'd have to call these not only before the glTexImage2D() call when first creating the texture, but also before drawing the texture?

You have to only set the min filter once when you create the texture because the default for minification filtering is GL_NEAREST_MIPMAP_LINEAR and if u don't provide mipmaps, it fails.

Could u show us the relevant code here so that we can tell you what is wrong.

Dan Bartlett
01-19-2012, 05:12 AM
You have to add those lines to every texture object, not just once at startup. As mobeen said, the initial value of GL_TEXTURE_MIN_FILTER for a texture object first bound to GL_TEXTURE_2D is GL_NEAREST_MIPMAP_LINEAR (but GL_LINEAR for a texture object first bound to GL_TEXTURE_RECTANGLE_EXT).

I personally think the initial value should have been GL_LINEAR for all texture types, rather than having to require knowledge of every texture type + knowing which use mipmaps + which don't, but too hard to change the initial value now now.



glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, texid);
// set other properties + load images




glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2D, texid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// set other properties + load images