How to read and understand openGL coding?

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,

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? :slight_smile:

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. :wink:

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.

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 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.

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

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.