OpenGL and Programmable Shaders

CS 381 Lecture, Dr. Lawlor

I've finally stripped down my set of OpenGL libraries to make a relatively simple example program.  It's called glsl_bare (Zip, Tar-gzip). (UPDATED Friday 3 pm: it should actually build anywhere now, and has been verified on Windows and Linux.  I provide a Visual C++ 2003 project file, Code::Blocks project file, and Linux/Mac OS X Makefile.)

C++ Libraries used with OpenGL

Name
Description
Reference
Header
Windows
Linux
Mac OS X
OpenGL
Basic rendering calls: triangles, vertices, textures, etc.
The OpenGL FAQ is a good place to start, or the Manual Pages. The  OpenGL 1.4 Specification is unreadable legalese.  The Red Book is dated but readable.
<GL/gl.h>

(note captialization, Windows people!)
opengl32.lib

(Usually have to add this to your project's linker properties...)
libGL.so
-framework OpenGL
GLUT
Create windows, set up buffers, handle keyboard and mouse.
The original GLUT API document is readable.
<GL/glut.h>
glut32.lib or freeglut.lib
libglut.so
-framework GLUT
GLEW
Dynamic interface to latest OpenGL routines.  A must for programmable shaders on Windows!
GLEW makes OpenGL routines work as advertised.  The only pure-GLEW routine is glewInit().
<GL/glew.h>

(Include first; this replaces GL/gl.h!)
(I prefer it statically linked)


GLUI
Buttons, scrollbars, dropdown menus, and other widgets.
I've prepared some doxygen comments. There's also an older GLUI manual.
<GL/glui.h>
(I prefer it statically linked)

ogl
Orion's random crappy OpenGL utilities
Read the ogl/ header files.
"ogl/util.h",
"ogl/main.h",
...
(I prefer it statically linked)


C++ Matrix and Vector Classes

I've posted two interesting header files as part of the glsl_bare example above:

    #include "osl/vec4.h"
    #include "osl/mat4.h"
    using namespace osl;

These contain an implementation of the GLSL "vec4" and "mat4" types in C++.  You can now usually just copy-and-paste GLSL vector and matrix code into C++, and it should "just magically work".  In particular, any legal GLSL vec4 or mat4 operation should be legal C++; but of course send me an email if you find a mismatch!

The command to upload a matrix into a GLSL program is glUniformMatrix4fv.  Call it with an osl "mat4" like this:
    glUniformMatrix4fvARB(glGetUniformLocationARB(prog,"mF"),1,0,&mF[0][0]);

The "1" is because we've only got one matrix to upload.  The "0" is because we don't need to transpose--mat4 is already column-major.