Newbie: Why can't I see my results ?

Hi,

I’m new to OpenGL and JOGL…
I’ve got a GLJPanel (400x400) to render, with a GLEventListener attached to it. I have a


while( true ){ panel.display(); }

and my Listener has (stripped out basics):


init(){
      gl.glViewport(0, 0, 200, 200); 
      gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}

display(){
       gl.glRotatef( 0.6f, 0.0f,0.0f,1.0f );
       
       gl.glBegin( GL.GL_QUADS );
       gl.glColor3f(1.0f,0.1f,0.1f);
       gl.glVertex3f(-0.6f,-0.6f,0.0f);
       gl.glColor3f(0.1f,0.1f,0.1f);
       gl.glVertex3f(0.6f,-0.6f,0.0f);
       gl.glColor3f(0.1f,0.1f,1.0f);
       gl.glVertex3f(0.6f,0.6f,0.0f);
       gl.glColor3f(1.0f,0.1f,1.0f);
       gl.glVertex3f(-0.6f,0.6f,0.0f);
       gl.glEnd();
}

But all I get is a black Panel with nothing in it…
When I add a


gl.glTranslatef(0.0f, 0.0f,-0.1f);

The quad will show up after about 100 frames…
It seems that at first the quad is bigger than the frame and can’t be displayed…

Where did I make the mistake ?

Thanks a lot !
Peter

You need to set up your projection and modelview matrices using for example gluPerspective and gluLookAt. Additionally you should probably enable GL_DEPTH_TEST and you should clear the color and depth buffers in your display() callback. Please look at the source code for the Gears demo for a relatively simple example of a rendering loop.

Thanks for the input !
My mistake was something completly different… For my example, I took code from several sources and there I had some code in the reshape method which changed my Perspective (or at least it looks like that…)
I’ll definitely have to read the documentation and study the examples for the next time !
Do you have any good book you could recommend to someone new to JOGL & OpenGL ?

Thanks a lot !
Peter

The OpenGL Programming Guide (“Red Book”) is the canonical OpenGL reference. I don’t know whether it’s the best introductory book if you’re new to 3D graphics but it’s a good start. All of the code contained within converts over to JOGL pretty easily. JOGL looks more or less like GLUT which is used in most of the examples. There are a couple of chapters of books and books specifically on JOGL but I think the OpenGL red book is a better reference on core OpenGL.