Using Glew in multiple files
Somehow I can't get Glew in multiple header files. It i开发者_运维知识库s just complaining about Gl is already defined before GLEW.
I have the following file structure in short:
- Program.h
includes:
<GL/glew.h>
,<GL/freeglut.h>
and"SceneManager.h"
. - SceneManager.h
includes:
"GameObject.h"
- GameObject.h
includes:
<GL/glew.h>
,<GL/freeglut.h>
.
I do understand that freeglut is in front of glew, but I would like to have the GL_BGR
extension for example.
How do I get the
glew.h
in the GameObject as well?
Must be a bug in glew.h
.
I use GLee instead, which doesn't have this problem. GLee's test looks like this:
#ifndef __glee_h_
#define __glee_h_
#ifdef __gl_h_
#error gl.h included before glee.h
#endif
#ifdef __glext_h_
#error glext.h included before glee.h
#endif
#ifdef __wglext_h_
#error wglext.h included before glee.h
#endif
#ifdef __glxext_h_
#error glxext.h included before glee.h
#endif
//...
#endif /* !defined(__glee_h_) */
So the tests are only done the first time glee.h
is included.
Apparently glew improperly does the tests outside the header multiple inclusion guard.
I switched from glew to GLee the first time I ran an OpenGL trace (glslDevil, actually) and saw glew calling glGetString(GL_EXTENSIONS)
hundreds of times at startup.
I did it a bit different myself right now:
I created a precompiled header with glew and freeglut in it. It looks like this:
#ifndef _STDAFX_H_
#define _STDAFX_H_
#include <GL/glew.h>
#include <GL/freeglut.h>
#endif
Could someone confirm if this is a solid and well know method to do so?
精彩评论