#error gl.h 包含在 glew.h 之前
所以我试图将我的 OpenGL 代码从 Main() 移动到一个特定的类中,该类仅在必要时处理 3D 图形.以前,我的 main.cpp 文件的顶部是这样的:
So I'm trying to move my OpenGL code from Main() into a specific class that will handle the 3D graphics only when necessary. Previously, the top of my main.cpp file looked like this:
#define GLEW_STATIC
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Game.h"
这很有效.我试图做的是将所有与 OpenGL 相关的代码移动到 Game
类的方法中.所以我把上面的 #define GLEW_STATIC
和 #include <GL/glew.h>
去掉,放到 Game.h 中,这样 Game.h 就可以了.h 现在看起来像这样:
This worked well enough. What I tried to do was move all the OpenGL-relevant code into methods of the Game
class. So I removed #define GLEW_STATIC
and #include <GL/glew.h>
from the above, and put them into Game.h, such that the top of Game.h now looks like this:
#define GLEW_STATIC
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Environment.h"
当我尝试编译时,出现标题错误,#error gl.h 包含在 glew.h 之前
.
When I try to compile, I get the title error, #error gl.h included before glew.h
.
为什么会发生这种情况,我怎样才能(几乎)完全在特定类的函数内使用 OpenGL 代码而不会发生这种情况?
Why is this happening, and how can I use OpenGL code (almost) entirely inside the functions of a specific class without this happening?
我也在 main.cpp 中尝试过这种配置,以确保在 GLEW 之前没有任何内容包含 SFML.
I have also tried this configuration in main.cpp, in an attempt to make sure that nothing includes SFML before GLEW.
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Game.h"
#include <SFML/Graphics.hpp>
不幸的是,这无济于事(我没有在此处提及其他任何内容).
Unfortunately, that doesn't help (there's nothing else being included that I'm not mentioning here).
推荐答案
其他一些库包含 gl.h.我的猜测是SFML.确保首先在 Game.h 中包含 GLEW 并检查包含 Game.h 的位置,以确保在 Game.h 之前不包含 SFML 或其他包含 gl.h 的内容.
Some other library is including gl.h. My guess would be SFML. Make sure you include GLEW first in Game.h and check the places where you include Game.h to make sure you're not including SFML or something else that includes gl.h before Game.h.
如果你有类似的东西:
#include <something_that_includes_gl.h>
#include "Game.h"
它会在 GLEW 之前有效地包含 gl.h.
It will effectively include gl.h before GLEW.
相关文章