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"
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"
When I try to compile, I get the title error, #error gl.h included before glew.h
.
Why is this happening, and how can I use OpenGL code (almost) entirely inside the functions of a specific class without this happening?
EDIT:
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).
See Question&Answers more detail:os