#error gl.h 包含在 glew.h 之前

#error gl.h included before glew.h(#error gl.h 包含在 glew.h 之前)
本文介绍了#error gl.h 包含在 glew.h 之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

所以我试图将我的 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.

这篇关于#error gl.h 包含在 glew.h 之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

OpenGL transforming objects with multiple rotations of Different axis(OpenGL 变换不同轴多次旋转的对象)
GLFW first responder error(GLFW 第一响应者错误)
SOIL not linking correctly(SOIL 连接不正确)
Core profile vs version string? Only getting GLSL 1.3/OGL 3.0 in mesa 10.0.1(核心配置文件与版本字符串?在 mesa 10.0.1 中只获得 GLSL 1.3/OGL 3.0)
What is the range of OpenGL texture ID?(OpenGL 纹理 ID 的范围是多少?)
How taxing are OpenGL glDrawElements() calls compared to basic logic code?(与基本逻辑代码相比,OpenGL glDrawElements() 调用的繁重程度如何?)