lwjgl.org
March 22, 2010, 11:57:46 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Noob question: How to draw HUD with glOrtho?  (Read 266 times)
betwixt666
Newbie
*
Posts: 6


« on: February 08, 2010, 18:55:21 »

Hi, I want to draw a healt bar to the top of my screen and then to scale it based on how much health I have left.

I found 2 functions that enable me to switch from projection to 3d drawing:
   private void viewOrtho(GL10 gl, int x, int y){                     // Set Up An Ortho View   
      gl.glMatrixMode(gl.GL_PROJECTION);               // Select Projection
      gl.glPushMatrix();                     // Push The Matrix
      gl.glLoadIdentity();                  // Reset The Matrix
      gl.glOrthof( 0, x , y , 0, -1, 1 );            // Select Ortho Mode
      gl.glMatrixMode(gl.GL_MODELVIEW);               // Select Modelview Matrix
      gl.glPushMatrix();                     // Push The Matrix
      gl.glLoadIdentity();                  // Reset The Matrix
   }

   private void viewPerspective(GL10 gl)                     // Set Up A Perspective View
   {
      gl.glMatrixMode( gl.GL_PROJECTION );               // Select Projection
      gl.glPopMatrix();                     // Pop The Matrix
      gl.glMatrixMode( gl.GL_MODELVIEW );               // Select Modelview
      gl.glPopMatrix();                     // Pop The Matrix
   }

Then I use them to draw a cross in the middle of the screen in the main loop

           viewOrtho(gl, width,height);   //Starting to draw the HUD
      gl.glScalef(0.025f, 0.005f, 0.0f); //Have to scale it otherwise the screen would be filled with it   
      square.draw(gl);    //Draw horizontal line
      gl.glLoadIdentity();
      gl.glScalef(0.005f, 0.025f, 0.0f);    
      square.draw(gl);   //Draw vertical line
                viewPerspective(gl); //switch back to 3D drawing

I tried placing gl.glTranslatef to different places, but the + would still be drawn in the middle of the screen and glrotatef won't rotate it either. I want do move it to a corner of the screen.

How can I do that? And why isn't the glTranslate moving it? Can you give me to some other examples? A la
gl.glThisAndThis()
    gl.glTranslatef(TopRightCorner.x, TopRightCorner.y, 0.0f);
    drawYourHUDsTuff();



Logged
betwixt666
Newbie
*
Posts: 6


« Reply #1 on: February 09, 2010, 08:08:24 »

I now know what I did do wrong. I had to put gl.glOrthof( 0, x , 0 , y, -1, 1 ); not gl.glOrthof( 0, x , y , 0, -1, 1 );   
Logged
lwjgl.org
   



 Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!