bernie2436
bernie2436

Reputation: 23921

How do I use Open GL in a C++ project that I am porting from Linux

I just tried to compile an open source C++ application on my Mac. I get the error GL/gl.h file not found. I know that this means that it can't find the open GL library, which it needs to compile and run. I am confused about what to do next because

  1. It seems like OS X includes built-in support for open gl. There is nothing to download.
  2. It seems like the header file names might be different for OpenGL on OSX and Linux ( OpenGL headers for OS X & Linux )

So I am confused about what to do next. Do I download OpenGL and link it to my project? Do I configure xcode to use a native version of OpenGL? Do I change the headers?

Can someone provide a little more direction. This answer gave windows/linux answers -- but not OS X: How to get the GL library/headers?

Upvotes: 4

Views: 4203

Answers (2)

datenwolf
datenwolf

Reputation: 162327

Apple thought it was clever if they were incompatible to everybody else and placed the OpenGL headers in a directory called OpenGL not just GL. So you must use

#include <OpenGL/gl.h>

on Apple systems and

#include <GL/gl.h>

everywhere else. Compiler predefined preprocessor macros are your friend here.

#ifdef __APPLE__
#  include <OpenGL/gl.h>
#else
#  include <GL/gl.h>
#endif/*__APPLE__*/

Upvotes: 10

Wagner Patriota
Wagner Patriota

Reputation: 5674

"OS X includes built-in support for OpenGL" is right!

Windows also does! BUT the thing is that Windows only gives you access to OpenGL 1.1 functions... Everything above this must be done via extensions! OpenGL extensions can be found here: http://www.opengl.org/registry/

But because it's very boring to set up those extensions, you could use things like GLEW or similar...

Another very common issue is how to open the OpenGL context on Windows properly! If you follow old tutorials like NeHe you will have some problems nowadays. The solution is to use something like GLFW, glut, freeglut or similar...

With this pair "context + extensions" you will be able to easily create the context and use any function from the "modern OpenGL" functions that you are probably using on OS X. I particularly prefer "GLFW + GLEW"!

Upvotes: 1

Related Questions