Strange behaviour [solved]

Started by
10 comments, last by jeroenb 18 years, 4 months ago
I am working on a project, where I noticed some strange flipping with the default opengl backface culling. On the image you can see what I mean (it is not the clearest picture). This picture contains a lot of boxes (all generated the same way, including per vertex normals). At the center of the image suddenly the front of the box isn't visible anymore but only the backside. During rotation, this 'swap' moves with the camera (I use the fixed pipeline). I have no clue what is going on here :s I have set up opengl just as normal. [Edited by - jeroenb on November 30, 2005 7:28:27 AM]

Crafter 2D: the open source 2D game framework

?Github: https://github.com/crafter2d/crafter2d
Twitter: [twitter]crafter_2d[/twitter]

Advertisement
seriously no one can see what is going on there but try and set ur NearPlane closer in

glPerspective(45,widht,height,ratio,nearplane,farplane);
----------------------------

http://djoubert.co.uk
Seams to me like not all the normals are pointing the right way.
The direction (perpendicular to the face of the box) may be right, but the normals have to point to the outside of the boxes.
I drawed a red line around the area where the strange behaviour can be seen best. The left box shows the correct faces, while the box to the right of it looks like to use an entirely different winding order. Odd thing is that all those boxes are generated the same, only thing I do is rotating them around the z-axis (the normals are calculated and averaged, thus not perpendicular to the face, after the rotations).

But I will have yet another look at the winding order/normals etc to see what is wrong.

Thanks for the replies!

ps. ignore the red dot, that has nothing to do with the problem :)

Crafter 2D: the open source 2D game framework

?Github: https://github.com/crafter2d/crafter2d
Twitter: [twitter]crafter_2d[/twitter]

Quote:Original post by Kwak
Seams to me like not all the normals are pointing the right way.
The direction (perpendicular to the face of the box) may be right, but the normals have to point to the outside of the boxes.

Normals are not used for face culling, only vertex winding order is.

OP: Thats a slightly odd problem you've got there. :S Are you perhaps doing any mirroring or other fliping via the modelview matrix? Negative scales/mirrors will reverse the winding order and you'll have to change the cull face. Other than that the only thing I can suggest is to turn off face culling to check that that really is the problem.
Also, perhaps double and triple check the vertex data you're sending to OpenGL.
Quote:Original post by OrangyTang
Normals are not used for face culling, only vertex winding order is.


Yeah - my first guess would be the vertex winding order... make sure the vertices are all orderde counter-clockwise (or clockwise) and set the openGL backface culling state approprately (unforuntately, I can't remember the call off the top of my head...)



Certainly looks like the winding order got reversed by mirroring. Particularly those gaps between boxes since they occur right at the position that you transition from drawing correctly to drawing incorrectly. That seems to be the plane of the front face of the structure on the platform to the top right suggesting that might be a coordinate plane of the object.
Keys to success: Ability, ambition and opportunity.
I also forgot to mention that I use a modified JOGL for rendering (I made it use an FBO instead of a PBuffer for offscreen rendering) on the java platform :s.

I quadruple checked the winding order and finally got the idea to do a translate instead of a gluLookAt and that seemed to solve the problem. I do wonder though why it goes wrong when I use gluLookAt.

When I use fill mode with T&L lighting, it still looks completely wrong. I have a point light at position <0,0,0>, thus inside the geometry tunnel. When I look normally the geometry is lit, but when I rotate the geometry 180 degrees it is not. Strange is also that the geometry on the outside is also lit :s.

Crafter 2D: the open source 2D game framework

?Github: https://github.com/crafter2d/crafter2d
Twitter: [twitter]crafter_2d[/twitter]

--removed original message--

After player some more with it, the same problems arise with the pbuffer. Also is does not seem to be affected with changing gluLookAt to a translate (luckily). So, I am still at the same point as before. Guess I have to display normals to see how these are.

[Edited by - jeroenb on November 30, 2005 5:45:52 AM]

Crafter 2D: the open source 2D game framework

?Github: https://github.com/crafter2d/crafter2d
Twitter: [twitter]crafter_2d[/twitter]

This topic is closed to new replies.

Advertisement