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.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › NeHe lesson 1 question: processing vs. opengl
Page Index Toggle Pages: 1
NeHe lesson 1 question: processing vs. opengl (Read 1459 times)
NeHe lesson 1 question: processing vs. opengl
Sep 22nd, 2009, 3:05pm
 
here is a sketch that I believe is pretty close to a direct port of the NeHe lesson 1 opengl code.

Quote:
import processing.opengl.*;
import javax.media.opengl.*;

PGraphicsOpenGL pgl;
GL gl;

void setup() {
  size(400, 400, OPENGL);
  pgl = (PGraphicsOpenGL)g;
  gl = pgl.gl;
  resizeGLScene();
  initGL();
}

void draw() {
  gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
  gl.glLoadIdentity();
}

void resizeGLScene() {
  gl.glViewport(0, 0, width, height);
  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glLoadIdentity();
//  gl.gluPerspective(45.0, (float)width/(float)height, 0.1, 100.0);
  gl.glMatrixMode(GL.GL_MODELVIEW);
  gl.glLoadIdentity();
}

boolean initGL() {
  gl.glShadeModel(GL.GL_SMOOTH);
  gl.glClearColor(0.0, 0.0, 0.0, 0.0);
  gl.glClearDepth(1.0);
  gl.glEnable(GL.GL_DEPTH_TEST);
  gl.glDepthFunc(GL.GL_LEQUAL);
  gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
  return true;
}



I have some questions about this code.  You'll notice gluPerspective is commented out.  Apparently, there is no method by that name.  If I can't set the perspective using that method then the associated glMatrixMode and glLoadIdentity are unnecessary.  If you remove both of those then GL_MODELVIEW matrixmode call and the assocaited loadidentity are also unnecessary as that is the default matrixmode correct?  That leaves the glViewport call which itself confuses me.  The glViewport docs say "Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0,0)."  Which contradicts the way processing works entirely right?  The upper left pixel is 0, 0 in processing.  On top of that, I don't know if I really need that call at all, as it seems like the size call sets up the viewport.  I could answer some of these questions on my own (what is default and such) using glGet but it looks like that method doesn't exist.

Basically, my question is, once you start using opengl in processing, where does processing end and opengl begin?  For example, I can change the perspective in processing by using the perspective method, but if I am making opengl calls inside my processing sketch what kind of impact will that call have?  I'm an opengl noob (obviously) and I'm mainly trying to get started off on the right foot.  Any help/ideas/advice would be appreciated.  Thanks!
Re: NeHe lesson 1 question: processing vs. opengl
Reply #1 - Sep 23rd, 2009, 1:38am
 
if you're going to use opengl rethink the way you think.
processing flips the screen for you to make things easier and logical.

opengl works from the bottom left corner and goes up, and processing teaches you that screen goes from top-left corner down (which is normal for anything other than opengl =)

as to use glu you need to grab a reference to the glu object (opengl utility), which includes goodies to make life easier, like that function there.


import javax.media.opengl.glu.*;  

GLU glu = (((PGraphicsOpenGL)g).glu);


viewport changes the viewport, at sometimes you might need to render to different viewports, and thats why that function exists. you'll see when you need it.

glGet exists as glGetInteger,Float, etc.. google it up.

Re: NeHe lesson 1 question: processing vs. opengl
Reply #2 - Sep 23rd, 2009, 6:17am
 
nice!  Thanks again V, this is really helpful stuff.  It sounds to me like once one starts using opengl in Processing one pretty much has to use all opengl calls as switching between opengl and the processing api can be tricky unless you are familiar with how the processing opengl renderer is implemented.
Re: NeHe lesson 1 question: processing vs. opengl
Reply #3 - Sep 23rd, 2009, 11:05am
 
Hey gotascii, this might help you too:

http://benhem.com/games/GLP5align/

It shows how to get the Processing and pure GL renderers aligned with the same perspective and camera position.

--Ben
Re: NeHe lesson 1 question: processing vs. opengl
Reply #4 - Sep 24th, 2009, 8:15am
 
thats cool ben.
Page Index Toggle Pages: 1