Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am working on creating an object loader for use with iOS, I have managed to load the vertices, normals and face data from and OBJ file, and then place this data into arrays for reconstructing the object. But I have come across an issue with the lighting, at the bottom is a video from the simulation of my program - this is with the lighting in the following position:

CGFloat position[] = { 0.0f, -1.0f, 0.0f, 0.0f };
glLightfv(GL_LIGHT0, GL_POSITION, position);

This is specified in both the render method each frame and the setup view method which is called once at setup.

Various other lighting details are here, these are called once during setup:

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
CGFloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
CGFloat diffuseLight[] = { 1.0f, 0.0f, 0.0, 1.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
CGFloat position[] = { 0.0f, -1.0f, 0.0f, 0.0f };
glLightfv(GL_LIGHT0, GL_POSITION, position);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE);

The video of the issue can be found here:

http://youtu.be/dXm4wqzvO5c

Thanks,

Paul

[EDIT]

Normals are also supplied by the following code, they are currently in a large normals array or XYZ XYZ XYZ etc...

// FACE SHADING
glColorPointer(4, GL_FLOAT, 0, colors);
glEnableClientState(GL_COLOR_ARRAY);
glNormalPointer(GL_FLOAT, 3, normals);
glEnableClientState(GL_NORMAL_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, 3*numOfFaces); 
glDisableClientState(GL_COLOR_ARRAY);

[ANSWERED!]

I have solved the issue but can't post the answer as I have too little reputation, but it was simply down to a typo!

glNormalPointer(GL_FLOAT, 3, normals);

should read

glNormalPointer(GL_FLOAT, 0, normals);

as all the normal data is in a single un shared array, so it does not need to skip values..

share|improve this question
    
unrelated to your question but I think you can make a good game out of that buggy lighting system! –  Ali.S Sep 30 '11 at 15:00
    
Are you storing the normals on the obj file or regenerating them on loading? –  r2d2rigo Sep 30 '11 at 15:18
    
In the video are you rotating the object or are you rotating the camera (possibly arcball camera?) –  Roy T. Sep 30 '11 at 16:32
    
@Gajet it would look much better if it worked! haha –  Paul Reed Sep 30 '11 at 17:03
    
@r2d2rigo I am storing the normals in a float array, which is stored in a 3d model object in the program. So taking them from file, but they are what the file says they are; I have used NSLog to check. For each vertex of a polygon I am supplying a XYZ normal value as the code above in the array –  Paul Reed Sep 30 '11 at 17:03

1 Answer 1

up vote 0 down vote accepted

I have solved the issue, was simply down to a typo of sorts!

glNormalPointer(GL_FLOAT, 3, normals);

should read

glNormalPointer(GL_FLOAT, 0, normals);

as all the normal data is in a single un shared array, so it does not need to skip values.. I thought the three was for there are 3 values for each normal stupidly!

share|improve this answer
    
Please mark this as the correct answer (click the outline of a checkmark next to the up/down arrows). –  ashes999 Oct 1 '11 at 20:30
    
I cannot do it for another ten hours! :) –  Paul Reed Oct 2 '11 at 3:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.