Intro to OpenGL

Actually, we will be using Mesa instead of OpenGL. The difference is not important from our point of view.

My first program

Download the code in threeDots.cc to your linux account. Compile and execute with g++ -o threeDots -L/usr/X11R6/lib -L/usr/lib/X11 -lglut -lGLU -lGL -lm -lX11 -lXi -lXmu threeDots.cc ./threeDots You can download and use the Makefile to ease building your OpenGL applications. In this case, you would just have to [arnold@cslinux ~/320]$ make threeDots g++ -L/usr/X11R6/lib -L/usr/lib/X11 -lglut -lGLU -lGL -lm -lX11 -lXi -lXmu threeDots.cc -o threeDots You can also try out f60.cc and bounce.cc (this shows you how to do animations, the key is glutIdleFunc(idle)). We won't discuss these in this tutorial.

References

Understanding OpenGL

OpenGL: device-independent, platform-independent

OpenGL libraries

OpenGLGLUGLUTGLUI
  • main library; graphics routines
  • header file: gl.h
    #include <GL/gl.h>
        
  • command prefix: gl; constant prefix: GL
  • example: glLineWidth(), GL_POLYGON
  • utility library; commands to set up matrices for viewing orientations and projections, perform polygon tessellation, and render surfaces
  • header file: glu.h
    #include <GL/glu.h>
        
  • command prefix: glu; constant prefix: GLU
  • example: gluLookAt()
  • utility toolkit; window and event management
  • header file: glut.h
    #include <GL/glut.h>
        
  • command prefix: glut; constant prefix: GLUT
  • example: glutSolidSphere(), GLUT_DOUBLE
  • user interface toolkit; buttons, etc.
  • header file: glui.h
    #include <GL/glui.h>
        

OpenGL is a State Machine

OpenGL is an immediate-mode API. Each command has an immediate effect based on the current rendering state. Rendering states are flags that specify which features are on and off and how they should be applied. Some examples are such questions as, "Is lighting enabled? Is texturing turned on? Is fog enabled, and what is its density?" Each state variable is either on or off or contains some numeric value. States can be set and read by the OpenGL functions.

See: glEnable, glDisable, glIsEnabled.

Overview of an OpenGL program

OpenGL order of operations

Syntax of OpenGL functions

OpenGL primitives

glBegin(GL_LINES)
    glVertex3f(__, __, __);
    glVertex3f(__, __, __);
    ...
glEnd();

OpenGL states

Viewing transformations

3D projection

Lighting