23

I use GLEW and freeglut. For some reason, after a call to glewInit(), glGetError() returns error code 1280, even with glewExperimental = GL_FALSE.

I cannot compile the shaders, glGetProgramInfoLog() returns "Vertex shader(s) were not successfully compiled before glLinkProgram() was called. Link failed." I was able to compile the shaders before.

Reinstalling the drivers didn't help.

Here's my code:

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);
}

What I am doing wrong?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Martin
  • 1,877
  • 5
  • 21
  • 37
  • Are you doing anything with GlewInitResult? Maybe you should be calling glewGetErrorString instead of glGetError (for detecting glew problems) – Tim Jun 01 '12 at 21:10
  • I don't do anything with GlewInitResult. glewGetErrorString returns "No error". – Martin Jun 01 '12 at 21:13

2 Answers2

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.

Tim
  • 35,413
  • 11
  • 95
  • 121
  • I tried to comment out the line, I still get invalid enum. I cannot compile shaders, glGetProgramInfoLog() returns "Vertex shader(s) were not successfully compiled before glLinkProgram() was called. Link failed." – Martin Jun 01 '12 at 21:24
  • 5
    You should verify the shaders before you try to link the program: glGetShaderiv(GL_COMPILE_STATUS) and glGetShaderInfoLog(). That will tell you why they fail to compile. @malymato – Tim Jun 01 '12 at 21:26
-2

It seems glew just does not work correctly... The easiest solution for me was using libepoxy. It does not require any init thing. Just replace your

#include <GL/glew.h>

with

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

and remove all the glew code. If you use gcc, you will also have to replace "-lGLEW" with "-lepoxy". That's it. For example I have something like:

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

It seems to be important to keep epoxy flag before others.

Nick
  • 21
  • 1