Orthographic projection issue

Started by
1 comment, last by DavidNysten 12 years, 4 months ago
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
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
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

This topic is closed to new replies.

Advertisement