help with jogl

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();

   }

Your Example1.java works fine on my machine. What kind of graphics card are you using? Are you using the latest JOGL build (1.1 beta 04, from the Documents & Files section of the JOGL home page)?

Thanks…I guess it must be my graphics card. I ran this code:

String vendor = gl.glGetString(GL.GL_VENDOR);
System.out.println("Vendor: " + vendor);
String renderer = gl.glGetString(GL.GL_RENDERER);
System.out.println("Renderer: " + renderer);

and my output was:

Vendor: Microsoft Corporation
Renderer: GDI Generic

So if I don’t support hardware acceleration or if my renderer is Generic, would I have to get a new graphics card to properly run openGL?

Which version of JOGL are you using? There was a bug in the 1.1 betas that GKW fixed where we were choosing the wrong pixel format in certain situations. This is fixed in the 1.1 beta 04 builds available from the Documents & Files section on the JOGL web page.

I downloaded the updated version of jogl and that fixed the flickering problem, but when I exit the program, it still gives me this error.

net.java.games.jogl.GLException: Error swapping buffers
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.swapBuffers
(WindowsOnscreenGLContext.java:140)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:292)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:208)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:75)
at net.java.games.jogl.Animator$1.run(Animator.java:107)
at java.lang.Thread.run(Thread.java:534)

Also, the first example I posted still doesn’t show anything on the screen and also gives me this swapped buffer error. I updated my jogl.jar file with the
1.1b04-July 16 file on the jogl home page.

The graphics card I am using if this helps is:

intel ® 82845G/GL/GE/PE/GV and I checked their website and they say they support Direct X and OpenGL. I updated there driver and now when I print
the graphics card information it prints:

Vendor: Intel
Renderer: Intel 845G

GKW has been working on a bug fix for the pixel format selection code on Windows that works around instability issues in ATI’s and Intel’s drivers. I think that will probably fix the last problem you’re seeing. Hopefully these changes will be in the source base soon.

I had this same type of “Error swapping buffers” issue. The problem is with the setDefaultCloseOperation. The following is a fixed version of Example1:

import javax.swing.;
import net.java.games.jogl.
;

import java.awt.*; //contains graphicsdevice info
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

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;
static Animator animator = 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);
  
  // This was the culprit:
  //setDefaultCloseOperation(EXIT_ON_CLOSE);
  
  animator=new Animator(canvas);
  animator.start();

}
public static void main(String[] args)
{
final Example1 frame = new Example1();

  // Use this method to stop the animator and exit from the program
  frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
          animator.stop();
          System.exit(0);
      }});

}

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)
{

}
}