JOGL is slow?

I decided last night to learn som java and JOGL, i am originally a c++ programmer so I havent really put much effort in reading about java, i guessed that I’d learn as I play along.

Anyways, so I made my first JOGL applications, it’s a simple triangle that rotates around it’s Y-axis. And I use the Animator class to handle the animation.
The problem is that the animation is really jerky and the CPU is up at around 98% of use. Err… So what am I doing wrong?

edit: I just noticed that the animation gets even more jerky if I move my mouse over the window alot :confused:

Here’s the source:


import java.awt.*;
import java.awt.event.*;
import net.java.games.jogl.*;

class GLFrame extends Frame implements GLEventListener
{
	protected Animator glAnimator;
	private int yrot = 0;

	public GLFrame()
	{
		super("JOGL Frame");
		setSize(320, 240);
	
		GLCanvas glCanvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
		glCanvas.addGLEventListener(this);
		add(glCanvas);

		glAnimator = new Animator(glCanvas);
		
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				glAnimator.stop();
				System.exit(0);
			}
		});

		setVisible(true);
		glAnimator.start();
	}

	public void init(GLDrawable drawable)
	{
		GL gl = drawable.getGL();
		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		gl.glClearDepth(1.0f);
		gl.glEnable(GL.GL_DEPTH_FUNC);
	}

	public void reshape(GLDrawable drawable, int i, int x, 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, (float)width/(float)height, 0.1f, 1000.0f);
		gl.glMatrixMode(GL.GL_MODELVIEW);
	}

	public void display(GLDrawable drawable)
	{
		yrot++;
		if( yrot > 360 ){ yrot = 0; }	

		GL gl = drawable.getGL();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
		gl.glLoadIdentity();
		gl.glTranslatef(0.0f, 0.0f, -5.0f);

		gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f);

		gl.glBegin(GL.GL_TRIANGLES);
		gl.glVertex3f( 0.0f, 1.0f, 0.0f);
		gl.glVertex3f(-1.0f,-1.0f, 0.0f);
		gl.glVertex3f( 1.0f,-1.0f, 0.0f);
		gl.glEnd();

		gl.glFlush();
		gl.glFinish();
	}

	public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged)
	{
	}


	public static void main(String[] args)
	{
		new GLFrame();
	}
}

You have a 320x240 drawing-surface, rendering 1 triangle.

That might give you something like 1200fps on a decent gpu.
You are rotating your triangle with 1 degree per frame, so that’s 1200 degrees per second, about 3 rotations per second.

Your monitor supports somewhere between 60 and 100Hz, so ‘interference’ will cause frames overlapping eachother at different vertical-heights.

So solve all this, you should either make a good ticker, or if you’re lazy, just Thread.sleep(20) every frame.

Note that glFlush() and glFinish() should not be called at the end of each frame.

I found some class called FPSAnimator which I tried with my code instead of the normal Animator and there where no difference, if there was it was very hard to see.

Also after closing some applications which I had in the background while testing, the animation looks pretty good, not perfect, but uhm… better… anyways the real big problem is when I move my mouse over the window, then the animation gets really jerky. Any solutions for that?

WEEE!! I solved it :smiley:

I was running my system with the onboard graphics card which is an ATI XPRESS 200, but I have a Nvidia 6600GT. I didn’t have the 6600GT installed because it was giving me troubles while playing games, made the computer crash, so I removed it . But now I’ve installed it again and the jerky stuff that was going on while moving my mouse over the scene has now dissapeared.

So it seems that JOGL has problems with ATI cards, or at least mine :confused: Are there any official notes on this?

You might want to try LWJGL. It doesn’t rely on AWT so there’s less that might go wrong.

ATi cards are much less forgiving of errors, so they tend to crash earlier (which is a good thing, actually… ??? :))

Did you remove glFlush() & glFinish() and try with the ATI?

Is the ATI driver dropping you into software rendering mode?

Yes I removed the glFlush() & glFinish(), actually I didn’t have them in my source from the beginning. But as I searched this forum I found a reply that said you should use these two methods, so I did, though I never done it before :confused:

And no I never checked if it dropped into software rendering mode, I don’t know how to :confused:

That gave me this results:

GL_VENDOR: ATI Technologies Inc.
GL_RENDERER: RADEON Xpress 200G Series SW TCL x86/MMX/3DNow!/SSE2
GL_VERSION: 1.4.4707 WinXP Release

Then you’re getting hardware-acceleration. Have you tried LWJGL already, if so, did you have the same jerky-ness? Can you output the framerate?

[quote]Have you tried LWJGL already, if so, did you have the same jerky-ness? Can you output the framerate?
[/quote]
I did it now, and it works great!
I guess I will have to use LWJGL instead then.

I really prefer LWJGL, so please forgive me my bias :slight_smile:

But well, it would be really nice of you if you’d file a BugReport @ JOGL.