When writing samples and prototype code and even production applications, keep in mind that different UNIX implementations and Windows 95/NT have different APIs, provide different system services, and can even provide substantially different development environments (such as contents of include files, location of libraries, etc.). Here are a few things to look out for when writing a program under UNIX with the intent to port to Windows or other UNIX operating systems:
#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN /* somewhat limit Win32 pollution */ #include <windows.h> #endif #include <GL/gl.h> #include <GL/glu.h>
Unfortunately, including <windows.h> has the unfortunate side effect of introducing literally thousands of macros and type declarations into your compilation environment. This undesirable ``name space pollution'' can sometimes affect source code portability by conflicting with your program's own macros and types. This can particularly be a problem for UNIX programmers that are not familiar with all the junk that comes with including <windows.h>.
One alternative is to include the <GL/glut.h> header. The GLUT header automatically includes <GL/gl.h> and <GL/glu.h> and guarantees to include these headers in a way that avoids introducing the name space pollution of including <windows.h>. If you use GLUT, your programs will automatically be more portable by simply including <GL/glut.h> and not including <GL/gl.h> or <GL/glu.h> directly (simply letting <GL/glut.h> include them).
#ifndef M_PI #define M_PI 3.14159265358979323846 #endif
#ifndef CALLBACK #define CALLBACK #endif
Then using a GLU tessellator begin callback as an example say:
static void CALLBACK begin(GLenum type, void *polyData) { glBegin(type); }
When registering the callback, say:
gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (void (CALLBACK*)()) &begin);
This advice also applies to the other GLU routines that require callback functions to be supplied. These other routines are gluQuadricCallback() and gluNurbsCallback().
A more in-depth list of portability considerations is available in the file Portability.txt in the GLUT source code distribution. GLUT is described in more detail in Appendix B.