OpenGL SuperBible: Comprehensive Tutorial and Reference (4th Edition)

Category: Programming
Author: Richard S. Wright, Benjamin Lipchak, Nicholas Haemel
All Stack Overflow 9


by anonymous   2017-08-20

Depending on what you are trying to achieve and what is your current knowledge, you can take different approaches.

If you are trying to learn OpenGL 2.0 while also learning GLSL, I suggest getting the Red book and the Orange book as a set, as they go hand in hand.

If you want a less comprehensive guide that will just get you started, check out the OpenGL bible.

If I misunderstood your question and you already know OpenGL, and want to study more about GLSL in particular, here's a good phong shading example that shows the basics.

Compiling a shader source is really simple,

First you need to allocate a shader slot for your source, just like you allocate a texture, using glCreateShader:

GLuint vtxShader = glCreateShader(GL_VERTEX_SHADER);
GLuint pxlShader = glCreateShader(GL_FRAGMENT_SHADER);

After that you need to load your source code somehow. Since this is really a platform dependent solution, this is up to you.

After obtaining the source, you set it using glShaderSource:

glShaderSource(vtxShader, 1, &vsSource, 0);
glShaderSource(pxlShader, 1, &psSource, 0);

Then you compile your sources with glCompileShader:


Link the shaders to each other, first allocate a program using glCreateProgram, attach the shaders into the program using glAttachShader, and link them using glLinkProgram:

GLuint shaderId = glCreateProgram();
glAttachShader(shaderId, vtxShader);
glAttachShader(shaderId, pxlShader);

Then, just like a texture, you bind it to the current rendering stage using glUseProgram:


To unbind it, use an id of 0 or another shader ID.

For cleanup:

glDetachShader(shaderId, vtxShader);
glDetachShader(shaderId, pxlShader);



And that's mostly everything to it, you can use the glUniform function family alongside with glGetUniform to set parameters as well.

by itsmatt   2017-08-20

Here are a few books that I used when writing OpenGL code in C++:

Fundamentals of Computer Graphics

OpenGL SuperBible

OpenGL Red Book

OpenGL Primer

You might check out the MIT OpenCourse on computer graphics too. It might help supplement your development.

Best of luck!