views:

38

answers:

1

I noticed that when I'm loading a texture, it might change the current drawing color, depending on the texture's color. For example after executing

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, info.biWidth,
    info.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,bitmap);
glTexParameterf(GL_TEXTURE_2D,
    GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,
    GL_TEXTURE_MAG_FILTER, GL_LINEAR);

all consecutive polygons drawn to the screen will have a color depending on the texture image loaded.

Is that standard? I didn't find this behavior documented.

+3  A: 

Yes, it's how it works, remember that GL is a state machine, so you left the texture bound (and probably enabled), so when drawing it used the first pixel (assuming you didn't provide any texture coordinates) to color the primitive.

To solve it, disable texturing when you don't want texturing, you can do it with:

glDisable(GL_TEXTURE_2D);
Matias Valdenegro
Huh? Isn't it better to just `glColor4f(1.0f,1.0f,1.0f,1.0f)`, instead of disabling the whole texture feature?
Elazar Leibovich
@Matias, thanks, but I'll be glad to see this documented somewhere in the OpenGL standard.
Elazar Leibovich
@Elazar No, using glColor will multiply the texture color with 1.0. This is not directly documented, the only documentation you will find is "GL is a state machine", if textures are enabled, one texture is bound, how do you expect GL to know you don't want textures?
Matias Valdenegro
Another way is just bind the default texture: glBindTexture(GL_TEXTURE_2D, 0);
Matias Valdenegro
To be more accurate, the problem is produced because when you load a texture, you left the loaded texture bound to GL_TEXTURE_2D, if texturing is enabled, GL will use it.
Matias Valdenegro
The thing is, you don't desactivate textures, so openGL will use them. But you don't specify UV coordinates, so they are undefined; probably 0,0, which means an uniform color, the same as your bottom-left texel in the last bound texture
Calvin1602