PDA

View Full Version : My HUD Changes color!!!! :(



Titus
07-25-2003, 03:38 PM
Yes, Im newbie
Ive been working with NeHes Tutorials and mixing them with others (perhaps bad idea)

Anyway, I finaly managed to have the infamous spining cube... and textured!!! http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Next step; the HUD, my fist attempt was to build a simple white rectangle, but a grey one appeared http://www.opengl.org/discussion_boards/ubb/frown.gif And when I press "F" (to change the texture of the cube from Nearest to Linear to MipMapping) the grey rectangle changes to a darker one http://www.opengl.org/discussion_boards/ubb/frown.gif

* Nearest -> grey rectangle
* Linear -> dark grey rectangle
* MipMap -> dark grey rectangle

Heres some code:
glGenTextures(3,&texture[0]);
// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
// Create Linear Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
// Create MipMapped Texture
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,GL_RGB,GL_UNSIGNED_BYTE, TextureImage[0]->data);

//That is part of the code that creates the
// textures

int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,z);
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);
glBindTexture(GL_TEXTURE_2D, texture[filter]);
//When you press F "filter" cycles trough
//[0,1,2] ;the textures from above


glBegin(GL_QUADS);
//The six faces of the cube with normals
//and texture coordinates
glEnd();
//*********
//** HUD **
//*********
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
gluOrtho2D (0, 10, 10,0 );
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glVertex2f(0.0f,0.0f);
glVertex2f(0.0f,5.0f);
glVertex2f(10.0f,5.0f);
glVertex2f(10.0f,0.0f);
glEnd();
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
return true;
}

Hope this is some stupid newbie mistake.
Thanks anyway
?

Bob
07-26-2003, 01:55 AM
Since you said the cube was textured, I assume you enable texturing before drawing the cube, although the code doesn't show that. But did you disable texturing before drawing the HUD? If not, the texture will be mapped to the hud aswell.

Bob
07-26-2003, 01:58 AM
Oh, another thing I noticed is your inefficient use of three identical textures. Just upload the texture once and change the filtering mode, not texture ID, when the user press the keys to change filtering. Since you're going to use a mipmapped filter at some point, keep the mipmap version of the texture.

Titus
07-26-2003, 10:43 AM
Thx Bob!!!!! http://www.opengl.org/discussion_boards/ubb/smile.gif

As I said it was a stupid newbie problem http://www.opengl.org/discussion_boards/ubb/biggrin.gif
Anyway, Ill be bothering you guys here prety soon.

BTW I had to enable texture at the begining of DrawGlScene (to draw the cube, duh!) and then disable it before drawing the hud...
That way it works

But is there a problem with performance? I mean, in most cases (with no hud) the texture is enabled in the InitGl function.

Again thanks....
?
P.D.: I just followed the NeHes tutorial, so hes guilty for the "ineficient" use of textures http://www.opengl.org/discussion_boards/ubb/tongue.gif