GL_PRIMITIVE_RESTART on OSX 10.8

2019-01-29 13:16发布

问题:

i'm using OpenGL 3.2 and GLUT on OSX, and compiling on the command line like such:

gcc test.c -framework OpenGL -framework GLUT

at the top of my source file, i manually include two headers:

#include <OpenGL/OpenGL.h>
#include <GLUT/GLUT.h>

so far, everything has been fine and dandy. but today i noticed that using GL_PRIMITIVE_RESTART gives me an undeclared identifier error...

are there other headers i need to include or other frameworks? or does apple just not support GL_PRIMITIVE_RESTART in their implementation of OpenGL 3.2?

回答1:

You're not directly including any of the OpenGL headers. <OpenGL/OpenGL.h> might sound like it's the OpenGL header, but it actually contains definitions for CGL.

You indirectly get an OpenGL header because <GLUT/GLUT.h> includes <OpenGL/gl.h>. Unfortunately that's the pre-GL3 header file, which is why you don't have the GL3 level definitions.

The header you want is <OpenGL/gl3.h>. You can include it yourself, but will most likely see some warnings because <GLUT/glut.h> will still also include the old header, and it will point out possible conflicts. The best I found is to use an include sequence like this:

#include <OpenGL/gl3.h>
#define __gl_h_
#include <GLUT/glut.h>

The #define corresponds to the header guard in <OpenGL/gl.h>, and prevents it from being included.

Apple is deprecating GLUT. You have to disable additional warnings in OS X 10.9 to prevent it from complaining about using GLUT. It also doesn't have support for creating newer contexts than GL 3.2.