On Sat, Feb 28, 2009 at 11:52 AM, bforrester
<[email protected]> wrote:
>
> I can't seem to get lighting to work right with glDrawElements. I have
> been working on this for quite some time now and can't seem to figure
> out what I'm doing wrong.  After googling, testing, logging, and
> beating my head against the keyboard, I'm hoping someone on this board
> can point out my folly :)
>
> I'm loading a very simple .obj file I exported from blender.  When I
> draw the object in immediate mode it lights/renders perfectly fine.
> Immediate mode is using the same root data (vertices, face indices,
> and calculated normals) as glDrawElements minus the pointers, so I
> know my normal calculations are correct.  When I use glDrawElements
> the geometry is right, but the lighting is very wrong (maybe almost
> random).  It makes me think that the normals pointer isn't right, but
> after double checking the code against examples, I'm pretty sure it's
> right.
>
> Anyway here are the relevant portions of my code.  My gl Init
> settings, and portions of the mesh class.  Maybe a fresh (more
> experienced) set of eyes will see something I'm glazing over.
>        for i in range(0, len(self.quads), 4):
>            p1 =Vector3( self.vertices[ (self.quads[i] * 3 )   ],
>                         self.vertices[ (self.quads[i] * 3 )+1 ],
>                         self.vertices[ (self.quads[i] * 3 )+2 ] )
>
>            p2 =Vector3( self.vertices[ (self.quads[i+1]*3)   ],
>                         self.vertices[ (self.quads[i+1]*3)+1 ],
>                         self.vertices[ (self.quads[i+1]*3)+2 ] )
>
>            p3 =Vector3( self.vertices[ (self.quads[i+2]*3)   ],
>                         self.vertices[ (self.quads[i+2]*3)+1 ],
>                         self.vertices[ (self.quads[i+2]*3)+2 ] )
>
>            v1 = p1 - p2
>            v2 = p2 - p3
>            v1.normalize()
>            v2.normalize()
>
>            cross = v1.cross(v2)
>            cross.normalize()
>
>            self.quad_normals.extend( [ cross.x, cross.y, cross.z ] )

It seems to me that you're only creating one normal for every four
quad indices.  There needs to be one normal for every vertex, and
there's no correspondence here at the moment.

Alex.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to