If you need to lit a GLModel object, then the lights should be called inside the beginGL()/endGL() block. See how this is done in the models/GLLights example that comes with the library.
The reason for this is that when the lighting functions are called outside beginGL()/endGL(), then they use the software implementation (i.e.: non-OpenGL lights).
I know this sounds quite convoluted, but due to architectural limitations of the OPENGL renderer on which GLGraphics is based, there is really no easy way to fully integrate OpenGL with the rest of the Processing API.
These issues are being taken of care with the new OPENGL2 renderer, though.
I'm very much looking forward to playing with the new renderer. I can see lots of possibilities coming up :)
My light situation is a little odd. The only one that I can get to look any good (so that it shows the actual edges and surfaces) is the spotlight. I used the same technique as in the GLLights example. It's just that when you hold the mouse in one position, and the cube looks well illuminated, as it rotates, it's almost as though the light rotates with it! Is that possible? (push and popMatrix didn't seem to make a difference)
I've been trying to decipher what's going on and can't get to the bottom of it.
In order to try and solve the lighting issue; I've created a plane in the background to see where the light's shining.
Looking at the plane, with the mouse held in one position (after getting illumination on the cube), you can see that the light does not appear to be moving, but when you watch the cube when it's lit (for more than a few seconds), the light seems to move, but only on the cube.
Can someone please have a look as it's driving me a bit crazy :)
Hi, you forgot to specify the model's normals, which are needed by OpenGL to compute the lighting. GLGraphics doesn't compute normals automatically, so you need to set them explicitly, see the code below:
int numvertex= 24;
float rotx = PI/4;
float roty = PI/4;
float lightX, lightY, lightZ;
size(640, 480, GLConstants.GLGRAPHICS);
frameRate( 55 );
cube = new GLModel(this, numvertex, QUADS, GLModel.STREAM);
plane = new GLModel(this, 4, QUADS, GLModel.STREAM);
That seems to have done the trick! Thanks very much andres :) Will investigate into normals a little more. .
One final quick point: do you know of any way to ray trace using GLGraphics? I've tried the Joons Renderer (http://code.google.com/p/joons-renderer/), but there seems to be an issue when it tries to render out. If nothing at the moment; will the OPENGL2 renderer have some way to do this?