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. This is Java code for OpenGL ES, but the principles of OpenGL should be the same :).:
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();