HUD Questions (OpenGL 3)

Started by 8Bit_Jedi, July 17, 2013, 10:37:50

Previous topic - Next topic

8Bit_Jedi

Hello everybody,

Just your thoughts on my method of rendering my HUD.

Pseudo steps I take to draw HUD: (Everything is in the main game loop)

  • Load textures (Out of game loop)
  • Load shaders  (Out of game loop)
  • Create Quads
  • Turn on shaders (GL20.glUseProgram(pId);)
  • Turn off depth test (GL11.glDisable(GL11.GL_DEPTH_TEST);)
  • Draw HUD elements and text
  • Turn on depth test (GL11.glEnable(GL11.GL_DEPTH_TEST);)
  • Turn off shaders (GL20.glUseProgram(0);)

My Questions are:

  • Should OpenGL capabilities like depth test be turned on off within your main game loop or is that insufficient, the reason I do this is to make sure nothing else goes on top of HUD?
  • Do I need to specify the depth function again or is once in my renderer fine (GL11.glDepthFunc(GL11.GL_LEQUAL);)?

If I am way out of the ballpark here tell me plz, are there any better ways to handle the HUD staying on top of everything.

Also any tutorials on HUD/Text creation would be helpful, I am soon going to have to implement "drag 'n drop" functionality.

Goodbye everybody.

Fool Running

1) It doesn't really matter where you turn on/off stuff. Maybe put it in a place that makes it easy to remember what you did and reverse if if needed. If its easier to remember in the main loop, then put it there, otherwise keep it where it is. :)
2) Just once is fine as long as you never need to change it. OpenGL will remember it for as long as the OpenGL context is available.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

8Bit_Jedi

Thankyou,

Looking back with hind-sight question (2) was kinda dumb since I know OpenGL is a state machine and will keep the state set with DepthFunc().

Was checking this 'ol link, always do when I am not sure: http://www.opengl.org/wiki/Common_Mistakes, section Disable depth test and allow depth writes

It said: "The correct solution is to tell GL to ignore the depth test results with glDepthFunc(GL_ALWAYS)"

So I replaced my calls of glDisable(GL_DEPTH_TEST) and glEnable(GL_DEPTH_TEST) to glDepthFunc(GL_ALWAYS) and glDepthFunc(GL_LESS) respectively. Same results HUD and text still on top of everything which is good, but still feel that mucking about with OpenGL functions like that in the game loop might cause a small performance hit, but can't think of anything else.