Results 1 to 2 of 2
Thread: 2D HUD in JOGL
- 07-19-2011, 02:20 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
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:
Then I put this code inside my display method: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); }
However, nothing displays - if I put a TextRenderer in there and draw text, though, that displays correctly.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);
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 03:55 AM. Reason: Problem solved
- 08-30-2011, 04:52 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 67
- Rep Power
- 0
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
-
Jogl
By Supamagier in forum Advanced JavaReplies: 2Last Post: 12-21-2012, 09:26 AM -
shaders in jogl
By deepthought in forum Java GamingReplies: 0Last Post: 09-29-2010, 01:25 PM -
JOGL lightmapping
By deepthought in forum Advanced JavaReplies: 1Last Post: 06-11-2010, 05:45 PM -
JOGL and texturing
By Archange in forum Java 2DReplies: 0Last Post: 06-06-2008, 02:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks