Results 1 to 2 of 2

Thread: 2D HUD in JOGL

  1. #1
    TrekSoft is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Thumbs up 2D HUD in JOGL

    Hi,

    I've seen topics posted elsewhere about doing a 2D HUD in OpenGL using the orthogonal perspective but I'm having trouble doing it in Java using JOGL.

    Here is what I have so far...

    These are my two methods for switching into and out of the orthogonal mode:

    Java Code:
        public void switchToOrtho(GLAutoDrawable drawable)
        {
            GL2 gl = drawable.getGL().getGL2();
    
            gl.glDisable(GL2.GL_DEPTH_TEST);
            gl.glMatrixMode(GL2.GL_PROJECTION);
            gl.glPushMatrix();
            gl.glLoadIdentity();
            gl.glOrthof(0, drawable.getWidth(), 0, drawable.getHeight(), -1, 1);
            gl.glMatrixMode(GL2.GL_MODELVIEW);
            gl.glLoadIdentity();
        }
    
        public void switchBackToFrustum(GLAutoDrawable drawable)
        {
            GL2 gl = drawable.getGL().getGL2();
    
            gl.glEnable(GL2.GL_DEPTH_TEST);
            gl.glMatrixMode(GL2.GL_PROJECTION);
            gl.glPopMatrix();
            gl.glMatrixMode(GL2.GL_MODELVIEW);
        }
    Then I put this code inside my display method:

    Java Code:
            switchToOrtho(drawable);
    
            gl.glBegin(GL2.GL_QUADS);                  // Begin drawing quads
            gl.glVertex2f(0.0f, 100.0f);         // Top left vertex
            gl.glVertex2f( 100.0f, 100.0f);         // Top right vertex
            gl.glVertex2f( 100.0f,0.0f);         // Bottom right vertex
            gl.glVertex2f(0.0f,0.0f);         // Bottom left vertex
            gl.glEnd();                               // Finish drawing quads
    
            switchBackToFrustum(drawable);
    However, nothing displays - if I put a TextRenderer in there and draw text, though, that displays correctly.

    Does anyone have any ideas what the problem is?

    Thanks,

    David

    EDIT: Someone else saw the problem with my code - apparently, I just needed to draw the vertices in reverse order.
    Last edited by TrekSoft; 07-19-2011 at 04:55 AM. Reason: Problem solved

  2. #2
    Skiller is offline Member
    Join Date
    Jan 2011
    Posts
    67
    Rep Power
    0

    Default

    Quote Originally Posted by TrekSoft View Post
    EDIT: Someone else saw the problem with my code - apparently, I just needed to draw the vertices in reverse order.
    Haha, yer that happens a lot in the early stages of developing game engines, I've fallen for that many times myself, fortunately once you've done it once you usually remember to check the winding order from then on :). These days I just do all my 2D stuff with culling off though, saves the need to check the winding order and nets a slight performance gain too :D.
    Currently developing Cave Dwellers, a Dwarf Fortress/Minecraft style game for Android.

Similar Threads

  1. Jogl
    By Supamagier in forum Advanced Java
    Replies: 2
    Last Post: 12-21-2012, 10:26 AM
  2. shaders in jogl
    By deepthought in forum Java Gaming
    Replies: 0
    Last Post: 09-29-2010, 02:25 PM
  3. JOGL lightmapping
    By deepthought in forum Advanced Java
    Replies: 1
    Last Post: 06-11-2010, 06:45 PM
  4. JOGL and texturing
    By Archange in forum Java 2D
    Replies: 0
    Last Post: 06-06-2008, 03:42 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
  •