出现过剩和毛刺的突然问题包括和类型说明符 [英] Sudden issues with glut and glew includes and type specifiers

查看:78
本文介绍了出现过剩和毛刺的突然问题包括和类型说明符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为游戏开发课程开发一个最终的编程项目,并且选择在程序的3D渲染方面使用C ++和OpenGL(尽管我对此几乎没有经验).

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

直到现在,我一直在使用它,而且还没有出现严重错误,而且还可以工作几天.但是当我返回时,由于使用了一些GLfloat变量,我开始遇到各种"C4430-缺少类型说明符"错误.

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

为了解决此问题,我开始更改#includes(也许是一种愚蠢的方法,但此时我还是很困惑),并发现像某些人建议的那样添加Windows.h和gl/GL.h,解决了其中一个问题.

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>

新问题是,在gl/glew.h之前尝试使用gl/GL.h会引发错误"C1189:在glew.h之前包含gl.h",因为猜测是glew本身包含gl.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.

让我感到困惑的是,如果glew包括GL.h,那么这些类型说明符也不会包括在内吗?我将继续进行方法编码,这是我暂时不需要进行的测试,但是需要能够尽快测试我正在做的事情.谁能提供帮助或建议?

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?

推荐答案

#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(或您使用的任何OpenGL加载器)始终排在第一位.您绝不gl.h包含在OpenGL加载程序标头中;您只需包括他们的名字(在这种情况下为glew.h).它位于OpenGL或OpenGL工具的所有其他标头之前.

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的标题紧随其后.之后,除非您正在执行某些Windows特定的代码,否则您根本不应该包含window.h.如果是这样,请将其包含在FreeGLUT的内容之后.

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.

这篇关于出现过剩和毛刺的突然问题包括和类型说明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆