Author Topic: gl in jframe  (Read 3126 times)

Offline Minigame

  • int
  • **
  • Posts: 55
    • View Profile
gl in jframe
« on: January 07, 2013, 08:50:24 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: gl in jframe
« Reply #1 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?

Offline Minigame

  • int
  • **
  • Posts: 55
    • View Profile
Re: gl in jframe
« Reply #2 on: January 07, 2013, 09:03:28 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
« Last Edit: January 07, 2013, 09:06:29 pm by corey »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: gl in jframe
« Reply #3 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:

Code: [Select]
Config.useMultipleThreads=true;
Config.loadBalancingStrategy=1;
Config.maxNumberOfCores=<number of cores available>;

Offline Minigame

  • int
  • **
  • Posts: 55
    • View Profile
Re: gl in jframe
« Reply #4 on: January 07, 2013, 09:33:32 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:

Code: [Select]
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?
« Last Edit: January 07, 2013, 09:49:26 pm by corey »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: gl in jframe
« Reply #5 on: January 08, 2013, 07:08:58 am »
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.