Question about where exactly OpenGL starts

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
bunnyman3344
Gremlin
Posts: 189
Joined: Fri May 21, 2010 9:01 am
Location: Tardis
x 1

Question about where exactly OpenGL starts

Post by bunnyman3344 »

The name MIGHT be weird (actually, it is weird). I couldn't think of a better title for this post.......ANYWAY, I'm wondering in what order should I specify vertices in OpenGL.
I'm still a bit confused as to what order to specify vertices, I want to understand which order, like <0,10>,<10,10>, <-10,10>, ect.....Also, can you believe my teacher wont let me use OOP? seriously........she said she'd fail me if I used classes, what the hell kind of teacher is that? (her excuse? openGL isn't OOP).......Uh, C++ it.....*sigh* it's either do it her way and maybe pass or my way and fail......damn it. I'm sorry, she's just got me so ticked off, it's not even funny.......
"One Shall Stand....One Shall Fall"
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Question about where exactly OpenGL starts

Post by Kojack »

There's one important thing to consider when choosing the order of vertices: winding.
When rendering a model, on average around half of the triangles that make up the model are facing away from the camera. If the model isn't transparent, there's no way to see these triangles. So to speed up rendering, the GPU can ignore all triangles that face away from the camera, potentially halving the amount of work to do.
The way the GPU checks if a triangle is facing away is by looking at the winding direction of the triangle. It does this by considering if the camera's view of the triangle sees the vertices in clockwise or anti-clockwise (some people call it counter-clockwise) order. In both Ogre and OpenGL, anti-clockwise is the default winding direction for rendering, so any clockwise faces are skipped. (You can change this in the material of a mesh).

Here's a triangle we are seeing from the front:
Image
The vertex order going from 0 to 1 to 2 is anti-clockwise, so it is rendered.

The same triangle viewed from behind:
Image
The vertex order is now clockwise, is the triangle would be ignored by the GPU.

The actual order of the vertices doesn't matter (any of them could be the first vertex), as long as they all go anti-clockwise.


As for OO programming... it depends on the reasoning. If she wants to see if you can do it without classes, that's fair enough (for example, I make my students do 3d rendering in directx without being allowed to use any directx math functions, they have to write their own. It's to test their math coding ability). But if she just thinks OO is bad, then I'd be pissed off too in that situation.
One of the important skills for a programmer who works with others is to be able to change the way you code when needed. Companies can have strict coding style guides. I was in a team where we had a strict (as in code would be rejected) rule that no line of code could be longer than 78 characters. This was so it could be printed without word wrapping (we did printouts of all code for peer reviews). I hated that rule, my screen fit more than that on it and I never print my own code. But that was the team rule, so that's what I did. Now that I'm a teacher, I always try to explain any odd requirements so students know why I put them there (such as why I force them to write a network chat program with UDP even though TCP would have been simpler).
Post Reply