When I run the sample from “Getting started with JOGL”, the window appears and everything is drawn, but my system almost freezes - 100% cpu consumed. What are possible solutions to the problem?
Thanks in advance.
When I run the sample from “Getting started with JOGL”, the window appears and everything is drawn, but my system almost freezes - 100% cpu consumed. What are possible solutions to the problem?
Thanks in advance.
Please help! I’m new to jogl, and have absolutely no idea how to fix the problem.
My video card - Ati FireGL 8800.
program output:
Using ATI workaround of dispatching display() on event thread
Using ATI workaround of dispatching display() on event thread
Thanks.
That’s a known problem of the Animator class - it uses all CPU time because it basically renders at the full speed, without sleeps in the thread. You can use the following class to overcome the problem. I’ve created it for my own projects and I’ve been happy with the results. Pass the GLDrawable and the desired frame rate in the constructor (e.g. 50) and you’re ready to go. This class requires JDK1.5 to compile.
import net.java.games.jogl.GLDrawable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
public class Renderer
implements Runnable
{
private GLDrawable glDrawable;
private ScheduledExecutorService scheduler;
private boolean threadSet;
private float framesPerSecond;
public Renderer(GLDrawable glDrawable, float framesPerSecond)
{
this.glDrawable = glDrawable;
this.framesPerSecond = framesPerSecond;
}
public void start()
{
if (scheduler != null) stop();
scheduler = Executors.newScheduledThreadPool(1, new RendererThreadFactory());
scheduler.scheduleAtFixedRate(this, 0, (int) (1000.0f / framesPerSecond), TimeUnit.MILLISECONDS);
}
public void stop()
{
if (scheduler == null) return;
scheduler.shutdown();
scheduler = null;
}
/**
* Render a single frame
*
*/
public void run()
{
if (!threadSet)
{
glDrawable.setRenderingThread(Thread.currentThread());
threadSet = true;
}
try
{
glDrawable.display();
}
catch (Throwable t)
{
System.err.println("Throwable thrown during display:");
t.printStackTrace();
}
}
}
class RendererThreadFactory
implements ThreadFactory
{
public Thread newThread(Runnable runnable)
{
Thread thread = new Thread(runnable);
thread.setDaemon(false);
thread.setPriority(Thread.NORM_PRIORITY);
return thread;
}
}
ps. Sorry about the indentations of the code, which are propably a bit messed up.
Thank you.
Unfortunately, the problem has transformed: now nothing appears on the screen at all (window is not shown), despite
the thread is working (run() method is executed repeatedly)
Here is my code (what am I doing wrong?)
import net.java.games.jogl.GLCanvas;
import net.java.games.jogl.GLDrawableFactory;
import net.java.games.jogl.GLCapabilities;
import net.java.games.jogl.Animator;
import javax.swing.;
import java.awt.;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class Main
{
public static void main(String args[])
{
try
{
JFrame testFrame = new JFrame(“TestFrame”);
testFrame.setSize( 512, 384 );
GLCapabilities glCaps = new GLCapabilities();
glCaps.setRedBits(8);
glCaps.setBlueBits(8);
glCaps.setGreenBits(8);
glCaps.setAlphaBits(8);
GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(glCaps);
testFrame.getContentPane().setLayout(new BorderLayout());
testFrame.getContentPane().add(canvas, BorderLayout.CENTER);
//TestRenderer draws triangle
canvas.addGLEventListener(new TestRenderer());
// final Animator animator = new Animator(canvas);
final Renderer renderer = new Renderer(canvas, 50);
testFrame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
// animator.stop();
renderer.stop();
System.exit(0);
}
});
testFrame.setVisible(true);
// animator.start();
renderer.start();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
I used also Frame and frame.show() with the same result, so my change to JFrame should not be the reason of the problem.
Thanks.
That is really odd. I copy-pasted your code and tested to run it and it worked nicely for me. I’m using an ATI Radeon 9600 card with WinXP. Which HW/SW platform are you developing on?
Also, it seems that the Animator class uses an NVidia specific workaround (GLCanvas has a method willSetRenderingThread), which is not accessible outside the JOGL’s internal package. Does anyone know, if this is a required thing for NVidia cards?
Cheers
Hello,
I’m using WinXP and ATI Fire GL 8800
Query your GL strings and see which renderer you’re using. If it comes up with Microsoft, you’re not getting hardware acceleration.
Could you please clarify what should I do?
"Query your GL strings and see which renderer you’re using. "- how can I check it?
Also, “…you’re not getting hardware acceleration” - but as I understand, OpenGL provides hardware acceleration, Microsoft or not - it doesn’t matter. (Am I wrong?)
sorry for stupid questions
The Installable Client Driver (ICD) provides the hardware acceleration, not OpenGL itself. OpenGL knows nothing about your hardware specifics, so it’s up to the driver to do the work.
Add this into a test app:
System.out.println("OPENGL DRIVER INFORMATION");
System.out.println(" Version: " + gl.glGetString(GL.GL_VERSION));
System.out.println("Renderer: " + gl.glGetString(GL.GL_RENDERER));
System.out.println(" Vendor: " + gl.glGetString(GL.GL_VENDOR));
Under WinXP, if you get “Microsoft”, you’re getting the generic (non-accelerated) driver. You want your card vendor’s driver.
Another app that’ll let you view the capabilities of your card is called PixelFormatEnumerator. It will show you the different modes your card is capable of and in which modes you’ll get acceleration.
Under *NIX, glxinfo will give you similar information.
OPENGL DRIVER INFORMATION
Version: 1.3.4650
Renderer: Fire GL 8x00/Fire GL E1 DDR Pentium 4 (SSE2)
Vendor: ATI Technologies Inc.
and opengl hardware acceleration in video card settings is on
Does your program work correctly if you remove the renderer?
If I use the Animator object, programs works (not correctly, because it consumes all cpu), but at least i see the window with the triangle. If i use Renderer, nothing is shown at all - i’m in despair right now, and thinking of going back to c++, though i don’t like it.
[quote]If I use the Animator object, programs works (not correctly, because it consumes all cpu), but at least i see the window with the triangle. If i use Renderer, nothing is shown at all - i’m in despair right now, and thinking of going back to c++, though i don’t like it.
[/quote]
No need to go back to c++ because of this ;). I checked the Animator source once again and I noticed that it calls setNoAutoRedrawMode(true) on the GLDrawable. Can you try to call that on the GLCanvas after it is created. Does this make a difference when using the Renderer class?
Edit: Here’s a new version of the Renderer class, which should be more compliant with the Animator class. Can you test it and see if it fixes your problem?:
import net.java.games.jogl.GLDrawable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
public class Renderer
implements Runnable
{
private GLDrawable glDrawable;
private ScheduledExecutorService scheduler;
private boolean threadSet;
private float framesPerSecond;
public Renderer(GLDrawable glDrawable, float framesPerSecond)
{
this.glDrawable = glDrawable;
this.framesPerSecond = framesPerSecond;
}
public void start()
{
glDrawable.setNoAutoRedrawMode(true);
if (isRunning()) stop();
scheduler = Executors.newScheduledThreadPool(1, new RendererThreadFactory());
scheduler.scheduleAtFixedRate(this, 0, (int) (1000.0f / framesPerSecond), TimeUnit.MILLISECONDS);
}
public void stop()
{
if (!isRunning()) return;
scheduler.shutdown();
scheduler = null;
glDrawable.setNoAutoRedrawMode(false);
}
public boolean isRunning()
{
return scheduler != null;
}
/**
* Render a single frame
*
*/
public void run()
{
if (!threadSet)
{
glDrawable.setRenderingThread(Thread.currentThread());
threadSet = true;
}
// XXX: Catch for debug only
try
{
glDrawable.display();
}
catch (Throwable t)
{
System.out.println("Throwable thrown during display:");
t.printStackTrace();
System.exit(1);
}
}
}
class RendererThreadFactory
implements ThreadFactory
{
public Thread newThread(Runnable runnable)
{
Thread thread = new Thread(runnable);
thread.setDaemon(false);
thread.setPriority(Thread.NORM_PRIORITY);
return thread;
}
}
Thanks a lot!
setNoAutoRedrawMode(true) helps, but…
still some questions
window appears, everything is drawn, cpu is not consumed, but
Thank you very much for your help, but if you can help with above problems, it’ll be great - I still cannot use jogl because of them.
Have you tried passing the argument -Dsun.java2d.noddraw=true on the Java command line? Some of the problems you’re reporting sound like driver-level issues.
Yes, tried, but if didn’t help. I also tried with different versions of drivers, but it didn’t help also. We can see now that ATI Fire GL 8800 is not a best choice if you want to work with Jogl Hope that buying other card is not the only solution for the problem.
Thank you.
When you get some of the bad behavior where it isn’t clear what’s happening, could you use Ctrl-Break to get a thread dump and post the results? Maybe the system is stuck somewhere non-obvious.
just after i switch to other application and go back, the program starts using 100% cpu, here is the dump:
Full thread dump Java HotSpot™ Client VM (1.5.0-b64 mixed mode, sharing):
“Thread-4” prio=5 tid=0x02f37a18 nid=0xe70 runnable [0x034ef000…0x034efb68]
at net.java.games.jogl.impl.windows.WGL.NativeEventLoop(Native Method)
at net.java.games.jogl.impl.windows.WindowsGLContextFactory$NativeWindowThread.run(WindowsGLContextFactory.java:
270)
“DestroyJavaVM” prio=5 tid=0x00036958 nid=0xbfc waiting on condition [0x00000000…0x0007fae8]
“Thread-3” prio=5 tid=0x02efd590 nid=0xcf4 in Object.wait() [0x034af000…0x034afbe8]
at java.lang.Object.wait(Native Method)
- waiting on <0x22abb8d0> (a java.awt.EventQueue$1AWTInvocationLock)
at java.lang.Object.wait(Object.java:474)
at java.awt.EventQueue.invokeAndWait(EventQueue.java:846)
- locked <0x22abb8d0> (a java.awt.EventQueue$1AWTInvocationLock)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:203)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:75)
at Renderer.run(Renderer.java:62)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:280)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:135)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.j
ava:65)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.
java:142)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:166
)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)
“AWT-EventQueue-0” prio=7 tid=0x02f3d170 nid=0xe44 runnable [0x0346f000…0x0346fc68]
at net.java.games.jogl.impl.windows.WGL.wglMakeCurrent(Native Method)
at net.java.games.jogl.impl.windows.WindowsGLContext.makeCurrent(WindowsGLContext.java:142)
- locked <0x22fff020> (a net.java.games.jogl.impl.windows.WindowsOnscreenGLContext)
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent(WindowsOnscreenGLContext.java:110)
- locked <0x22fff020> (a net.java.games.jogl.impl.windows.WindowsOnscreenGLContext)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:254)
- locked <0x22fff020> (a net.java.games.jogl.impl.windows.WindowsOnscreenGLContext)
at net.java.games.jogl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:238)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
“AWT-Windows” daemon prio=7 tid=0x00a9af28 nid=0xc24 runnable [0x0333f000…0x0333fce8]
at sun.awt.windows.WToolkit.eventLoop(Native Method)
at sun.awt.windows.WToolkit.run(WToolkit.java:269)
at java.lang.Thread.run(Thread.java:595)
“AWT-Shutdown” prio=5 tid=0x00a9abd8 nid=0x5a4 in Object.wait() [0x032ff000…0x032ffd68]
at java.lang.Object.wait(Native Method)
- waiting on <0x22fe2ec8> (a java.lang.Object)
at java.lang.Object.wait(Object.java:474)
at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:259)
- locked <0x22fe2ec8> (a java.lang.Object)
at java.lang.Thread.run(Thread.java:595)
“Java2D Disposer” daemon prio=10 tid=0x00acbf90 nid=0xd20 in Object.wait() [0x032bf000…0x032bf9e8]
at java.lang.Object.wait(Native Method)
- waiting on <0x22fe2f50> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
- locked <0x22fe2f50> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
at sun.java2d.Disposer.run(Disposer.java:107)
at java.lang.Thread.run(Thread.java:595)
“Low Memory Detector” daemon prio=5 tid=0x00a6c7f0 nid=0xdd0 runnable [0x00000000…0x00000000]
“CompilerThread0” daemon prio=10 tid=0x00a6b3c8 nid=0xcb4 waiting on condition [0x00000000…0x02bcf8c0]
“Signal Dispatcher” daemon prio=10 tid=0x00a6a6e0 nid=0xed8 waiting on condition [0x00000000…0x00000000]
“Finalizer” daemon prio=9 tid=0x00a67a58 nid=0xc4c in Object.wait() [0x02b4f000…0x02b4fc68]
at java.lang.Object.wait(Native Method)
- waiting on <0x22f79228> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
- locked <0x22f79228> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
“Reference Handler” daemon prio=10 tid=0x00a66578 nid=0xe40 in Object.wait() [0x02b0f000…0x02b0fce8]
at java.lang.Object.wait(Native Method)
- waiting on <0x22f792a8> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:474)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
- locked <0x22f792a8> (a java.lang.ref.Reference$Lock)
“VM Thread” prio=10 tid=0x00a63cd8 nid=0xed4 runnable
“VM Periodic Task Thread” prio=10 tid=0x00a6da00 nid=0xdd4 waiting on condition
I would place my bet on:
“AWT-EventQueue-0” prio=7 tid=0x02f3d170 nid=0xe44 runnable [0x0346f000…0x0346fc68]
at net.java.games.jogl.impl.windows.WGL.wglMakeCurrent(Native Method)