问题
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.
回答1:
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_BUFFERinstead ofGL_ARRAY_BUFFERCreate 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 usingglGetShaderInfoLogCreate 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 withglGetProgramandglGetProgramInfoLog
When you want to draw:
Bind the vertex and index buffers using
glBindBufferwith argumentsGL_ARRAY_BUFFERandGL_ELEMENT_ARRAY_BUFFERrespectivelyBind the program with
glUseProgramNow for each varying variable in your shaders, you have to call
glVertexAttribPointerwhose 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 callingglGetAttribLocationon 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
glActiveTexturewithGL_TEXTUREi(i being different for each texture), thenglBindTextureand 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
来源:https://stackoverflow.com/questions/3746376/opengl-3-2-core-profile-guide