Thread: Various OpenGL questions

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    22

    Various OpenGL questions

    Since I have several questions at once, I thought I would post them under one thread instead of 3 separate threads.

    Question #1
    I'm not sure how I would use prospective and orthographic at the same time (within one viewport). Or maybe I am not thinking about the problem in the right way, but I am trying to draw 2D and 3D at the same time. For example, having a heath bar overlay while having a 3D scene in the background.

    My current implementation is below:
    Code:
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    //camera setup
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //3D drawing
    
    gluOrtho2D(-1, 1, -1, 1);
    glLoadIdentity();
    //2D drawing
    	
    glutSwapBuffers();
    Question #2
    I am also working with models. I can load the models and textures just find as well as display the mesh. However, the texture comes out as which ever color I have been using previously. My implementation for textures is:

    Code:
    if (!glIsTexture(texture)){return;}
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    glBindTexture(GL_TEXTURE_2D,texture);
    Should I be disabling / enabling a command?
    When I do not use glColor(...) commands the texture works just fine.


    Question #3
    I was also wondering what the best choice is for loading in models with bone structure support. I have ms3d and obj, but I believe 3ds is a fairly good choice (correct me if I am wrong). I was going to go along with ms3d, but I haven't found too many exporters for it so far. If you have a recommendation (that does not require a dll), please provide the site (preferably with an example).


    Thank you for your help!

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    1) gluOrtho2D multiplies an orthographic projection matrix onto the current matrix. Think where it should be put. Remember that the matrix mode indicates which matrix stack is being manipulated.

    2) GL_DECAL does a copy of the texture onto the surface, while GL_MODULATE takes into account lighting, materials and added colors. ( Default OpenGL environment mode is GL_MODULATE )

    3) I haven't worked with models for a while now. Someone else?
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    22
    Thanks for the response, sorry for responding so late.
    For question number one, I placed the projection order in both locations. Where is is right now, the ortho draws are drawn as 3D. However, when applying the ortho draws first before all the other normal projection commands, then the ortho draws correctly, but the other 3D draws are non-existant. Again my goal it to have a 3D scene with cameras while having a 2D overlay on the screen, such as portraying a health bar, or various other non-3D data.

    For question number two. Thanks for the info on GL_MODULATE, I am looking for something very close to that. I need for the texture to take into account of my lighting, but not the blended color. Right now, my model does blend in with which ever color I assigned last. Is there a way to tell it which color to blend to (and by how much).

    Once again, thanks for the response!

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    For the second question, disable or don't enable GL_COLOR_MATERIAL. That should solve your problem.

    For the first:
    My approach is to switch to GL_PROJECTION matrix mode, push an identity matrix, call gluOrtho2D() and switch back to GL_MODELVIEW.
    When done with drawing your 2D graphics, switch to GL_PROJECTION matrix mode again, pop the matrix and switch back to GL_MODELVIEW.
    The first projection matrix should already be filled with your 3D gluPerspective() matrix.

    Don't forget though that even your 2D coordinates are affected by the current GL_MODELVIEW matrix. So remember to push an identity matrix before drawing 2D graphics.
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    22
    There we go, questions number one and two are solved. I also found that setting the blend color to white could also fix the problem with blending to a color.
    If anyone could answer question number 3 that would be great!
    Thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGl questions
    By Shadowwoelf in forum Windows Programming
    Replies: 4
    Last Post: 06-20-2007, 05:35 PM
  2. lots of questions about opengl
    By n3v in forum Game Programming
    Replies: 9
    Last Post: 07-01-2006, 07:32 AM
  3. BMP Loading Questions, More OpenGL!!! :D
    By Shamino in forum Game Programming
    Replies: 13
    Last Post: 05-08-2005, 02:31 PM
  4. Some More Questions About OpenGL:
    By Krak in forum Game Programming
    Replies: 3
    Last Post: 04-29-2003, 06:19 PM
  5. Some OpenGL Questions:
    By Krak in forum Game Programming
    Replies: 7
    Last Post: 04-29-2003, 12:07 AM

Tags for this Thread