Noob question: How to draw HUD with glOrtho?

Started by betwixt666, February 08, 2010, 17:55:21

Previous topic - Next topic

betwixt666

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();




betwixt666

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 );