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 › OpenGL lights w/ OCD library
Page Index Toggle Pages: 1
OpenGL lights w/ OCD library (Read 632 times)
OpenGL lights w/ OCD library
Feb 19th, 2010, 12:06pm
 
There is something wrong with my GL_LIGHT0 dynamic position.
My normals look to be ok.. but when I start to use glLightfv for positionning my light according to the cam's position, the result is really weird...

My goal is to make a pointLight thats follows the camera...

And for those who will ask me why i use opengl instead of processing's commands, i just need it, for performance and for fancy things Wink  

Code:
import processing.opengl.*;
import javax.media.opengl.*;
import damkjer.ocd.*;

PGraphicsOpenGL pgl;
GL gl;

Camera cam;

float halfsize = 25;

void setup(){
 size(720, 480, OPENGL);
 
 pgl = (PGraphicsOpenGL) g;
 gl = pgl.gl;

 cam = new Camera(this, 55, 65, -50);  
 
}

void draw(){
 
 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 
 gl.glEnable(GL.GL_DEPTH_TEST);
 gl.glEnable(GL.GL_LIGHTING);
 gl.glEnable(GL.GL_LIGHT0);
 gl.glEnable(GL.GL_COLOR_MATERIAL);
 
 cam.circle(0.02);
 cam.feed();  
 
 float[] p = cam.position();    
 gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[]{p[0], p[1], p[2], 0.0}, 0);
 
 pgl.beginGL();  
   gl.glPushMatrix();
   
   gl.glBegin(GL.GL_QUADS);
   gl.glColor3f(0.9f, 0.2f, 0.4f);
   
   gl.glNormal3f( halfsize, halfsize,-halfsize); // Normal
   gl.glVertex3f( halfsize, halfsize,-halfsize); // Top: Top Right  
   gl.glNormal3f(-halfsize, halfsize,-halfsize); // Normal  
   gl.glVertex3f(-halfsize, halfsize,-halfsize); // Top: Top Left  
   gl.glNormal3f(-halfsize, halfsize, halfsize); // Normal  
   gl.glVertex3f(-halfsize, halfsize, halfsize); // Top: Bottom Left  
   gl.glNormal3f( halfsize, halfsize, halfsize); // Normal  
   gl.glVertex3f( halfsize, halfsize, halfsize); // Top: Bottom Right  
   
   gl.glNormal3f( halfsize,-halfsize, halfsize); // Normal  
   gl.glVertex3f( halfsize,-halfsize, halfsize); // Bottom: Top Right  
   gl.glNormal3f(-halfsize,-halfsize, halfsize); // Normal  
   gl.glVertex3f(-halfsize,-halfsize, halfsize); // Bottom: Top Left  
   gl.glNormal3f(-halfsize,-halfsize,-halfsize); // Normal  
   gl.glVertex3f(-halfsize,-halfsize,-halfsize); // Bottom: Bottom Left  
   gl.glNormal3f( halfsize,-halfsize,-halfsize); // Normal
   gl.glVertex3f( halfsize,-halfsize,-halfsize); // Bottom: Bottom Right
   
   gl.glNormal3f( halfsize, halfsize, halfsize); // Normal  
   gl.glVertex3f( halfsize, halfsize, halfsize); // Front: Top Right  
   gl.glNormal3f(-halfsize, halfsize, halfsize); // Normal
   gl.glVertex3f(-halfsize, halfsize, halfsize); // Front: Top Left  
   gl.glNormal3f(-halfsize,-halfsize, halfsize); // Normal
   gl.glVertex3f(-halfsize,-halfsize, halfsize); // Front: Bottom Left  
   gl.glNormal3f( halfsize,-halfsize, halfsize); // Normal
   gl.glVertex3f( halfsize,-halfsize, halfsize); // Front: Bottom Right
   
   gl.glNormal3f( halfsize,-halfsize,-halfsize); // Normal
   gl.glVertex3f( halfsize,-halfsize,-halfsize); // Back: Top Right  
   gl.glNormal3f(-halfsize,-halfsize,-halfsize); // Normal
   gl.glVertex3f(-halfsize,-halfsize,-halfsize); // Back: Top Left  
   gl.glNormal3f(-halfsize, halfsize,-halfsize); // Normal
   gl.glVertex3f(-halfsize, halfsize,-halfsize); // Back: Bottom Left  
   gl.glNormal3f( halfsize, halfsize,-halfsize); // Normal
   gl.glVertex3f( halfsize, halfsize,-halfsize); // Back: Bottom Right    
   
   gl.glNormal3f(-halfsize, halfsize, halfsize); // Normal
   gl.glVertex3f(-halfsize, halfsize, halfsize); // Left: Top Right  
   gl.glNormal3f(-halfsize, halfsize,-halfsize); // Normal
   gl.glVertex3f(-halfsize, halfsize,-halfsize); // Left: Top Left  
   gl.glNormal3f(-halfsize,-halfsize,-halfsize); // Normal
   gl.glVertex3f(-halfsize,-halfsize,-halfsize); // Left: Bottom Left  
   gl.glNormal3f(-halfsize,-halfsize, halfsize); // Normal
   gl.glVertex3f(-halfsize,-halfsize, halfsize); // Left: Bottom Right  
   
   gl.glNormal3f( halfsize, halfsize,-halfsize); // Normal
   gl.glVertex3f( halfsize, halfsize,-halfsize); // Right: Top Right  
   gl.glNormal3f( halfsize, halfsize, halfsize); // Normal
   gl.glVertex3f( halfsize, halfsize, halfsize); // Right: Top Left  
   gl.glNormal3f( halfsize,-halfsize, halfsize); // Normal
   gl.glVertex3f( halfsize,-halfsize, halfsize); // Right: Bottom Left  
   gl.glNormal3f( halfsize,-halfsize,-halfsize); // Normal
   gl.glVertex3f( halfsize,-halfsize,-halfsize); // Right: Bottom Right  
     
   gl.glEnd();  
     
   gl.glPopMatrix();  
 pgl.endGL();
 
}


thank you
Page Index Toggle Pages: 1