CPU load 100% issue

hello

i’ve been working through “shogi’s learning jogl” tutorials. i previously experienced a problem with my cpu load being 100% whenever i ran my jogl application, with everything in the background slowing down to a crawl. i had implemented my window solely using awt. i then decided to try using swing instead, and the cpu load changed to a pretty 2% average. this was great with the first couple of example applications where no animator was being used.

then today i did the animation bit of the tut, attaching my glCanvas to a new animator object, and then starting the animator thread. running that app has shot my cpu load back up to 100%. i’m not sure why. i’ve tried creating a simple threading application that exectures a couple of threads and the cpu load factor is tiny. so it’s not threads in general, it’s something to do with animator/glCanvas.

i’m using jogl.jar and .dll from 2003, because the more recent versions dont seem to work on my pc. i get “unable to lock surface” errors. i have an on-board graphics card whose openGL capabilities are probably limited, but this is just an assumption. not sure why else the 2003 libraries work, and the later versions don’t. (card = S3 DeltaChrome IGP)

anyone got ideas as to why my CPU load is sky-rocketing with awt and with animator thread?

following up from the animator cpu hog-

everytime i close the application i also get the following output in my console:


Exception in thread "Thread-2" 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:193)
	at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:182)
	at net.java.games.jogl.GLCanvas.display(GLCanvas.java:82)
	at net.java.games.jogl.Animator$1.run(Animator.java:104)
	at java.lang.Thread.run(Unknown Source)

not sure if this is of any help nor why i am getting this output.

here is the code where i start the animator thread (nothing out of the ordinary i bet…) - perhaps it might help clarify:


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

public class AnimatorApp extends JFrame
{
	static Animator animator = null;
	
	public static void main(String [] args)
	{
		final AnimatorApp app = new AnimatorApp();
		
		//display window
		SwingUtilities.invokeLater(new Runnable(){public void run(){app.setVisible(true);}});
		
		//run animator
		SwingUtilities.invokeLater(new Runnable(){public void run(){animator.start();}});		
	}

	public AnimatorApp()
	{
		super("Animation Template");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		//create listener
		AnimatorListener listener = new AnimatorListener();
		
		//create canvas
		GLCapabilities glCaps = new GLCapabilities();
		GLDrawableFactory glFactory = GLDrawableFactory.getFactory();
		GLCanvas glCanvas = glFactory.createGLCanvas(glCaps);
		glCanvas.addGLEventListener(listener);
		
		//create animator
		animator = new Animator(glCanvas);
		
		//add canvas to window
		getContentPane().add(glCanvas, BorderLayout.CENTER);
		setSize(500,300);
		centerWindow(this);
	}
	
    public void centerWindow(Component frame)
    {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize  = frame.getSize();

        if (frameSize.width > screenSize.width) frameSize.width = screenSize.width;
        if (frameSize.height > screenSize.height) frameSize.height = screenSize.height;

        frame.setLocation ((screenSize.width  - frameSize.width ) >> 1, (screenSize.height - frameSize.height) >> 1);
    }	
}

some of you will probably notice that this code is based on shogi’s tuts.

thanks

Well that’s the purpose of the Animator : run your application at the maximal framerate.
Try to use the FPS animator (it may not be present in the version you are using but you get the sources from another version and create this kind of animator for your code).

As turquoise said, the Animator in JOGL runs your rendering thread as fast as possible. If you check the source, the most if ever does to ‘back down’ is a Thread.yield() call at the end of the rendering loop.
And also said by turquoise, you can try using the FPSAnimator, which instead tries to maintain a target framerate. Or, create your own rendering loop/Thread to work in whatever way you desire it to.

ah ok thanks for clearing that up.

i assume that my cpu load is at 100% because of my onboard graphics card. ie: am i correct in saying that were i to have a conventional 3d graphics card, my cpu load would be fine (under, say, 10%), but my GPU would be maximised instead?

my concern here is that if i invest in a proper 3d graphics card and run jogl apps, my other multi-tasked applications won’t slow down to a crawl (like they currently are with my onboard graphics card).

Actually it would probably be the other way around. A better 3d card would not block as often and be ready to accept data from the CPU quicker/more frequently which in turn keeps the CPU usage up.

If you’re really concerned about reducing CPU usage, you need to look into the FPSAnimator as suggested.