I'm having a light problem in OpenGL.
I load in my C++ an eyeglasses OBJ containing the faces, normals e uvmapping exported with blender and I want to visualize the object in the user's face. The obj is this: https:https://drive.google.com/file/d/0B8ba1lz8BBHAUEVQX1hkYmtqYlE/view?usp=sharing
So, I solve a linear system that finds a transformation matrix to transform all the points of object from 3D to 2D. I transpose this matrix and load as my modelview matrix in opengl. This part is ok.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (0, 512, 512, 0, 100,-100); //Define a ortho
glMatrixMode (GL_MODELVIEW);
glLoadMatrixd(&mViewMatrix(0,0));
Now I want to add light effects in my glasses, so, I configure the light like this in opengl:
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 };
GLfloat light_position[] = { camXV2, camYV2, camZV2, 0.0 };
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
And I render the object and set its respective normals, but the results is something like this:
Blue is the real texture color, but as we can see the result is very far from the expected. Anyone help
[Edit by Spektre] obj preview with normals
Normals from OBJ:
Computed normals from faces (ignoring
vn
entries)
To test your engine try this Wavefront OBJ:
v -1.0 -1.0 -1.0
v +1.0 -1.0 -1.0
v +1.0 +1.0 -1.0
v -1.0 +1.0 -1.0
v -1.0 -1.0 +1.0
v +1.0 -1.0 +1.0
v +1.0 +1.0 +1.0
v -1.0 +1.0 +1.0
vn -0.333 -0.333 -0.333
vn +0.333 -0.333 -0.333
vn +0.333 +0.333 -0.333
vn -0.333 +0.333 -0.333
vn -0.333 -0.333 +0.333
vn +0.333 -0.333 +0.333
vn +0.333 +0.333 +0.333
vn -0.333 +0.333 +0.333
f 1 2 3 4
f 5 6 7 8
f 1 2 6 5
f 2 3 7 6
f 3 4 8 7
f 4 1 5 8
It is simple cube with normals set to shade it as a sphere.