适用于OS X& Linux [英] OpenGL headers for OS X & Linux

查看:115
本文介绍了适用于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平台上,似乎。



-matt


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

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:

 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>
}

解决方案

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.

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

-matt

这篇关于适用于OS X&amp; Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆