gl in jframe

Started by Minigame, January 07, 2013, 08:50:24 PM

Previous topic - Next topic

Minigame

I've written a few jPCT based client applications and have gotten them to run @ 120fps but they have used lwjgl display and input handling.
The latest project of mine though, only gets up to 35fps, and I'm wondering if it's because I am using jPCT solely to render the 3D scene, which is drawn inside of a JFrame, and uses Java2D (AWT functions) for game interfaces, user input, etc.
The way scene processes is just as efficient as previous clients, so I have to wonder if what I'm doing (the jframe thing) is bad?

EgonOlsen

How are you doing the rendering into the JFrame? AWTGLRenderer, software renderer or an image taken from the FrameBuffer?

Minigame

#2
Quote from: EgonOlsen on January 07, 2013, 08:54:14 PM
How are you doing the rendering into the JFrame? AWTGLRenderer, software renderer or an image taken from the FrameBuffer?

I'm just creating the frame buffer instance after the jframe is created
            buffer = new FrameBuffer(app.getSettings().getWidth(), app.getSettings().getHeight()-125, FrameBuffer.SAMPLINGMODE_NORMAL);

this is how I'm getting the 2D graphics to display in the buffer, or whatever
         graphics = (Graphics2D) getBufferStrategy().getDrawGraphics();

and in the update loop, I'm just cycling this bit of code to render the scene

               // Clear the previous frame
               graphics.clearRect(0, 0, getWidth(), getHeight());
               buffer.clear(Color.BLACK); // app.getSettings().getBackgroundColor());
               
               app.getCurrentState().display3D(buffer); // This is the jPCT world..
               buffer.update();
               buffer.display(graphics); // 2D graphics
               app.getCurrentState().display2D(graphics);

Sorry for the lack of technicality in details.. I'm still learning

EgonOlsen

...so...it's the software renderer!? In that case it's only natural that it's slower, because rendering is done by the CPU instead of the graphics card now. If you are using a multi-core CPU, you can try to do this:


Config.useMultipleThreads=true;
Config.loadBalancingStrategy=1;
Config.maxNumberOfCores=<number of cores available>;

Minigame

#4
Quote from: EgonOlsen on January 07, 2013, 09:26:57 PM
...so...it's the software renderer!? In that case it's only natural that it's slower, because rendering is done by the CPU instead of the graphics card now. If you are using a multi-core CPU, you can try to do this:


Config.useMultipleThreads=true;
Config.loadBalancingStrategy=1;
Config.maxNumberOfCores=<number of cores available>;


Edited: The above code helped with performance quite a bit. Switching to OpenGL hardware would use the GPU though, correct?

EgonOlsen

Quote from: corey on January 07, 2013, 09:33:32 PM
Edited: The above code helped with performance quite a bit. Switching to OpenGL hardware would use the GPU though, correct?
Yes, but then it won't be such easy to combine it with a gui. If you disable the software renderer and call this method: http://www.jpct.net/doc/com/threed/jpct/FrameBuffer.html#enableGLCanvasRenderer(), you'll get an AWT canvas into which the engine will render. You can find an example in distribution (HelloWorldAWTGL.java). This can be combined with AWT and Swing, but you might run into problem combining Swing with its lightweight components with that canvas, which is heavyweight. You should be able to find some threads about this in the forum.