Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Having trouble with textures in HUD

  1. #1
    Member Contributor
    Join Date
    Oct 2010
    Posts
    52

    Having trouble with textures in HUD

    For some odd reason I can't get my texture to show up on my HUD. Instead I just get a solid color. Does anyone see what's going wrong? Any configurations I could be missing? It works perfectly fine when I render the environment, but it's just not working on the HUD.

    glEnable(GL_TEXTURE_2D);

    glBindTexture(GL_TEXTURE_2D, gGameData.mHUD->mTexID);
    glTexImage2D(GL_TEXTURE_2D, 0, 4, gGameData.mHUD->mW, gGameData.mHUD->mH,
    0, GL_RGBA, GL_UNSIGNED_BYTE, gGameData.mHUD->mData);

    glBegin( GL_QUADS );

    glTexCoord2d(0.0,0.0); glVertex2d(0.0,0.0);
    glTexCoord2d(1.0,0.0); glVertex2d(1.0,0.0);
    glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0);
    glTexCoord2d(0.0,1.0); glVertex2d(0.0,1.0);
    glEnd();
    glFlush();

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: Having trouble with textures in HUD

    change this line
    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, 4, gGameData.mHUD->mW, gGameData.mHUD->mH,
    0, GL_RGBA, GL_UNSIGNED_BYTE, gGameData.mHUD->mData);
    to this
    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gGameData.mHUD->mW, gGameData.mHUD->mH,
    0, GL_RGBA, GL_UNSIGNED_BYTE, gGameData.mHUD->mData);
    Also is your depth test enabled? if so disable depth test before rendering the HUD.
    Regards,
    Mobeen

  3. #3
    Member Contributor
    Join Date
    Oct 2010
    Posts
    52

    Re: Having trouble with textures in HUD

    Still giving me trouble and yes depth test is enabled...

    Also... I noticed that the first thing I call to be drawn is at the front rather than the back? Anything wrong with the following?

    void initGame::setupGUI(int x, int y, int w, int h)

    {

    glViewport(x, y, w, h);

    glMatrixMode(GL_PROJECTION);

    glPushMatrix();

    glLoadIdentity();



    gluOrtho2D(-(float)w/(float)h, (float)w/(float)h, -1.0, 1.0);

    glMatrixMode(GL_MODELVIEW);

    glPushMatrix();

    glLoadIdentity();



    initGame::enableGUI();

    }

    void initGame::takeDownGUI()

    {

    glMatrixMode(GL_PROJECTION);

    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);

    glPopMatrix();

    }

    void initGame::enableGUI()

    {

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    }

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: Having trouble with textures in HUD

    Quote Originally Posted by MrUNOwen
    Still giving me trouble and yes depth test is enabled...

    Also... I noticed that the first thing I call to be drawn is at the front rather than the back? Anything wrong with the following?

    void initGame::setupGUI(int x, int y, int w, int h)

    {

    glViewport(x, y, w, h);

    glMatrixMode(GL_PROJECTION);

    glPushMatrix();

    glLoadIdentity();



    gluOrtho2D(-(float)w/(float)h, (float)w/(float)h, -1.0, 1.0);

    glMatrixMode(GL_MODELVIEW);

    glPushMatrix();

    glLoadIdentity();



    initGame::enableGUI();

    }

    void initGame::takeDownGUI()

    {

    glMatrixMode(GL_PROJECTION);

    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);

    glPopMatrix();

    }

    void initGame::enableGUI()

    {

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    }
    In this code snippet, i dont see where u disable the depth test. It should be called before you are about to render the HUD. Could u post a minimal glut code so it would be better to know what u r trying to do?
    Regards,
    Mobeen

  5. #5
    Member Contributor
    Join Date
    Oct 2010
    Posts
    52

    Re: Having trouble with textures in HUD

    Ooooops, sorry skimmed that last phrase... thought you said it had to be enabled.

    Anyway, the texture is still not showing up, but now it draws in order. So where am I going wrong in terms of the texture?

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: Having trouble with textures in HUD

    Could u post the code where u create the texture. Have u called
    Code :
    glGenTextures(GL_TEXTURE_2D, &gGameData.mHUD->mTexID);
    because from the code snippet u posted earlier i did not see this call.
    And one more thing, have u restored the viewport again since the setupGUI function is setting it.
    Regards,
    Mobeen

  7. #7
    Member Contributor
    Join Date
    Oct 2010
    Posts
    52

    Re: Having trouble with textures in HUD

    This is where I don't have a full understanding of textures. I never made that call and as to how I went about getting the texture, I read in a BMP file and in the case of mTexID, its value is 0 as set by the second argument of my function loadMyTexBMP().

    gGameData.mHUD = loadMyTexBMP("./content/hud/imgBlueBrick.bmp", 0);

    glBindTexture(GL_TEXTURE_2D, gGameData.mHUD->mTexID);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);



    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gGameData.mHUD->mW, gGameData.mHUD->mH,

    0, GL_RGBA, GL_UNSIGNED_BYTE, gGameData.mHUD->mData);

  8. #8
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: Having trouble with textures in HUD

    Quote Originally Posted by MrUNOwen
    This is where I don't have a full understanding of textures. I never made that call and as to how I went about getting the texture, I read in a BMP file and in the case of mTexID, its value is 0 as set by the second argument of my function loadMyTexBMP().

    gGameData.mHUD = loadMyTexBMP("./content/hud/imgBlueBrick.bmp", 0);

    glBindTexture(GL_TEXTURE_2D, gGameData.mHUD->mTexID);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);



    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gGameData.mHUD->mW, gGameData.mHUD->mH,

    0, GL_RGBA, GL_UNSIGNED_BYTE, gGameData.mHUD->mData);
    Hmm thats where ur problem is. You have to ask opengl to generate a texture id for u by making a call to
    Code :
    GLuint texID;
    glGenTextures(1, &texID);
    Then u will pass this texID to glBindTexture and do the other stuff u showed earlier. So to make ur code to work do this.
    Add a new global variable texID like this,
    Code :
    GLuint texID;
    and then make ur calls as follows
    Code :
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &texID);
    gGameData.mHUD = loadMyTexBMP("./content/hud/imgBlueBrick.bmp", texID);
     
    glBindTexture(GL_TEXTURE_2D, gGameData.mHUD->mTexID);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gGameData.mHUD->mW, gGameData.mHUD->mH,0, GL_RGBA, GL_UNSIGNED_BYTE, gGameData.mHUD->mData);
    See if this helps.
    Regards,
    Mobeen
    Regards,
    Mobeen

  9. #9
    Member Contributor
    Join Date
    Oct 2010
    Posts
    52

    Re: Having trouble with textures in HUD

    Still doesn't work, I get a solid color still. Other than having texture disabled, what else would cause a texture not to not show up.

  10. #10
    Member Newbie
    Join Date
    Jan 2011
    Location
    Lincoln, UK
    Posts
    36

    Re: Having trouble with textures in HUD

    Can you post your most recent code?

    Dale

Page 1 of 2 12 LastLast

Similar Threads

  1. Trouble with loading textures.
    By geomazzix in forum OpenGL: Basic Coding
    Replies: 20
    Last Post: 12-15-2017, 01:19 AM
  2. Trouble loading textures with glimg
    By Ygyaxthe3rd in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-28-2013, 01:27 PM
  3. Trouble with creating / drawing textures.
    By Wopple in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-06-2011, 09:09 AM
  4. Trouble creating chessboard with textures.
    By thealmightyone in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-30-2009, 09:05 AM
  5. Trouble with Textures and Materials
    By Erfdain in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-05-2005, 04:57 PM

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