tags:

views:

42

answers:

1

Hi,

When I bind a specific texture for drawing a quad in OpenGL, it affects all the display : if I use a red BMP file, I see all the screen like if I was wearing red glasses (same for every color : in black I see very dark, in white everything looks almost OK).

This is for texture-mapping fonts, which work well (currently I have only drawn numbers and the rest of the texture is black), but I have this weird behavior on every other surface.

No problem with other BMP files, though. It might come from this BMP file I created, but I had no problem with opening it in various image editors, and I manually check headers and data in my program which look OK.

Anybody has a clue on what could be the problem here ?

Thanks.

edit : this is my code to display a font :

static const GLfloat tfVertices[] = {
    -.5f, -.5f, .1f,
    -.5f,  .5f, .1f,
     .5f, -.5f, .1f,
     .5f,  .5f, .1f
};
GLfloat tfTextureCoords[] = {
     // I compute here the coords of the desired font, that works fine.
     // 4 lines of 2 float values (x, y)
};

glColor4ub(255, 255, 255, 255);
glBindTexture(GL_TEXTURE_2D, FontTextureGLnb); // when removing this (so use default texture instead of the one with fonts) I have no display bug.
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, tfVertices);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, tfTextureCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
+1  A: 

There is no problem, that's how OpenGL works. If you want textures, enabled them, if you don't want textures, disable them. If you set the vertex color state to red, everything will be drawn red until you change that state.

Matias Valdenegro
Thanks, but I am mainly using non-textured surfaces : I use textures only in specific cases and I always call glEnableClientState and glDisableClientState with parameter GL_TEXTURE_COORD_ARRAY around these drawings. And btw I always use glColor4*(...) for setting color.
teupoui
That doesn't disable textures, glEnable/glDisable GL_TEXTURE_2D to do it.
Matias Valdenegro
I am not sure this is the solution. This is compatible with OpenGL ES, so I never use glBegin()/glEnd() with glTexCoord2f(i,j) and glVertex3f(x,y,z). I do not think it should cause a problem. Plus I have a weird lighting bug (probably hardware) on one of the computers I was testing the program that was fixed by enabling GL_TEXTURE_2D, and so far it had no side effect.
teupoui
@teupoui I don't get your comment, i haven't mentioned GL ES or glBegin/glEnd.
Matias Valdenegro
Sorry, what I wanted to say was that disabling GL_TEXTURE_2D could be a solution, but will not fix the original problem. Event with GL_TEXTURE_2D enabled, as long as I do not ask OpenGL to apply texture to things I draw (which is why I gave ou the list of what I used and what I did not), I should not have that kind of side effect. I want to find why in this case I have this weird behavior, as it might affect other things than just textures. Even if my immediate problem is solved like this or by binding another texture, things remain dirty beside the fix, so I want to know what is wrong.
teupoui