Hi. I am a beginner in JOGL and I was trying out some tutorials I got from nehe.gamedev.net (for c / c++)…
I hit a snag when I was doing the 3d shapes tutorial, the tutorial says, that we need to move the drawing point to the loc (-1.5, 0, -6.0), using glTranslatef() func. I tried the same but I am getting just a black screen. I tried the code without changing the drawing point, i.e leaving it at its original place (0, 0, 0), then I could see a very big pyramid rotating. Here is the code. I am using eclipse, with the latest JRE and JOGL library. Can somebody please tell me, what I am doing wrong. Thanks in advance.
import javax.media.opengl.*;
import com.sun.opengl.util.Animator;
import javax.media.opengl.GLEventListener;
import java.awt.*;
import java.awt.event.*;
class SimpleEventListener implements GLEventListener{
float rt;
Animator anim;
public void init(GLAutoDrawable drawable){
GL gl = drawable.getGL();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
rt=0.0f;
anim= new Animator(drawable);
anim.start();
}
public void display(GLAutoDrawable drawable){
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glLoadIdentity();
gl.glTranslatef(-1.5f, 0.0f, -6.0f);
gl.glRotatef(rt, 0.0f, 1.0f, 0.0f);
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f( 0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f(-1.0f,-1.0f, 1.0f);
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f( 1.0f,-1.0f, 1.0f);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f( 0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f( 1.0f,-1.0f, 1.0f);
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f( 1.0f,-1.0f, -1.0f);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f( 0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f( 1.0f,-1.0f, -1.0f);
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f(-1.0f,-1.0f, -1.0f);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f( 0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f(-1.0f,-1.0f,-1.0f);
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f(-1.0f,-1.0f, 1.0f);
gl.glEnd();
rt+=0.2f;
}
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h){}
public void displayChanged(GLAutoDrawable drawable, boolean b1, boolean b2){}
}
public class SimpleTest {
public static void main(String[] args)
{
Frame frame= new Frame("SimpleTest");
GLCanvas canvas= new GLCanvas();
SimpleEventListener listener= new SimpleEventListener();
frame.setSize(640, 480);
frame.add(canvas);
frame.setVisible(true);
canvas.addGLEventListener(listener);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}