Using JOGL to Draw on 2D Coordinates
Posted by JOGLn00b on Oct 03, 2013; 11:54am
URL: https://forum.jogamp.org/Using-JOGL-to-Draw-on-2D-Coordinates-tp4030146.html
Hi,
I just started to learn JOGL, so i wanted to create some easy 2D Quads. I read about the command gl.glOrtho but it does not work as i expect it to do.
I want to draw the turquoise quad in the back just from the upper left corner to the bottom right (from coordinate (0|0) to (600|800)).
Also in my opinion the red quad should be just in front of the blue one, so you should only see the red one.
I would like to know how to draw on specific coordinates and how to initialize such a coordinate system properly and the orthographic view :)
Thanks for every help :)
@Override
public void display(GLAutoDrawable drawable) {
// TODO Auto-generated method stub
final GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity(); // Reset The View
int x = 100;
int y = 100;
gl.glViewport(0, 0, 800, 600);
gl.glOrtho(0, 800, 0, 600, 0, 128);
x = 800;
y = 600;
gl.glColor3f(0,1,1);;
gl.glBegin (GL2.GL_QUADS);
gl.glVertex3f ( 0, 0, 128.0f);
gl.glVertex3f ( x, 0, 128.0f);
gl.glVertex3f ( x, y, 128.0f);
gl.glVertex3f ( 0, y, 128.0f);
gl.glEnd ();
x = 100;
y = 100;
gl.glColor3f(1,0,0);;
gl.glBegin (GL2.GL_QUADS);
gl.glVertex3f ( 0.0f, 0.0f, 100.0f);
gl.glVertex3f ( x, 0.0f, 100.0f);
gl.glVertex3f ( x, y, 100.0f);
gl.glVertex3f ( 0.0f, y, 100.0f);
gl.glEnd ();
gl.glColor3f(0,0,1);;
gl.glBegin (GL2.GL_QUADS);
gl.glVertex3f ( 0.0f, 0.0f, 110.0f);
gl.glVertex3f ( x, 0.0f, 110.0f);
gl.glVertex3f ( x, y, 110.0f);
gl.glVertex3f ( 0.0f, y, 110.0f);
gl.glEnd ();
gl.glFlush();
}