core/vgui/vgui_glut.h
Go to the documentation of this file.
00001 #ifndef vgui_glut_h
00002 #define vgui_glut_h
00003 
00004 #include <vgui/vgui_config.h>
00005 #ifdef HAS_GLUT
00006 
00007 // See vgui_glu.h
00008 // There used to be logic here to deal issues related to GLUT's use of
00009 // exit, but it appears to be unnecessary now. If the problem arises
00010 // again, have a look at the older versions of this source, and in
00011 // the comments at the top of glut.h
00012 //  - Amitha Perera
00013 
00014 # include <vcl_compiler.h>
00015 # include <vgui/vgui_gl.h>
00016 # include <vgui/vgui_glu.h>
00017 #ifdef __APPLE__
00018 # include <glut.h>
00019 #else
00020 # include <GL/glut.h>
00021 #endif
00022 
00023 // Workaround for a "bug" in GL/glut.h on Leuven's alpha, where the
00024 // prototypes of some functions is declared as char* instead of const
00025 // char*. Note that we cannot (should not) overload these functions
00026 // since they are C functions. Instead we define the local functions
00027 // with the correct prototypes (lifted from the GLUT 3.7 sources), and
00028 // call the system ones to do the actual work. We then use the
00029 // pre-processor to use our functions instead of the incorrect system
00030 // declarations.
00031 //
00032 // We expect and hope that the broken implementations don't attempt to
00033 // modify the constant strings.
00034 //
00035 // The "fixing functions" have C++ linkage, but that's okay, since
00036 // vgui is a C++ library anyway.
00037 
00038 // The #ifdef test below is based on one
00039 // sample. GLUT_XLIB_IMPLEMENTATION==5 is circa 1995. Most modern GLUT
00040 // libraries are probably 11 or greater.
00041 #if GLUT_XLIB_IMPLEMENTATION <= 5 // fix glut function declarations
00042 
00043 inline int vgui_glutCreateWindow( const char* title )
00044 {
00045   return glutCreateWindow( const_cast<char*>(title) );
00046 }
00047 #undef glutCreateWindow
00048 #define glutCreateWindow   vgui_glutCreateWindow
00049 
00050 inline void vgui_glutSetWindowTitle( const char* title )
00051 {
00052   glutSetWindowTitle( const_cast<char*>(title) );
00053 }
00054 #undef glutSetWindowTitle
00055 #define glutSetWindowTitle vgui_glutSetWindowTitle
00056 
00057 inline void vgui_glutSetIconTitle( const char* title )
00058 {
00059   glutSetIconTitle( const_cast<char*>(title) );
00060 }
00061 #undef glutSetIconTitle
00062 #define glutSetIconTitle   vgui_glutSetIconTitle
00063 
00064 inline void vgui_glutAddMenuEntry( const char* label, int value )
00065 {
00066   glutAddMenuEntry( const_cast<char*>(label), value );
00067 }
00068 #undef glutAddMenuEntry
00069 #define glutAddMenuEntry   vgui_glutAddMenuEntry
00070 
00071 inline void vgui_glutAddSubMenu( const char* label, int sub )
00072 {
00073   glutAddSubMenu( const_cast<char*>(label), sub );
00074 }
00075 #undef glutAddSubMenu
00076 #define glutAddSubMenu     vgui_glutAddSubMenu
00077 
00078 inline void vgui_glutChangeToMenuEntry( int item, const char* label, int value )
00079 {
00080   glutChangeToMenuEntry( item, const_cast<char*>(label), value );
00081 }
00082 #undef glutChangeToMenuEntry
00083 #define glutChangeToMenuEntry vgui_glutChangeToMenuEntry
00084 
00085 inline void vgui_glutChangeToSubMenu( int item, const char* label, int sub )
00086 {
00087   glutChangeToSubMenu( item, const_cast<char*>(label), sub );
00088 }
00089 #define glutChangeToSubMenu vgui_glutChangeToSubMenu
00090 
00091 #if (GLUT_API_VERSION >= 2)
00092 inline int vgui_glutExtensionSupported( const char* name )
00093 {
00094   return glutExtensionSupported( const_cast<char*>(name) );
00095 }
00096 #undef glutExtensionSupported
00097 #define glutExtensionSupported vgui_glutExtensionSupported
00098 #endif
00099 
00100 #endif // fix glut function declarations
00101 
00102 #else // HAS_GLUT
00103 # error "Trying to use vgui_glut when HAS_GLUT is not defined."
00104 // If you get here, then you are trying to use vgui_glut in your
00105 // source without determining if your system has glut. If you are
00106 // using CMake to build, then look at the FindGLUT module. Something like
00107 //
00108 //   INCLUDE(${CMAKE_ROOT}/Modules/FindGLUT.cmake)
00109 //   IF( GLUT_FOUND )
00110 //     INCLUDE_DIRECTORIES(${GLUT_INCLUDE_DIR})
00111 //     ADD_DEFINITIONS( -DHAS_GLUT)
00112 //   ENDIF( GLUT_FOUND )
00113 
00114 #endif // HAS_GLUT
00115 
00116 #endif // vgui_glut_h