在 macOS Mojave 上静音 OpenGL 警告

Ale*_*der 14 opengl freeglut

我的代码充满了警告,比如

不推荐使用“glTranslatef”:首先在 macOS 10.14 中不推荐使用 - 不推荐使用 OpenGL API。(定义 GL_SILENCE_DEPRECATION 以消除这些警告)

我做了,#define GL_SILENCE_DEPRECATION但这并没有解决问题。我使用的freeglut是通过使用安装的brew install freeglut

我可以以某种方式让它静音吗?

Vin*_*rão 18

你应该放在#define GL_SILENCE_DEPRECATIONOpenGL 包含之前,这样你就可以做类似的事情:

#ifdef __APPLE__
/* Defined before OpenGL and GLUT includes to avoid deprecation messages */
#define GL_SILENCE_DEPRECATION
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glut.h>
#endif
Run Code Online (Sandbox Code Playgroud)

解决此问题的另一种方法是-Wno-deprecated-declarations在编译阶段将选项传递给编译器。