We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Weird Render (Read 984 times)
Weird Render
May 16th, 2008, 1:13pm
 
Hi everyone.

I feel kinda stupid asking this but, is there any reason why i get better results with P3D render than OpenGL?

I'm just rendering a bunch of box() on a 3D environment, and nothing else. However when i change from OpenGL render to P3D, I get some massive FPS increace. I believe it was the other way around.

I'm running under WinXP, and i have the drivers properly installed (nVidia GeForce Go 7400).
Re: Weird Render
Reply #1 - May 17th, 2008, 12:29am
 
hmmm... i ran a test render with a grid of 250 lit rotating boxes on both opengl and P3D.  I'm at work and used the two pcs at my desk, one is a laptop 2ghz core2 duo and the other is a p4 3.2 ghz desktop.  Both of these are running off onboard video.  here's the code:

Quote:


import processing.opengl.*;

void setup(){
 size (500,500,P3D);
}

void draw(){
 lights();
 background(0);
 rotateY(radians(frameCount));
 for (int j=0; j<50; j++){
   pushMatrix();
   for (int i=0;i<50; i++){
     translate(15,0,0);
     box(10);
   }
   popMatrix();
   translate(0,15,0);
   box(10);
 }
println(frameRate);
}




And here are the results:

Laptop:
opengl=11 fps
P3D= 17 fps

Desktop:
opengl=9 fps
p3d= 7 fps

I'm guessing it has something to do with the hardware acceleration but you've got a pretty decent card...for a laptop Tongue so i'm not really sure.  I'm sure one of the other gurus on here can explain....
Re: Weird Render
Reply #2 - May 17th, 2008, 6:16pm
 
decinoge wrote on May 16th, 2008, 1:13pm:
I feel kinda stupid asking this but, is there any reason why i get better results with P3D render than OpenGL

I'm just rendering a bunch of box() on a 3D environment, and nothing else. However when i change from OpenGL render to P3D, I get some massive FPS increace. I believe it was the other way around.

In certain cases, you'll get better performance out of P3D. It's the case for your specific example, because drawing boxes requires several calls over to native code (a couple for each vertex of the box), which can be expensive. Lots of ellipses or spheres would be another such case. P3D doesn't sweat much, especially at size 500x500.

You'd probably find your code to be slower in P3D if you used size(screen.width, screen.height, P3D), because it takes longer for Java to update pixels than OpenGL does.

For what it's worth, this is something that will change as we optimize a bit more for OpenGL (this Summer). We're not using OpenGL very efficiently:
http://dev.processing.org/reference/everything/javadoc/processing/opengl/PGraphicsOpenGL.html
Re: Weird Render
Reply #3 - May 18th, 2008, 8:23pm
 
Well currently there is a shton of overhead for using processing's shape functions in opengl. Plus you are recreating 250 cubes on the fly. Depending on how the cube function works it most likely means opengl has to create 6 quads or 24 vertices per cube. But they also need 4 texture coordinates per face. All this adds up to 1500 quads that you are generating each frame.

If you want to see speed improvements you I would suggest looking up openGL display lists. It would increase the speed of your app the most based on what you have presented. The idea is this: you build all of the boxes once using quads and Store it as a display list. Then each time you want to draw the scene you just call glCallList() and it renders it in the current matrix.

Unfortunately i think you would have to use glPopMatrix and glPushMatrix and this could be a slippery slope out of the processing world and into the raw opengl world.
Re: Weird Render
Reply #4 - May 19th, 2008, 12:23am
 
I was just curious as to why the p3d renderer was faster than processing's opengl in this case. thanks for input fry.

I've never really used p3d, and i stopped using processing 's opengl quite some time ago, raw opengl really is the way to go. i load most of my geometry with  indexed arrays and vbos. I can load a 50mb obj geometry file and keep my framrate over 60fps on my 8800 gtx (Happy) there's no way i'de be able to do that with processing's opengl. I really haven't had any issues either it's just jogl in a really friendly environment.
Re: Weird Render
Reply #5 - May 20th, 2008, 12:46pm
 
Thank you for all your replys.

actually i did some more digging, and i found out that my drivers were not properly installed after all (something due to the fact that this board was specific for sony laptops, and the drivers developed for the manufactor).

Anyway, the OpenGL render is working quite good now. still, i am verry interested in working with pure OpenGL. however i am extremely unexperienced with any kind of 3D coding, and i think this would be a great chance to star getting into it.

if it is not too much of a burden, could anyone indicate me some tutorials or even great topics about how can we interact directly with OpenGL with processing? I've been and still be watching and reading topics over the discourse, but some kind of orientation with a better "know how" would be a great help.

Thanks you all, i am very apreciated for all the help.
Re: Weird Render
Reply #6 - May 20th, 2008, 10:16pm
 
I'de recommend to start play around with processing first, there's ton of stuff you can do without having to start screwing with native opengl commands. Processing can do almost anything natice gl can do, it's just somewhat slower.  On the flip side you don't have to worry about surface normals lighting calculations, vertex arrays etc. Most of the sketches i've made started as pure processing and then i optimized them with native opnegl commands.  Once you get comfortable with coding then buy a book on opengl, i'de recommend the opengl super bible 4th edition. I spent two months reading books on processing and java before i started screwing with native opengl. and if you haven't already done so pick up one of the processing books they're great reads.

if you still want to jump right into native gl. here's some info on getting you started:

Quote:


import processing.opengl.*;  
import javax.media.opengl.*; // This is the jogl library you need

PGraphicsOpenGL pgl; // bindings for opengl
GL gl;

void setup(){
 size(600,600,OPENGL);
 hint( ENABLE_OPENGL_4X_SMOOTH); // anti aliasing
 
  pgl = (PGraphicsOpenGL) g;
 gl = pgl.gl;
}

 void draw(){
   background(0);
   // processing code goes here
   
   pgl.beginGL(); // place before you native gl code
   // gl code does here
   
   // this translates the different matrices and other stuff so that  
   // you can use gl commands note that most of the processing commands will
   // not work or will behave strangly so don't mix the two.  Gl geometry
   //  will only be lit with gl lights and normals.
   pgl.endGL(); //place after your native gl code, you can place more processing stuff here
 }



This is pretty much what you'll need to interface processing with opengl.  if you need some tutorials look for tutorials on jogl (java opengl): here's a couple of links:

jogl forums:
http://www.javagaming.org/forums/index.php?board=25.0

a couple of tuts:
http://www.felixgers.de/teaching/jogl/index.html

Don't worry about setting up a jogl environment or window creation etc... processing does that for you, that's the beauty of it.
Re: Weird Render
Reply #7 - May 21st, 2008, 2:04am
 
I agree with sgsrules. I'm prone to preaching my own schtick but i feel that it would be more beneficial to first muck around with processing until you find yourself at a roadblock - as we all have learned at one point or another that necessity tends to provide the most meaningful change and knowledge.

Processing is natively capable of doing most everything for beginning and intermediate graphics programing. The kicker is (and this is why i love it) that it's perfectly suited for rapid development of advanced graphics applications as well. There is an unreasonable amount of overhead Java that is out of the way though still accessible.

Finally, i feel openGL is just sort of icing on the cake at the moment. I've scoured the source quite extensively and concluded that the P3D render mode is not to be underestimated.
Page Index Toggle Pages: 1