howto use Vertex Buffer objects(vbo) with opengl & Qt
Posted: October 31, 2009 Filed under: Game Development | Tags: howto, openGL, qt, vbo 1 Comment »This how-to concerns, including the functions needed for using Vertex Buffer Objects or VBOs; but in Qt framework. In short, this answers questions like:
“ glGenbuffers : identifier not found error
How do I resolve this (when working in Qt)? “
This article at gamedev explains the process very well. The article is old, but I would recommend reading it since you then understand what the problem is and why is it giving you this error.
After you’re done reading that, you’d know that you are still using openGL v1.1 and need to access VBOs which is a feature of openGL v1.5. This is done by using v1.5 as extensions and interacting with the device drivers(assuming you have the latest drivers and they support v1.5), which is facilitated in code by specific function pointers.
By now, you’d know how to get this fixed if you were on a windows machine. But, I was using Qt and needed a way to get it to work with that. I came across these files:
glextensions.h and
glextensions.cpp
provided by Qt in one of there demos (boxes). These would resolve the functions you need for using VBOs. To get it to work, the code is not trivial.
After including the files in your header, one needs to “resolve()” the associated functions with a “context” (which is provided by the QGLWidget (or a class that you might have derived from it) ).
This is how I resolve them from within my class which derives from QGLWidget:
getGLExtensionFunctions().resolve(this->context() );
Functions like glGenBuffers, glBindBuffer, glBufferData etc are now ready to be used.
Also, I heard a lot of people using GLEW but I did not explore that route, so if you are stuck that might be something worthwile to checkout.
I hope it this article has saved you both, hours and tears. Let me know if you need any help.
(PS: When you call the resolve() function, the context should be available. I am still not 100% clear on how Qt manages the context for you, but I call it within InitializeGL(), since the context would be ready when the control reaches there. Also, take a look at the glextensions files to see they do pretty much the same thing as mentioned in the gamedev article )
True words, some authentic words dude. Thanks for making my day!