Results 1 to 4 of 4

Thread: My HUD Changes color!!!! :(

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Chile
    Posts
    10

    My HUD Changes color!!!! :(

    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!!!

    Next step; the HUD, my fist attempt was to build a simple white rectangle, but a grey one appeared 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

    * 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
    ?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: My HUD Changes color!!!! :(

    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.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: My HUD Changes color!!!! :(

    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.

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Chile
    Posts
    10

    Re: My HUD Changes color!!!! :(

    Thx Bob!!!!!

    As I said it was a stupid newbie problem
    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

Similar Threads

  1. Rainbow color band and color palettes in OpenGL?
    By rakeshthp in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 01-15-2013, 01:57 AM
  2. High color/true color troubles on Win2000
    By Lelik in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-22-2004, 04:39 AM
  3. Drawing color affected by texture color
    By yossi in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 03-14-2001, 03:56 AM
  4. How to show object-color through light-color?
    By jonn in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 01-18-2001, 09:25 PM
  5. color buffer color as source for register combiners
    By Kosta in forum OpenGL: General
    Replies: 1
    Last Post: 07-11-2000, 09:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean