ofx3DUtils lights with ofxObjLoader

hi all

was originally hoping to load in a textured model but will wait until texture support is added to the obj loader as alternate libraries look pretty tricky.

so thought that instead i’d import a model, and draw it as a single colour reflecting lights created with the ofx3DUtils

i have imported a model into the ofx3DUtils example, and am drawing it next to the sphere. the sphere receives lights but the model does not

  
camera.place();//this MUST be inside the draw function, and actually places the camera in position  
ofxLightsOn(); //turn lights on  
ofSetColor(255, 255, 255);  
glPushMatrix();  
glTranslatef(centerX, centerY, centerZ);  
glRotatef(rotX, 1.0f, 0.0f, 0.0f);  
glRotatef(rotY, 0.0f, 1.0f, 0.0f);  
glutSolidSphere(200, 30, 30);  
  
//draw model:  
float s = min(ofGetWidth(),ofGetHeight())*0.2;  
glScalef(s,s,s);  
car.fillFaces();  
  
glPopMatrix();  
  
camera.remove();  
ofxLightsOff(); //turn lights off to draw text  

any advice on getting this to work or alternate approaches?

cheers
nay.

it seems to be a problem with the normals. in opengl, when using lights you need to define the normals of the surfaces, the normal is a normalized vector perpendicular from the surface. opengl needs this to calculate lights.

i was looking at the obj loader and it does import normals from your model, but the model must have this information. maybe yours doesn’t?

if you want i can have a look at your source, just email it to me at ruibmx at gmail dot com

hello, i was trying out ur ofx3dutils addon and it works very well! the only thing when i change the sphere to a solidcube in your example i get this weird artefacts which look like shadows from other sides of the cube… any ideas ?

How are you drawing the cube? Are you using glutSolidCube ?

If you are making the cube yourself then you need to specify normals for each vertex that makes up each side of the cube. Or at the very least for each face ie:

//for the left side
glBegin(GL_QUADS);
glNormal3f(-1, 0, 0);
glVertex…
glVertex…
glVertex…
glVertex…
glEnd();

hello theo , yes i used glutSolidCube . simply replacing the glutSolidsphere in the examplepatch. thought if it works on the sphere it should work on the cube . doesnt the normalsinformation come with glutSolidsphere ? here my output thnx for the info on the normals . aloha, eugen