OpenGL

About this page.

The purpose of this page, and the other pages in this tree is to provide a foundation for learning and using OpenGL. Much of information on the web assumes knowledge which a student may not have. I do not endorse any hardware vendor.

What is OpenGL ?

OpenGL is the defacto standard for acclerated cross-platform interactive graphics. That is, if you need to write a program that takes advantage of modern GPU hardware, and that program needs to run on Windows, Mac OS X, and Linux then OpenGL is a good choice for you. Most high end cell phones also have a GPU inside them which is exposed to the programmer with OpenGL. The OpenGL standard itself is part of a family of multimedia standards administered by an industry consortium called The Khronos Group .

How do I write an OpenGL program?

Because OpenGL is meant to run on any operating system, OpenGL (or GL) has no notion of a window. Therefore, each operating system must have an API which can setup a window so that OpenGL drawing calls will work in that window. On UNIX/Linux that API is called GLX. On Windows that API is called WGL, and on Mac OS X, that API is called AGL. There are OpenGL bindings for Java also.

Of course, after opening a window, we'd like to get keyboard and mouse events also. These calls are operating system specific also. Further, if we're writing software that's supposed to function across multiple operating systems, we'd like all those platform specific calls to be abstracted away to generic event callbacks anyway. Fortunately, toolkits that do just this job are available. Here are a few examples:

I do not evaluate these libraries in terms of their suitability for any particular application domain here. That is up to you. Rather, I mention them because I have used them all and they all provide a reasonable way of abstracting the operating systems services required, namely: opening an OpenGL window and getting events of various kinds (e.g. keyboard and mouse events). They are also all open source, so they can be used at no cost. Notably, GLUT is not free, but a free alternative exists here: Freeglut

Hardware vendors write drivers which allow programmers to use their GPU by making OpenGL calls. So, in addition to having operating system support for OpenGL, (or, as with the libraries above, an abstraction of those services) your GPU driver must support it. Fortunately, all major hardware vendors do.

There are OpenGL bindings for many languages, but I will focus on C/C++ since those are the most widely used. Once you are familiar with OpenGL, transferring that knowledge to Java or Python should be straight forward.

Resources:

Many Examples

A math professor of mine used to repeat the phrase "many examples" quite often. He used many examples. I learned quite a lot from him, so I will adopt that approach here.

All the examples I show use the GLUT toolkit. It is well suited for teaching and it is the lingua franca of the OpenGL world. That is, when reading books or talking with other developers, knowledge of GLUT is assumed. GLUT is quite easy to use. Makefiles for Linux are provided.