OpenGL/GLUT Basics

CS 481 Lecture, Dr. Lawlor

C++ Libraries used with OpenGL

You can use many libraries along with OpenGL itself.  Here are a few we'll be using in this course:
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)


Calls you Should Already Know

(or else calls you need to look up right now!)

Vectors, dot, and cross products

You should know basic 2D and 3D vectors, including dot products and cross products. Vectors are basically all we ever deal with in computer graphics, so it's important to understand these pretty well.

In particular, you should know at least:
You should pick one of the thousands of "vec3" classes on the web to represent vectors in your code, or else you'll go insane writing "glSomething3f(foo_x,foo_y,foo_z); foo_x+=bar_x; foo_y+=bar_y; foo_z+=bar_z;" (instead, you'll be able to say "glSomething3fv(foo); foo+=bar;").

Sphere Geometry

FYI, a point on the surface of a unit sphere with coordinates (lat,lon) in degrees has 3D coordinates (x,y,z):
#include <math.h>
#define D2R (M_PI/180.0) /* degrees to radians */
double z=sin(D2R*lat);
double r=cos(D2R*lat); /* 2D radius at z cross-section */
double x=r*cos(D2R*lon), y=r*sin(D2R*lon);
For a unit sphere centered at the origin, a 3D surface point v's normal vector is... v.  No other surfaces work like that, but it's handy for spheres!