# Understanding OpenGL

I am reading through a the Xojo3D guide. It is really good btw. I am having trouble understanding what is meant by anti-clockwise in terms of a 3D enviroment.

‘IMPORTANT: The vertices of a polygon is always defined in an anti-clockwise order, so that OpenGL knows which way the polygon is facing.’

Does it just mean that you should define polygons further back first?

Maybe it’s just me and my comprehension and this needs clarifying for me or this could be improved by Alwyn. But great work Alwyn, your guide seems great for beginner programmers.

Thanks

‘A an B’, typo at http://xojo3d.com/tut007.php?

The typo in tutorial 7 is fixed. Anti-clockwise should rather be referred to as counterclockwise, so I’ve updated the pages with this change as well.

[quote=123676:@Oliver Scott-Brown]‘IMPORTANT: The vertices of a polygon is always defined in an anti-clockwise order, so that OpenGL knows which way the polygon is facing.’

Does it just mean that you should define polygons further back first?[/quote]

No, counterclockwise does not imply this. Counterclockwise simply means that the order in which the vertices of your polygon is defined is done in a counterclockwise direction. Without getting to much into the maths about it, the direction in which the vertices is defined determines the direction in which the normal vector of the polygon will point. This is important because the normal vector is used during light calculations and to determine if a polygon is facing away from us, or towards us.

Tutorial 1 gives diagrams that illustrates the counterclockwise direction.

You are however touching on a topic that is important when you start drawing transparent polygons with OpenGL. Then the polygons further should be drawn before the near polygons. This is a however a much more advanced topic. I suggest you first become comfortable with drawing opaque polygons (non-see-through) before tackling transparent polygons.

Please feel welcome to ask any questions you might have with regards to 3D programming with OpenGL, There is lots to learn, but it is certainly a very interesting and fun area of computer science.

I’m just guessing but…

Lets say you have a triangle (simplest polygon)
Only one side of that polygon has a face - meaning only one side gets drawn. This is for optimization and other reasons in 3d engines.
How do you determine given 3 points in 3d space, which side of the triangle gets drawn? The counter-clockwise order determines this.

I think the clockwise counterclockwise thing just has to do with face culling, the normal is separately defined. With face culling turned off you won’t see a difference from orientation, the triangle is always filled. But if face culling is turned on then the orientation of the triangle determines whether it’s filled. You have a choice to cull front faces, back faces or both even.

Alwyn has a nice picture of it (the numbered vertex Front and Back triangles). Imagine looking at the Front triangle in 3D space and rotate it about the vertical axis to get the Back orientation. Mid way through you’re looking at the triangle edge on and then the orientation flips. There’s a math trick that lets opengl know a triangles orientation quickly and you have the option to cull faces based on that.

So if you know a triangle will only be seen from one side you can build them with the proper winding and cull the orientation you don’t need, leading to possibly fewer fills.

The typo in tutorial 7 is fixed. Anti-clockwise should rather be referred to as counterclockwise, so I’ve updated the pages with this change as well.

No, counterclockwise does not imply this. Counterclockwise simply means that the order in which the vertices of your polygon is defined is done in a counterclockwise direction. Without getting to much into the maths about it, the direction in which the vertices is defined determines the direction in which the normal vector of the polygon will point. This is important because the normal vector is used during light calculations and to determine if a polygon is facing away from us, or towards us.

Tutorial 1 gives diagrams that illustrates the counterclockwise direction.

You are however touching on a topic that is important when you start drawing transparent polygons with OpenGL. Then the polygons further should be drawn before the near polygons. This is a however a much more advanced topic. I suggest you first become comfortable with drawing opaque polygons (non-see-through) before tackling transparent polygons.

Please feel welcome to ask any questions you might have with regards to 3D programming with OpenGL, There is lots to learn, but it is certainly a very interesting and fun area of computer science.[/quote]
Hey, Alwyn. Thanks for your work. You mentioned using display lists? Is this part of the Xojo3D engine and does the tutorials show you how to use it. I am sure I will be able to work it out but I was wondering if you mentioned it anywhere. From a quick Google, it looks pretty easy to do.

Thanks

The typo in tutorial 7 is fixed. Anti-clockwise should rather be referred to as counterclockwise, so I’ve updated the pages with this change as well.

No, counterclockwise does not imply this. Counterclockwise simply means that the order in which the vertices of your polygon is defined is done in a counterclockwise direction. Without getting to much into the maths about it, the direction in which the vertices is defined determines the direction in which the normal vector of the polygon will point. This is important because the normal vector is used during light calculations and to determine if a polygon is facing away from us, or towards us.

Tutorial 1 gives diagrams that illustrates the counterclockwise direction.

You are however touching on a topic that is important when you start drawing transparent polygons with OpenGL. Then the polygons further should be drawn before the near polygons. This is a however a much more advanced topic. I suggest you first become comfortable with drawing opaque polygons (non-see-through) before tackling transparent polygons.

Please feel welcome to ask any questions you might have with regards to 3D programming with OpenGL, There is lots to learn, but it is certainly a very interesting and fun area of computer science.[/quote]
Another question is - does the engine handle display lists for me? Thanks

I think your materials tutorial is really cool! I might play around with colours and materials. Thanks

You’re welcome Oliver.

Display lists is an OpenGL feature. The idea is very simple, you record a list of OpenGL “instructions” into a list. Once the list is created, you can “replay” these instructions at any time with a single call. It’s almost like… what a function does for Xojo, a display lists does for OpenGL.

Great stuff. The more your experiment the more you learn. Tutorials can only give an introduction, real experience comes from using your knowledge.

Forgot to mention… the X3 engine handles display lists for you automatically.

[quote=123877:@Alwyn Bester]You’re welcome Oliver.

Display lists is an OpenGL feature. The idea is very simple, you record a list of OpenGL “instructions” into a list. Once the list is created, you can “replay” these instructions at any time with a single call. It’s almost like… what a function does for Xojo, a display lists does for OpenGL.

Great stuff. The more your experiment the more you learn. Tutorials can only give an introduction, real experience comes from using your knowledge.[/quote]
Thanks