#error gl.h included before glew.h

So, I'm trying to move my OpenGL code from Main () to a specific class that will only process 3D graphics if 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 quite well. What I was trying to do was move all the code that corresponds to OpenGL into the methods of the Game class. So I removed #define GLEW_STATIC and #include <GL/glew.h> from the above and put them in Game.h, so 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 a header error, #error gl.h included before glew.h

Why is this happening, and how can I make full use of OpenGL code (almost) inside functions of a particular class without this?

EDIT:

I also tried this configuration in main.cpp, trying to make sure that nothing included SFML before GLEW.

 #include <cstdlib> #include <iostream> #include <fstream> #include "Game.h" #include <SFML/Graphics.hpp> 

Unfortunately, this does not help (there is nothing else that I do not mention here).

+8
c ++ include codeblocks opengl sfml
source share
2 answers

Some other library includes gl.h. My guess would be SFML. Make sure you turn on GLEW first in Game.h and check the places where you turned on Game.h to make sure you don't include SFML or anything else that gl.h includes before Game.h.

If you have something like:

 #include <something_that_includes_gl.h> #include "Game.h" 

It will effectively include gl.h before GLEW.

+14
source share

I think I also had this question. This is for some reason caused by the fact that SFML (1.6?) Includes OpenGL stuff.

IIRC (there was some time, and I no longer need GLEW from the moment of transition to SFML2), it is connected with SFML Graphics.hpp, including GLEW.h. It should not be due to the inclusion of guards, but I think that with some versions this can happen. You may be able to completely skip the GLEW header, as it is still included in SFML.

What version of SFML are you using? 1.6, 2.0 or 2.0 with the new API? Also, what is the reason for using GLEW? Something you lack in SFML? Perhaps this is something included in the latest version, so you do not need to include it.

+1
source share

All Articles