Sudden issues with glut and glew includes and type specifiers

China☆狼群 提交于 2020-01-14 04:18:40

问题


I’m currently working on a final programming project for a games development course, and chose to make use of C++ and OpenGL for the 3D rendering side of the program (despite the fact I have little experience with it).

I was working with it until now absolutely fine with no serious errors, and then left it for a few days. But when I returned I started to get various "C4430 - Missing Type Specifier" errors with the few GLfloat variables I had used.

This was my previous definitions, which worked fine until I reloaded today:

    #include <gl/glew.h>
    #include <gl/glut.h>

    ... Other variable and object definitions

    const GLfloat DEFAULT_X = -5.0f;  //C4430: missing type specifyer on all 3 lines and
    const Glfloat DEFAULT_Y = -4.0f;  //C2146: syntax error : missing ';' before identifier 'DEFAULT_Y' on this line only
    const GLfloat DEFAULT_Z = -20.0f;

    GLfloat viewX = DEFAULT_X; //This line is fine
    GLfloat viewY = DEFALUT_Y; //Resulting C2065: Undeclared identifyer
    GLfloat viewZ = DEFALUT_Z; //on both these lines

In an attempt to fix this I began altering the #includes (perhaps, a daft approach, but I was pretty confused at this point) and found that adding Windows.h and gl/GL.h, as some have suggested, fixed all but one of the problems.

    #include <Windows.h>
    #include <gl/GL.h>
    #include <gl/glew.h>
    #include <gl/glut.h>

The new problem is that attempting to use gl/GL.h before gl/glew.h throws the error "C1189: gl.h included before glew.h" because, at a guess, glew includes gl.h itself. But any alteration brings back the previous type specifyer errors.

What's confusing me is that if glew was including GL.h, then wouldn’t these type specifiers have also been included? I’m going to continue method coding what I can without testing for the time being, but need to be able to test what I’m doing soon. Can anyone offer help or suggestions?


回答1:


#include <Windows.h>
#include <gl/GL.h>
#include <gl/glut.h>
#include <gl/glew.h>

This is the wrong order to include these headers in.

GLEW (or whatever OpenGL loader you're using) always comes first. You never include gl.h with an OpenGL loader headers; you just include theirs (glew.h in this case). And it comes before all other headers for OpenGL or OpenGL tools.

FreeGLUT's headers come next. After that... you shouldn't be including window.h at all, unless you're doing some Windows-specific code. If you are, you include it after FreeGLUT's stuff.



来源:https://stackoverflow.com/questions/15166307/sudden-issues-with-glut-and-glew-includes-and-type-specifiers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!