Gar*_*ckW 8 c++ opengl codeblocks include sfml
所以我试图将我的OpenGL代码从Main()移动到一个特定的类中,该类只在必要时处理3D图形.以前,我的main.cpp文件的顶部看起来像这样:
#define GLEW_STATIC
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Game.h"
Run Code Online (Sandbox Code Playgroud)
这很好用.我试图做的是将所有与OpenGL相关的代码移到Game类的方法中.所以我删除#define GLEW_STATIC,并#include <GL/glew.h>从上面的,并把它们放到Game.h,这样Game.h的顶部,现在看起来是这样的:
#define GLEW_STATIC
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Environment.h"
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,我得到标题错误,#error gl.h included before glew.h.
为什么会发生这种情况,如何在不发生这种情况的情况下(几乎)完全在特定类的函数内部使用OpenGL代码?
编辑:
我也在main.cpp中尝试过这个配置,试图确保在GLEW之前没有包含任何SFML.
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Game.h"
#include <SFML/Graphics.hpp>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这没有帮助(没有其他任何内容,我在这里没有提到).
R. *_*des 14
其他一些库包括gl.h. 我的猜测是SFML.确保在Game.h中首先包含GLEW并检查包含Game.h的位置,以确保在Game.h之前不包括SFML或包含gl.h的其他内容.
如果你有类似的东西:
#include <something_that_includes_gl.h>
#include "Game.h"
Run Code Online (Sandbox Code Playgroud)
它将在GLEW之前有效地包含gl.h.