Computer Graphics
Børre Stenseth

OpenGL

OpenGL [1] is:

  • is a library for programming of 2D and 3D graphics.
  • is established as an industry standard and reference standard.
  • is developed by Silicon Graphics.
  • has a long history under other names, GL.
  • was developed under control of an Architecture Review Board, which now is a part of The Khronos Group. [2]

OpenGL is continuously developed, with new versions. Latest version, may 2009, is 3.1. One major addition to the OpenGL concept is OpenGL Shading Language [3] . OpenGL is developed as platform independent package and runs on a lot of platforms: MS-Windows NT/2000/95/Vista, MS-.Net, Linux, Unix, MacOS.

OpenGL is a flat library. It is not object-oriented and it has no standardized export or import of graphical models. OpenGL is often referred to as a "state machine": We specify a lot of details as transformations, eye point, perspective, materials etc. When all this states are set, we start rendering.That is we send our point-sequences in a pipeline through the state machine where all our settings influence the result.

There are lots of material, examples and tutoriels, available on the net.

Language bindings

We can use OpenGL from a lot of languages, C, C++, C#, Fortran, Java, Python,.... How the library is reached from the language depends on the implementation of the language binding. In Java/JOGL we work against OpenGL as an object. That means that we typically do this:

  // get the OpenGL object associated with a drawing context
  GL gl = drawable.getGL();
  ...
  // use it
  gl.glEnable(GL.GL_LIGHTING);

In a typical C++ environment we do like this

  // we have linked to OpenGL and we use it
  glEnable(GL_LIGHTING);

It is important to notice that as a programmer it is easy to move sequences of source code from C/C++ to Java since most examples found in books or on the net is written in C/C++. Basically we add the "gl." and "GL.", and there are a few syntactical differences in how we define arrays, and JOGL has a few minor changes in how we use arrays. In Java:

 float ambient[] = {1.0f,1.0f,1.0f,1.0f };
 gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT,ambient,0);

In C++

 GLfloat ambient[] = {0.2f,0.2f,0.2f,1.0f };
 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);

More than gl

It is important to be aware of 3 additional libraries in the OpenGL - family.

glu

gl utilities is a set of methods that are based on gl, can be expressed in a series of gl-calls, and is supported to make some standard operations simpler for us as programmers. Typically:

GLU glu = new GLU();
...
glu.gluPerspective(45.0f, h, 1.0, 20.0);

glut

The OpenGL Utility Toolkit is basically a set of routines that manage platform independent simple windowing and mousing. We have access to glut when programming Java/JOGL. The Utah Teapot [4] is included in glut:

GLUT glut=new GLUT();
...
glut.glutSolidTeapot(1.0);

wgl

Windows specific routines for OpenGL. The purpose is to manage window specific concepts. One usage is 3D text based on Windows font descriptions.

References
  1. OpenGLwww.opengl.org/14-04-2009
  1. OpenGL, Architecture Review BoardControl of the development of OpenGLwww.opengl.org/about/arb/14-03-2009
  1. OpenGL Shading Languagewww.opengl.org/documentation/glsl/14-03-2009
  1. The Utah Teapotwww.sjbaker.org/wiki/index.php?title=The_History_of_The_Teapot14-03-2009
Maintainance
til toppen