I just started playing around with jogl and I wrote some code on my brothers computer and everything was working fine, then when I tried to run the same code on my computer, I ran into some problems. My brother and I are both running windows xp. First, the code I wrote was giving me this swap buffer error and I don’t know why. Then it would show the object on the screen (I am not sure what I did to get around this swap buffer error) but wouldn’t be rotating like it should. But when I run it a second time, the display would be blank. Then I typed my professors example from last semester and his code works except that it is flickering. Does anybody know what this swap buffer error is, or why the code would flicker or how I get around that.
HERE IS MY CODE WHERE IT WAS GIVING ME A SWAP BUFFER ERROR************
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;
}
public void reshape (GLDrawable drawable, int i, int x, int width, int height)
{
}
public void displayChanged (GLDrawable drawable, boolean modeChanged, boolean deviceChanged)
{
}
}
//******HERE IS THE CODE THAT IS FLICKERING
public class Example extends JFrame implements GLEventListener
{
private Cube theCube;
private float cubeAngle;
private Pyramid thePyramid;
private float pyramidAngle;
private final int WIDTH=500;
private final int HEIGHT=500;
public Example()
{
setTitle("Simple Polygon");
setSize(WIDTH,HEIGHT);
GLCanvas myCanvas=GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
myCanvas.addGLEventListener(this);
this.getContentPane().add(myCanvas);
theCube=new Cube();
thePyramid=new Pyramid();
this.setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Animator animator=new Animator(myCanvas);
animator.start();
}
public void init (GLDrawable drawable)
{
GL gl=drawable.getGL();
GLU glu=drawable.getGLU();
gl.glShadeModel(GL.GL_SMOOTH);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective((float)60.0,(float)WIDTH/(float)HEIGHT,(float).1,(float)100.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.glMatrixMode(GL.GL_MODELVIEW);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glTranslatef((float)-1.5,(float)0.0,(float)-6.0);
gl.glRotatef(pyramidAngle,(float)0.0,(float)1.0,(float)0.0);
thePyramid.draw(drawable);
gl.glLoadIdentity();
gl.glTranslatef((float)1.5,(float)0.0,(float)-6.0);
gl.glRotatef(cubeAngle,(float)1.0,(float)1.0,(float)1.0);
theCube.draw(drawable);
gl.glPopMatrix();
pyramidAngle +=(float).2;
cubeAngle -=(float).15;
gl.glFlush();
}