Axelrod360
Axelrod360

Reputation: 113

Getting started with JOGL cube issue

I am new to JOGL but I am having trouble with the basics. I think it is something to do with the camera angle but Im not sure. I do not even know if all this code is even necessary or if I need more.

It makes the last drawn sides overlap the first ones (if the back was drawn after front, the back overlaps front). It might have something to do with the depth or refreshing a variable after each frame.

The axes are supposed to go through the center of the cube but the cube gets cut off for some reason and does not display the sides correctly. The coordinates at the top are the cameras "eye" position (floats relating to gluLookAt() first 3 parameters). The cube is .5X.5X.5 centered around 0,0,0 (therefore extending .25 off each axis).

I cant post photos yet so here are my screenshots: http://www.flickr.com/photos/64158328@N02/sets/72157628882982925/

I am extending JFrame and implementing GLEventListener. This is my OpenGL code from my constructor:

GLCapabilities caps = new GLCapabilities(null);
caps.setRedBits(8);
caps.setGreenBits(8);
caps.setBlueBits(8);
caps.setAlphaBits(8);
caps.setDoubleBuffered(false);
caps.setHardwareAccelerated(true);

GLCanvas canvas = new GLCanvas(caps);
canvas.addGLEventListener(this);
canvas.addKeyListener(this);
add(canvas, BorderLayout.CENTER);

anim = new FPSAnimator(canvas, 60);
anim.setUpdateFPSFrames(10, null);
anim.start();

display method (along with the cube and axis code):

GL2 gl = drawable.getGL().getGL2();
gl.glLoadIdentity();
GLU glu = new GLU();
glu.gluLookAt(eyeX, eyeY, eyeZ, 0, 0, 0, 0, 1, 0); // sets camera angle
gl.glClear(GL.GL_COLOR_BUFFER_BIT);

init method:

GL2 gl = drawable.getGL().getGL2();
gl.glClearColor(0, 0, 0, 0);
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(-1, 1, -1, 1, -1, 1);

reshape method:

GL2 gl = drawable.getGL().getGL2();
gl.glViewport(0, 0, width, height);

Upvotes: 1

Views: 663

Answers (1)

Axelrod360
Axelrod360

Reputation: 113

I got it, I need to enable GL_DEPTH_TEST and I need to rotate the world around the camera using glRotatef() and glTranslatef() instead of using gluLookAt() to move the camera around the world.

Upvotes: 2

Related Questions