Hi,
I’m currently using JOGL ver. 1.1.1 and it seems to me that it calls method display(GLAutoDrawable) only once, whereas the code for C calls it every time it loops. Here is my code:
this is in Main.java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import javax.media.opengl.*;
import javax.swing.*;
/**
*
* @author ramon
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JFrame frame = new JFrame("Jogl Test");
frame.setSize(640,480);
frame.setResizable(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GLCanvas canvas = new GLCanvas();
SimpleJogl glevent = new SimpleJogl();
canvas.addGLEventListener(glevent);
frame.add(canvas);
frame.setVisible(true);
}
}
this is in SimpleJogl.java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
/**
*
* @author ramon
*/
public class SimpleJogl implements GLEventListener {
public SimpleJogl() {
}
public void init(GLAutoDrawable glad) {
GL gl = glad.getGL();
gl.setSwapInterval(1);
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}
public void display(GLAutoDrawable glad) {
GL gl = glad.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(rtri, 0.0f, 1.0f, 0.0f);
gl.glBegin(GL.GL_TRIANGLES); // Drawing Using Triangles
gl.glColor3f(1.0f, 0.0f, 0.0f); // Set the current drawing color to red
gl.glVertex3f( 0.0f, 1.0f, 0.0f); // Top
gl.glColor3f(0.0f, 1.0f, 0.0f); // Set the current drawing color to green
gl.glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
gl.glColor3f(0.0f, 0.0f, 1.0f); // Set the current drawing color to blue
gl.glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
gl.glEnd(); // Finished Drawing The Triangle
gl.glLoadIdentity();
gl.glTranslatef(1.5f, 0.0f, -6.0f);
gl.glRotatef(rquad, 1.0f, 0.0f, 0.0f);
gl.glBegin(GL.GL_QUADS); // Draw A Quad
gl.glColor3f(0.5f, 0.5f, 1.0f); // Set the current drawing color to light blue
gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
gl.glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
gl.glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
gl.glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
gl.glEnd(); // Done Drawing The Quad
gl.glFlush();
rtri += 0.2f;
rquad += 0.15f;
}
public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
final GL gl = glad.getGL();
GLU glu = new GLU();
if (height <= 0) // avoid a divide by zero error!
height = 1;
final float h = (float)width / (float)height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void displayChanged(GLAutoDrawable glad, boolean bln, boolean bln1) {
}
private float rquad = 0.0f;
private float rtri = 0.0f;
}
I’d like to see the triangle rotating always.
Please help!