Main Menu

Low fps

Started by roninjnj, August 24, 2008, 06:37:55 PM

Previous topic - Next topic

roninjnj

Hi!

I´m working in a tile-style engine 3D. Main idea is render the world in a canvas instance to put this canvas in a JFrame with all buttons, labels, ect...

My problems is that with 4200 vertexs in world, its only can do between 30 or 40 frames per second.

Time delayed between buffers updates is only 25 millisecons.

Otherside, i was reading FPS sample in JPCT download section and its can up 200 frames por seconds.

¿There is another way to make faster hardware render into a canvas instance that i´m using?

My code example:


In object creation:

buffer = new FrameBuffer(width, height, defaultFrameBufferMode);     
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
canvas = buffer.enableGLCanvasRenderer();

In loop method:

buffer.clear(java.awt.Color.BLACK);                             
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
canvas.repaint();     




A Screenshot
[img=http://img231.imageshack.us/img231/4391/image1wd3.th.jpg]

THANKS!!!! ;-)

EgonOlsen

I don't get this part:

Quote
Time delayed between buffers updates is only 25 millisecons.

Does that mean you are adding an extra delay like Thread.sleep(25) in the loop?

How are you measuring fps? If you are doing it in the loop, its not accurate when using the AWTGLRenderer (most likely it will be lower than the numbers show). Put the measurement code into an implementation of an attached IPaintListener if you haven't done this already.

roninjnj



1) Yes, i´m using Thread.sleep(25) in the loop.  (if i not do some like this, cpu work at 100%)

2) Yes, i´m measuring fps in the loop :S (FPS.JAR sample do something like that in loop() method, isn´t? )


EgonOlsen

Well, then how should the fps be higher than 1000ms/25ms=40? If you don't want 100% load on the core that executes the loop (the rendering will take place on another core if available), the sleep will always limit your fps to 1000ms/sleepTime. You may want to adjust the sleep time according to the time the frame takes to be processed, i.e. measure the time taken from buffer.clear to canvas.repaint() with a high accuracy timer (i.e. not with currentTimeMillis() but nanoTime() or something) and subtract that from 25. That way, you'll get a constant 40fps in that loop regardless of how long the processing takes (given that it doesn't take longer than 25ms). That's what i'm doing in my game to limit the fps to 75fps.

The fps-example uses the OpenGL renderer. That renderer uses (unless configured otherwise, which no one ever did except for myself as far as i know...) one thread only. The AWTGLRenderer uses two. One is your loop-executing thread and one is the rendering thread (which is in fact the AWT event dispatch thread). If you want to measure rendering time/fps, you can't do it in the loop like the fps-example does it. It's just not accurate, because it may happen that the loop calculates 2 frames but the render thread only manages to process one in that time. There is the IPaintListener interface. You can implement it in your main class and put the fps-counter-code in the finishedPainting()-method. That should give you correct fps.

roninjnj

Very interesting!!

That´s solve me some questions about frame-counters in JPCT.

It´s a very clean explain! :D

Thanks!!!