OpenGL标题为OS X和Linux。

时间:2021-09-12 18:35:21

I'd like to have both the includes for OS X as well as linux in my opengl program (C++) how can I set my program to use one if the other is not available? Here's what i'm currently doing:

我希望在我的opengl程序(c++)中包含OS X和linux,如果其他的程序无法使用,我该如何设置我的程序呢?以下是我目前正在做的事情:

 if(!FileExists(OpenGL/gl.h))
    #include <GL/glut.h> //linux lib
else {
    #include <OpenGL/gl.h> //OS x libs
    #include <OpenGL/glu.h>
    #include <GLUT/glut.h>
}

4 个解决方案

#1


30  

Here is what I use:

以下是我所使用的:

#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#ifdef _WIN32
  #include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif

All compilers for the mac (well,I guess that's gcc, and maybe clang) should define __APPLE__. I throw the _WIN32 in there since windows.h must be included before gl.h on windows platforms, it seems.

所有mac的编译器(嗯,我想是gcc,可能是clang)应该定义__APPLE__。我把_WIN32从窗口扔进去。h必须包含在windows平台上的glh .h之前。

You can put this in its own include file (say gl_includes.h) if you have many files that need OpenGL

如果你有很多需要OpenGL的文件,你可以把它放到它自己的包含文件中(比如gl_includes.h)。

-matt

马特

#2


12  

Alternatively, put the platform specific headers into their own files:

或者,将平台特定的头文件放到它们自己的文件中:

linux\platform.h

linux \ platform.h

#include <GL/gl.h>
#include <GL/glu.h>

osx\platform.h

osx \ platform.h

#include <OpenGL/gl.h> //OS x libs
#include <OpenGL/glu.h>
#include <GLUT/glut.h>

win32\platform.h

win32 \ platform.h

#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>

and include in code:

在代码中,包括:

#include "platform.h"

and then let your build system specify the correct search path based on the target platform.

然后让构建系统根据目标平台指定正确的搜索路径。

#3


5  

#ifdef __APPLE__
#include <OpenGL/gl.h> //OS x libs
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#4


0  

What we use for OSX, Unix, Linux, Android, and iOS

我们使用的OSX, Unix, Linux, Android,和iOS !

#if defined(_WIN32) || defined(_WIN64)
#  include <gl/glew.h>
#  include <GL/gl.h>
#  include <GL/glu.h>
#elif __APPLE__
#  include "TargetConditionals.h"
#  if (TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR) || TARGET_OS_IPHONE
#    include <OpenGLES/ES2/gl.h>
#    include <OpenGLES/ES2/glext.h>
#  else
#    include <OpenGL/gl.h>
#    include <OpenGL/glu.h>
#    include <OpenGL/glext.h>
#  endif
#elif defined(__ANDROID__) || defined(ANDROID)
#  include <GLES2/gl2.h>
#  include <GLES2/gl2ext.h>
#elif defined(__linux__) || defined(__unix__) || defined(__posix__)
#  include <GL/gl.h>
#  include <GL/glu.h>
#  include <GL/glext.h>
#else
#  error platform not supported.
#endif

#1


30  

Here is what I use:

以下是我所使用的:

#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#ifdef _WIN32
  #include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif

All compilers for the mac (well,I guess that's gcc, and maybe clang) should define __APPLE__. I throw the _WIN32 in there since windows.h must be included before gl.h on windows platforms, it seems.

所有mac的编译器(嗯,我想是gcc,可能是clang)应该定义__APPLE__。我把_WIN32从窗口扔进去。h必须包含在windows平台上的glh .h之前。

You can put this in its own include file (say gl_includes.h) if you have many files that need OpenGL

如果你有很多需要OpenGL的文件,你可以把它放到它自己的包含文件中(比如gl_includes.h)。

-matt

马特

#2


12  

Alternatively, put the platform specific headers into their own files:

或者,将平台特定的头文件放到它们自己的文件中:

linux\platform.h

linux \ platform.h

#include <GL/gl.h>
#include <GL/glu.h>

osx\platform.h

osx \ platform.h

#include <OpenGL/gl.h> //OS x libs
#include <OpenGL/glu.h>
#include <GLUT/glut.h>

win32\platform.h

win32 \ platform.h

#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>

and include in code:

在代码中,包括:

#include "platform.h"

and then let your build system specify the correct search path based on the target platform.

然后让构建系统根据目标平台指定正确的搜索路径。

#3


5  

#ifdef __APPLE__
#include <OpenGL/gl.h> //OS x libs
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#4


0  

What we use for OSX, Unix, Linux, Android, and iOS

我们使用的OSX, Unix, Linux, Android,和iOS !

#if defined(_WIN32) || defined(_WIN64)
#  include <gl/glew.h>
#  include <GL/gl.h>
#  include <GL/glu.h>
#elif __APPLE__
#  include "TargetConditionals.h"
#  if (TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR) || TARGET_OS_IPHONE
#    include <OpenGLES/ES2/gl.h>
#    include <OpenGLES/ES2/glext.h>
#  else
#    include <OpenGL/gl.h>
#    include <OpenGL/glu.h>
#    include <OpenGL/glext.h>
#  endif
#elif defined(__ANDROID__) || defined(ANDROID)
#  include <GLES2/gl2.h>
#  include <GLES2/gl2ext.h>
#elif defined(__linux__) || defined(__unix__) || defined(__posix__)
#  include <GL/gl.h>
#  include <GL/glu.h>
#  include <GL/glext.h>
#else
#  error platform not supported.
#endif