views:

95

answers:

2

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.

+2  A: 

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) and glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW)

  • Same for index buffers, except that you use GL_ELEMENT_ARRAY_BUFFER instead of GL_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 using glShaderSource, and compile them with glCompileShader ; you can check if it succeeded with glGetShaderiv(shader, GL_COMPILE_STATUS, &out) and retrieve error messages using glGetShaderInfoLog

  • 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 using glAttachShader, then link the program using glLinkProgram ; just like shaders you can check linking success with glGetProgram and glGetProgramInfoLog

When you want to draw:

  • Bind the vertex and index buffers using glBindBuffer with arguments GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER respectively

  • Bind the program with glUseProgram

  • Now for each varying variable in your shaders, you have to call glVertexAttribPointer whose syntax is similar to the legacy glVertexPointer, glColorPointer, etc. functions, except for its first parameter which is an identifier for the varying ; this identifier can be retrieved by calling glGetAttribLocation on a linked program

  • For 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 calling glGetUniformLocation (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 with GL_TEXTUREi (i being different for each texture), then glBindTexture and then set the value of the uniform to i

  • Call 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

Tomaka17