23

我使用 GLEW 和 freeglut。出于某种原因,在调用 glewInit() 后,glGetError() 返回错误代码 1280,即使 glewExperimental = GL_FALSE 也是如此。

我无法编译着色器,glGetProgramInfoLog() 返回“顶点着色器在调用 glLinkProgram() 之前没有成功编译。链接失败。” 我之前能够编译着色器。

重新安装驱动程序没有帮助。

这是我的代码:

int main(int argc, char* argv[])
{
    GLenum GlewInitResult, res;

    InitWindow(argc, argv);

    res = glGetError(); // res = 0

    glewExperimental = GL_TRUE;
    GlewInitResult = glewInit();    

    fprintf(stdout, "ERROR: %s\n", glewGetErrorString(GlewInitResult)); // "No error"
    res = glGetError(); // res = 1280

    glutMainLoop();

    exit(EXIT_SUCCESS);
}

void InitWindow(int argc, char* argv[])
{
    glutInit(&argc, argv);

    glutInitContextVersion(4, 0);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,
    GLUT_ACTION_GLUTMAINLOOP_RETURNS);

    glutInitWindowPosition(0, 0);
    glutInitWindowSize(CurrentWidth, CurrentHeight);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

    WindowHandle = glutCreateWindow(WINDOW_TITLE);

    GLenum errorCheckValue = glGetError();

    if (WindowHandle < 1)
    {
        fprintf(stderr, "ERROR: Could not create new rendering window.\n");
        exit(EXIT_FAILURE);
    }

    glutReshapeFunc(ResizeFunction);
    glutDisplayFunc(RenderFunction);
    glutIdleFunc(IdleFunction);
    glutTimerFunc(0, TimerFunction, 0);
    glutCloseFunc(Cleanup);
    glutKeyboardFunc(KeyboardFunction);
}

我做错了什么?

4

2 回答 2

22

Did you see the comment on this wiki page?

http://www.opengl.org/wiki/OpenGL_Loading_Library

It mentions why this occurs, and it says "in some cases you may still get GL_INVALID_ENUM after specifying glewExperimental depending on your glew version".

It sounds like it might be safe to ignore as long as you're not seeing any other problems.

于 2012-06-01T21:17:40.537 回答
-2

似乎 glew 不能正常工作......对我来说最简单的解决方案是使用 libepoxy。它不需要任何初始化的东西。只需更换您的

#include <GL/glew.h>

#include <epoxy/gl.h>
#include <epoxy/glx.h>

并删除所有 glew 代码。如果您使用 gcc,您还必须将“-lGLEW”替换为“-lepoxy”。而已。例如我有类似的东西:

g++ main.cpp -lepoxy -lSDL2 -lSDL2_image -lSDL2_mixer -lglut -lGLU -o main

在其他人之前保持环氧树脂标志似乎很重要。

于 2015-03-24T04:12:18.817 回答