I am trying to write one or two of the examples from http://nehe.gamedev.net/ . The code that I have come up with works fine, except that the triangle seems to stick to the edges at certain window dimensions, and then pops into the right location. I have written an equivalent version in C and that seems to work fine. I am trying this with the latest ‘release’ for MacOS X, which is ’ 1.1.1 - July 12’. Any suggestions as to what could be wrong? Here is the code:
package lesson02;
import net.java.games.jogl.*;
import java.awt.*;
public class Lesson02 extends Panel implements GLEventListener {
public Lesson02 () {
GLCapabilities capabilities = new GLCapabilities();
GLCanvas canvas =
GLDrawableFactory.getFactory().createGLCanvas(capabilities);
canvas.addGLEventListener(this);
setLayout(new BorderLayout());
add(canvas);
}
public void init(GLDrawable drawable) {
}
public void display(GLDrawable drawable) {
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
gl.glLoadIdentity(); // Reset The Current Modelview Matrix
gl.glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
gl.glBegin (GL.GL_TRIANGLES);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f( 0.0f, 1.0f, 0.0f); // Top
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
gl.glEnd(); // Finished Drawing The Triangle
//canvas.swapBuffers();
}
public void reshape(GLDrawable drawable, int x, int y, int width, int height) {
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
gl.glViewport( 0, 0, width, height );
gl.glMatrixMode( GL.GL_PROJECTION );
gl.glLoadIdentity();
glu.gluPerspective(45.0f,width/height,0.1f,100.0f);
gl.glMatrixMode( GL.GL_MODELVIEW );
}
public void displayChanged(GLDrawable drawable, boolean arg1, boolean arg2) {
// TODO Auto-generated method stub
}
/**
* @param args
*/
public static void main(String[] args) {
Lesson02 lessonPanel = new Lesson02();
Frame frame = new Frame();
frame.setBounds(100,100,400,300);
frame.add(lessonPanel);
frame.setVisible(true);
}
}
There are two captures showing what I mean.