Welcome to a series I have planned on OpenGL 3.0 regarding the forward compatible mode, or in layman’s terms, using OpenGLwithout all the stuff that got cut.
It’s quite a different beast to work with, even I have problems getting my head around it since so much things that you used for every other line has to be done differently, I find myself adding the line glTranslatef(…. only to suddenly stop thinking “o, right, doesn’t work anymore”.
It’s a bit harder also as you have to use shaders or it won’t be drawn, you cant just use a VBO like before but instead you have to bind it to a input variable.
In short everything is different, but I will try to guide you trough the basic stuff, but look at it from the bright side, now you have no more excuse not to code the way it should be done.
So what got cut well quite a bit, take a look at http://www.opengl.org/documentation/specs/ and download the 3.0 specification and then check under the section called “The Deprecation Model”, but here are some highlights
Immediate mode – glBegin, glEnd, glColor*, glFogCoord*, glIndex*, glNormal3*, glSecondaryColor3*, glTexCoord*, glVertex*.
Which means you have to use VBOs.
Vertex processing – glColorPointer, glEdgeFlag-Pointer, glFogCoordPointer, glIndexPointer, glNormalPointer, glSecondary-ColorPointer, glTexCoordPointer, glVertexPointer, glEnableClientState, glDisableClientState, and glClientActiveTexture.
Which means you have you use a vertex shader in order to render.
Matrix processing – glFrustum, glLoadIdentity,glLoadMatrix, glLoadTransposeMatrix, glMatrixMode, glMult-Matrix, glMultTransposeMatrix, glOrtho, glPopMatrix, glPushMatrix, glRotate, glScale, and glTranslate.
Which means you have to calculate all translations and rotations yourself.
Fixed function stuff – like alpha testing and lighting is now done by the shaders, but not blending.
Also display lists, evaluators, accumulation buffers and selection and feedback render modes, but they shouldn’t be used anyway.
Ok, so how about some code then, how do we set up a window so that all the old stuff doesn’t work.
It turns out it’s not that straight forward.
Essentially what we need to do is to call wglCreateContextAttribsARB instead of wglCreateContext, the tricky part is that wglCreateContextAttribsARB is an extension and to be able to use it with the help of wglGetProcAddress we need a rendering context, which is exactly what wglCreateContextAttribsARB does, so we need to trick it.
First we need to define our attribute list, basically a bunch of variables that dictate which version we need to run.
int attribList =
Note that if you comment out the third line in this array it will allow you to use all the deprecated stuff, a good tip to check if all of this works.
Next we create a temporary context and make it current.
|HGLRC tempContext = wglCreateContext(window->hDC);
then get the proc address for wglCreateContextAttribsARB and check if it works.
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress("wglCreateContextAttribsARB");
if(wglCreateContextAttribsARB == NULL) //OpenGL 3.0 is not supported
finally create the new 3.0 context delete the temp context and make the new once current
wglMakeCurrent (window->hDC, window->hRC);
and that should be it, though implementation may wary from code to code, this one is tested against the base code use in my previous tutorials and will probably also work with the old nehe base code.
In part 2 I will try to render something on the screen.