glTexImage2D causes problem to opengl color

Hi,
in my project i load a bitmap image and then i put it into a texture using glTexImage2D. After i do this, when i draw something e.x a circle, i use black color it is black, if i try any other color the results are not what they should be. For example if i draw white the output color is dark red (that depends on the colors of the image). This seems unreasonable but maybe you know something i dont.

when the image has only black and white colors i have no problem. The problem occures when i load a coloured image.

The code i use to load the image is not mine, i found it ready but i dont think its the problem cause i tried other codes with the same result.

with this code i make it a texture
ImageLoad(“bitmap.bmp”, in_image);

glGenTextures(1, &texture[2]);

glBindTexture(GL_TEXTURE_2D, texture[2]);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexImage2D(GL_TEXTURE_2D, 0, 4, in_image->sizeX, in_image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, in_image->data);

free(in_image->data);
free(in_image);

So if i try to draw a white rectangle like this
glBegin(GL_QUADS);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(0.0f,size_winy,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(size_winx,0.0f,0.0f);
glVertex3f(size_winx,size_winy,0.0f);
glEnd();

some other color is drawn(depending on the image).

If you can help me understand why is that and fix it, i’ll be very gratefull.
Thanx

Hi,

Try using GL_BGR(A)_EXT as your source format for glTexImage2D.

Using this format caused the texture to invert colors. Now the if the image is red it becomes blue. Anyway this didnt solve the problem since now when i draw white it comes out as dark blue

I see. Well, just so you know, bmp images are stored in BGR(A) format, so GL_RGB won’t work as an source format for glTexImae2D, unless you byte-swap the data before uploading. This may not be your only problem, but it’s probably among them, unless there’s more going on behind the scenes.

It seems that i just had to add
glBindTexture(GL_TEXTURE_2D,0);
before drawing anything because it binds the texture and draws it with the polygons. I’m not sure why is that since i didnt bind it anywhere but that did the trick:)
Thanks anyway

Always glad to help a citizen.

glDisable(Gl_TEXTURE2D)

Originally posted by blueepl:
It seems that i just had to add
glBindTexture(GL_TEXTURE_2D,0);
before drawing anything because it binds the texture and draws it with the polygons. I’m not sure why is that since i didnt bind it anywhere but that did the trick:)
Thanks anyway

What about this line of your code?

glBindTexture(GL_TEXTURE_2D, texture[2]);

To create the texture you have to bind it…