• gl.h included before glew.h


     

    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).

     

    [答案]

    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.

    If you have something like:

    #include
    					<something_that_includes_gl.h>
    					

    #include
    					"Game.h"
    				

    It will effectively include gl.h before GLEW.

     

    我的情况是在andriod ndk项目中遇到的这个错误,把

    #include <GL/glew.h>

    这句话放在pch.h的最前面,错误就没有了。

  • 相关阅读:
    设计模式之适配器模式温故知新(九)
    设计模式之策略模式总结(八)
    设计模式之观察者模式, 个人感觉相当的重要(七)
    设计模式之抽象工厂模式读后(六)
    设计模式之工厂模式详细读后感TT!(五)
    设计模式之简单工厂模式, 加速(四)
    设计模式之代理模式笔记(三)
    设计模式之单例模式读后思考(二)
    为什么要用设计模式?先看看6大原则(一)
    Codeforces_835
  • 原文地址:https://www.cnblogs.com/time-is-life/p/7140682.html
Copyright © 2020-2023  润新知