Learning OpenGL. Log 4

This post is part of a series of logs of my journey in learning OpenGL (or as some say, modern OpenGL. OpenGL 3.1+).

—————————————————————————————————————————————–

Since the last log. I’ve done a lot of code exercises, basically involving implementing the render system in my engine. The main two focus were moving away from the homogenous/normalized device coordinate system and using VAOs(vertex array objects) properly.

Projection, projections

I spent  quite a bit of time over the last couple days learning and implementing perspective and orthogonal projects (and wrapping them into a simple camera class). It’s been quite a few years since I’ve done calculus back in high school. Where I’ve learnt the basics of matrix maths. I know how matrix multiplication works and I do have some basic ideas on what the maths are doing when I looked at the necessary steps to create a perspective project matrix, but I didn’t really understand the higher level concepts and theories in the transformations. Mostly because my brain was in denial and did not want to learn them, plus I just couldn’t care less at the time. So I did what any lazy person would and went the premixed cake flour route. I read a bunch of tutorials online and books and stitch together bits and pieces of codes that will work for now. Leaving the mess to my future self to worry later. At the end of the day. The minimal you need to know when comes to learning new stuff is knowing what things do, but not how they do it. At least that’s how I look at it.

Vertex Buffer Objects

I only just picked up what vertex buffer objects really do yesterday. Reading any tutorial or guide on modern OpenGL. One of the first things you do when you want to draw something (e.g. a triangle). You have to setup a vertex buffer object by calling glGenVertexArray(), and bind it by calling glBindVertexArray(). They then move on to do other stuff only to never return to the generated vertex array object (aka: VAO).

After spending much time on Google-ing, reading and cursing. I’ve finally came to the understanding that the VAO is conceptually just an object that records all the configure and setup calls such as glBindBuffer(), glEnableVertexAttriArray()m gkVertexAttribPointer() when it is binded. So instead of calling those functions everytime I made a draw call. I can just create and bind a VAO  and make those calls during object setup, and then bind the VAO each time I want to draw the object and unbind right after. When drawing multiple objects (e.g. multiple triangle shapes), each object should have their own vertex buffer object and just bind it when it needs to be drawn. Very cool stuff.

One thing to take note here: The usual order to setup things up is the following:

  • create and bind a VAO
  • create and bind a vertex buffer object (VBO)
  • buffer data.
  • call your gl*Pointer functions to enable and set attributes. (This automatically associates the attributes with the VBO. Don’t call glDisableAttribPointer() here.
  • you can unbind your VBO now. (as far as I can tell it doesn’t effect anything).
  • unbind VAO
  • call glDisableVertexAttribPointer(). (seems to be optional. I am not sure if I am suppose to).

Next

The next thing I will learn and work on is textures and simple lights.

Leave a Reply

Your email address will not be published. Required fields are marked *