I just started playing around with jogl. And I wrote this example code which ran on my brothers computer, but when I put it on mine, it was giving me this swap buffer error. How do I fix that? Now, it runs but doesn’t rotate, and then when I try to run it a second time the display is empty. Also, I inputed this example I got from my professor last semester and his code runs but it is flickering, what causes the flickering? Here is the code that I wrote if anybody has any suggestions.
import javax.swing.;
import net.java.games.jogl.;
import java.awt.*; //contains graphicsdevice info
public class Example1 extends JFrame implements GLEventListener
{
GLCanvas canvas=null;
private float m_angle=(float)0.0;
int width=500;
int height=500;
GraphicsEnvironment ge=null;
GraphicsDevice gd=null;
GraphicsConfiguration gc=null;
public Example1()
{
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
gd = ge.getDefaultScreenDevice();
gc = gd.getDefaultConfiguration();
setTitle("Simple Object");
setSize(width,height);
GLCapabilities capabilities = new GLCapabilities();
canvas=GLDrawableFactory.getFactory().createGLCanvas(capabilities);
canvas.addGLEventListener(this);
this.getContentPane().add(canvas);
if( gd.isFullScreenSupported() )
{
gd.setFullScreenWindow(this);
}
this.setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Animator animator=new Animator(canvas);
animator.start();
}
public void init (GLDrawable drawable)
{
GL gl = drawable.getGL();
GLU glu=drawable.getGLU();
gl.glClearColor((float)0.0,(float)0.0,(float)0.0,(float)0.0);
gl.glViewport(0,0,width,height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective((float)52.0,(float)width/(float)height,(float)1.0,(float)1000.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display (GLDrawable drawable)
{
GL gl=drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef((float)0.0,(float)0.0,(float)-5.0);
gl.glRotatef(m_angle,(float)1.0,(float)0.0,(float)0.0);
gl.glRotatef(m_angle,(float)0.0,(float)1.0,(float)0.0);
gl.glRotatef(m_angle,(float)0.0,(float)0.0,(float)1.0);
gl.glColor3f((float)0.7,(float)1.0,(float)0.3);
gl.glBegin(GL.GL_TRIANGLES);
gl.glVertex3f((float)1.0,(float)-1.0,(float)0.0);
gl.glVertex3f((float)-1.0,(float)-1.0,(float)0.0);
gl.glVertex3f((float)0.0,(float)1.0,(float)0.0);
gl.glEnd();
gl.glColor3f((float)1.0,(float).7,(float).7);
gl.glPointSize((float)15.0);
gl.glBegin(GL.GL_POINTS);
gl.glVertex3f((float)0.0,(float)0.0,(float)0.0);
gl.glVertex3f((float)0.0,(float)1.0,(float)0.0);
gl.glEnd();
gl.glEnable(GL.GL_LINE_STIPPLE);
gl.glLineStipple(2,(short)15);
gl.glLineWidth(2);
gl.glBegin(GL.GL_LINES);
gl.glVertex3f((float)1.0,(float)0.0,(float)3.0);
gl.glVertex3f((float)-5.0,(float)1.0,(float)3.0);
gl.glEnd();
m_angle+=(float).1;
}
}