Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL: Loading a texture changes the current color

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.

like image 337
Elazar Leibovich Avatar asked Aug 04 '10 13:08

Elazar Leibovich


1 Answers

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);
like image 195
Dr. Snoopy Avatar answered Nov 02 '22 19:11

Dr. Snoopy