[英]OpenGL headers for OS X & Linux
我想在我的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>
}
這是我使用的:
#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
mac的所有編譯器(好吧,我猜那是gcc,也許是clang)應該定義__APPLE__
。 我拋出_WIN32
,因為windows.h平台上的gl.h必須包含在windows.h中。
如果您有許多需要OpenGL的文件,可以將它放在自己的包含文件(例如gl_includes.h)中
-matt
或者,將特定於平台的標頭放入自己的文件中:
Linux的\\ platform.h
#include <GL/gl.h>
#include <GL/glu.h>
OSX \\ platform.h
#include <OpenGL/gl.h> //OS x libs
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
的win32 \\ platform.h
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
並包含在代碼中:
#include "platform.h"
然后讓您的構建系統根據目標平台指定正確的搜索路徑。
#ifdef __APPLE__
#include <OpenGL/gl.h> //OS x libs
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
我們用於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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.