Jump to content
  • Advertisement
Sign in to follow this  
DavidNysten

Orthographic projection issue

This topic is 2571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everybody,

I have a 3D environment, created with JOGL (I'm using Eclipse) and now I want to create a simple 2D menu that the user can open by pressing "esc".

So I was thinking of using the orthographic projection. As I never used that projection, I tried looking up some sample code, but it just shows a black screen.


GL2 gl = (GL2) drawable.getGL();

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glOrtho(0, 500, 500, 0, 0, 1);
gl.glScalef(1, -1, 1);
gl.glTranslatef(0, -500, 0);
gl.glMatrixMode(GL2.GL_MODELVIEW);

gl.glColor3d(1.0, 1.0, 0.0);
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(125, 125);
gl.glVertex2f(125, 375);
gl.glVertex2f(375, 375);
gl.glVertex2f(375, 125);
gl.glEnd();

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL2.GL_MODELVIEW);


This is where I got the example code from: http://www.swiftless.com/tutorials/

Or do I need to search the mistake somewhere else?

Kind regards,
Dave

Share this post


Link to post
Share on other sites
Advertisement

Hey everybody,

I have a 3D environment, created with JOGL (I'm using Eclipse) and now I want to create a simple 2D menu that the user can open by pressing "esc".

So I was thinking of using the orthographic projection. As I never used that projection, I tried looking up some sample code, but it just shows a black screen.


GL2 gl = (GL2) drawable.getGL();

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glOrtho(0, 500, 500, 0, 0, 1);
gl.glScalef(1, -1, 1);
gl.glTranslatef(0, -500, 0);
gl.glMatrixMode(GL2.GL_MODELVIEW);

gl.glColor3d(1.0, 1.0, 0.0);
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(125, 125);
gl.glVertex2f(125, 375);
gl.glVertex2f(375, 375);
gl.glVertex2f(375, 125);
gl.glEnd();

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL2.GL_MODELVIEW);


This is where I got the example code from: http://www.swiftless.com/tutorials/

Or do I need to search the mistake somewhere else?

Kind regards,
Dave


try gl.glTranslatef(0, -500, -1); instead of gl.glTranslatef(0, -500, 0); right now you are rendering it at the viewer and not in front of it.

also I would use glColor3f not glColor3d

Share this post


Link to post
Share on other sites
Hey,

Thanks a lot. I changed the Translatef and also removed my gluLookAt (I kinda forgot to comment it out somewhere else). Works perfectly now. ;)

Regarding the Color3f instead of Color3d, is there a reason why you prefer one over the other?

Kind regards,
Dave

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!