Can anyone suggest a guide for learning the OpenGL 3.2 core profile?
The SDK is hard to read, and most of the guides I have seen only taught the old method.
Can anyone suggest a guide for learning the OpenGL 3.2 core profile?
The SDK is hard to read, and most of the guides I have seen only taught the old method.
I don't know any good guide but I can make you a quick summary
I'll assume that you are already familiar with the basics of shaders, vertex buffers, etc. If you don't, I suggest you read a guide about shaders first instead, because all OpenGL 3 is based on the usage of shaders
On initialisation:
Create and fill vertex buffers using
glGenBuffers
,glBindBuffer(GL_ARRAY_BUFFER, bufferID)
andglBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW)
Same for index buffers, except that you use
GL_ELEMENT_ARRAY_BUFFER
instead ofGL_ARRAY_BUFFER
Create textures exactly like you did in previous versions of OpenGL (
glGenTextures
,glBindTexture
,glTexImage2D
)Create shaders using
glCreateShader
, set their GLSL source code usingglShaderSource
, and compile them withglCompileShader
; you can check if it succeeded withglGetShaderiv(shader, GL_COMPILE_STATUS, &out)
and retrieve error messages usingglGetShaderInfoLog
Create programs (ie. a group of shaders bound together, usually one vertex shader and one fragment shader) with
glCreateProgram
, then bind the shaders you want usingglAttachShader
, then link the program usingglLinkProgram
; just like shaders you can check linking success withglGetProgram
andglGetProgramInfoLog
When you want to draw:
Bind the vertex and index buffers using
glBindBuffer
with argumentsGL_ARRAY_BUFFER
andGL_ELEMENT_ARRAY_BUFFER
respectivelyBind the program with
glUseProgram
Now for each varying variable in your shaders, you have to call
glVertexAttribPointer
whose syntax is similar to the legacyglVertexPointer
,glColorPointer
, etc. functions, except for its first parameter which is an identifier for the varying ; this identifier can be retrieved by callingglGetAttribLocation
on a linked programFor each uniform variable in your shaders, you have to call
glUniform
; its first parameter is the location (also a kind of identifier) of the uniform variable, which you can retrieve by callingglGetUniformLocation
(warning: if you have an array named "a", you have to call the function with "a[0]")For each texture that you want to bind, you have to call
glActiveTexture
withGL_TEXTUREi
(i being different for each texture), thenglBindTexture
and then set the value of the uniform to iCall
glDrawElements
This is the basic things you have to do. Of course there are other stuff, like vertex array objects, uniform buffers, etc. but they are merely for optimization purposes
Other domains like culling, blending, viewports, etc. remained mostly the same as in older versions of OpenGL
I also suggest you study this demo program (which uses vertex array objects). The most interesting file is main.cpp
Hope this can help