PDA

View Full Version : How to read and understand openGL coding?



myst_iori
06-03-2011, 10:44 AM
Hello everyone,

I'm new to openGL, and I'm very confused when reading openGL source, specifically the transformation and process of mapping each coordinate into the window scene. So my question is, what approach do OpenGL programmers use to understand the code?
- Do I need to actually perform the matrix calculation part to figure out how glOrtho(), glFrustum(), gluPerspective()?
- Or it will gradually becomes a second nature after a good amount of practice? Still, I don't think this is going to work due to the fact that coordinates are actual numbers, I couldn't find another way except performing the calculation, even drawing them in paper.
Any feedback would be greatly appreciated.

Thank you,

Aleksandar
06-03-2011, 03:30 PM
So my question is, what approach do OpenGL programmers use to understand the code?
They post their code at the forum and ask the community: how does it work? :)

Just kidding! If you have problems with basic concepts I advice you to read some good book about legacy OpenGL, for example OpenGL Programming Guide (aka Red Book). After first three chapters you'll grab the basic concepts and you can go further.

Don't worry, you won't need to multiply matrices manually to figure out which transformations and in which order they should be applied. If you get the concepts it is quite natural way of thinking. After all, you can execute your code and figure out if it works correctly. ;)

Alfonse Reinheart
06-03-2011, 07:34 PM
So my question is, what approach do OpenGL programmers use to understand the code?

There are generally two approaches. The sadly common approach is the one you seem to be leaning towards: find the correct order to call the OpenGL functions in that will allow you to get a result not entirely unlike what you want. This one focuses on easy results early on, at the cost of doing a lot more "unlearning" later.

Personally, I prefer the other approach: understand how graphics works, then understand what the OpenGL calls do; therefore, when the time comes to implement something you want, you will be able to implement anything you want easily and with relatively little trouble.

One of the things I like about programmable rendering and working with core OpenGL is that the first approach is more or less impossible. Unless someone provides you with base code that hides the details, you have to know how stuff works. You have to understand it. You have to know what a matrix is, how matrices are multiplied by vectors, what coordinate systems are, etc. If you don't know these things, then there's much less of a chance for you to accidentally get something working.

I'm working on a series of tutorials for beginners aimed at teaching them this way. The link is in my signature if you're interested.

RefleX
06-04-2011, 12:10 PM
First thing you got to have a solid understanding of the language you are working with(eg.C++). Next you have to familiar with your IDE(eg.Visual Studios, Code::Blocks, Qt Creator, etc.). After you have these foundations you can start learning OpenGl, I would recommend you read OpenGL Super Bible 5th Edition (http://www.amazon.com/OpenGL-SuperBible-Comprehensive-Tutorial-Reference/dp/0321712617) it's a good book for newcomers and doesn't bother with old deprecated features of opengl but it has one fault, some of the code they display works on a framework the author created which is bad news for someone that wants to know how to write code from scratch but generally it's a good book. A good book for C++ is C++ Primer Plus 5th Edition (http://www.amazon.com/Primer-Plus-5th-Stephen-Prata/dp/0672326973/ref=sr_1_1?s=books&ie=UTF8&qid=1307214531&sr=1-1).

dorbie
06-05-2011, 03:41 AM
You can get by without knowing the details of the implementation of matrix operations. It is enough to understand conceptually how these work. Concepts like pre and post multiplication and transpose for row column order etc will be important.

As you use these you will develop a deeper understanding either because you will implement some of this for equivalent application code, will need to transition to your own code as the move to OpenGL 4 or OpenGL ES 2.0

myst_iori
06-05-2011, 02:03 PM
Thank you so much for all the recommendation. I think I should slow it down a bit, I was rush to got all openGL concepts in a week.
@Alfonse Reinheart: Your tutorial is just great ;). Many thanks.