OpenGL cube map example on Mac OS X

Alec Jacobson

March 26, 2010

weblog/

I had some trouble getting the demos from NVidia's cube map OpenGL tutorials to work on my MacBook Pro running Mac OS X 10.5 with NVIDIA GeForce 9400M graphics card. It seems that this demo code is totally outdated, not to mention you need to change some things to get OpenGL programs working on Mac OS X. (You can just download the modified cube map demo) The basic things you need to change in the cube map demo is:
  1. Get rid of all of the _EXTs from the GL constants. I guess, these are hanging around from the days when the cube map was not well supported. Now, and especially on Mac OS X, you should expect that it is.
  2. Likewise get rid of the run time check for GL_EXT_texture_cube_map: glutExtensionSupported("GL_EXT_texture_cube_map")
  3. Change the includes from #include <GL/gl.h> to #include <OpenGL/gl.h> and #include <GL/glut.h> to #include <GLUT/glut.h>
Lastly to compile use the following:
cc -o cubemap cubemap.c -framework GLUT -framework OpenGL -lXext -lX11 -lm
cc -o cm_demo cm_demo.c trackball.c tga.c -framework GLUT -framework OpenGL -lXext -lX11 -lm
You will probably get these warning when compiling the cm_demo program though it didn't seem to matter:
cm_demo.c: In function ‘loadFace’:
cm_demo.c:256: warning: incompatible implicit declaration of built-in function ‘exit’
cm_demo.c: In function ‘keyboard’:
cm_demo.c:356: warning: incompatible implicit declaration of built-in function ‘exit’
tga.c: In function ‘gliReadTGA’:
tga.c:385: warning: assignment from incompatible pointer type
tga.c:388: warning: assignment from incompatible pointer type
This got the whole thing working:

cube map demo screenshot

Note: I have made all the necessary changes to the demo: Download cube map demos with these changes already made