Can't get GLEW to work.

Hi all, I’m new here.

I usually never post my problems, because my google-fu usually finds someone else who already had the same problem.
Not so now. And this has cost me night after night. Time to admit my defeat and Ask The Pros.

The problem: Glew does not initialise.
Yes, the OpenGL context was created.
No, there is no error when calling glewInit().

I’m at a loss here. No version of GL higher than 1.1 (standard windows) is reported, and all extension functions return null (segfault when called).

I tried both #define GLEW_STATIC 1 and #define GLEW_BUILD 1. I run glew version 1.5.2.

The Code!



#define GLEW_STATIC 1
#include <GL/glew.h>
#include <SDL.h>
#include <iostream>

int main(int argc, char **argv) {


    SDL_GL_LoadLibrary (0);  // Default OpenGL drivers
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
        sdldie("Unable to initialize SDL
");

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);

    SDL_WindowID mainwindow = SDL_CreateWindow("PanArch", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
        512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
    if (!mainwindow) /* Die if creation failed */
        sdldie("Unable to create window");

    SDL_GLContext maincontext = SDL_GL_CreateContext(mainwindow);
    if (!maincontext) /* Die if creation failed */
        sdldie("Unable to create context");

    SDL_GL_SetSwapInterval(1);

    glClearColor ( 1.0, 0.0, 0.0, 1.0 );
    glClear ( GL_COLOR_BUFFER_BIT );
    SDL_GL_SwapWindow(mainwindow);
    SDL_Delay(2000);

    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        std::cout<<"Engine: GLEW init failed
";
    }
    if (!GLEW_VERSION_2_0){
        std::cout<<"Version: "<<(glewGetString(GLEW_VERSION))<<"
";
        sdldie("Engine-GLEW: No 2.0?
");
    }
}

What happens here is I create a red-background openGL window (to make sure there is a context), then try to get glew’s functions.

The output:

Version: 1.5.2
Engine-GLEW: No 2.0?

So even 2.0 is not supported, tested that all the way down to 1.2. Glewinfo runs fine and tells me I should have up to GL version 3.1.

What did I do wrong? (in the code I mean, not “what did I do to deserve this” :p)

Thanks in advance for any pointers or help.

Edit:
In case it matters: I’m Using mingw on windows.

Okay, GLEE does the same. No extensions or errors whatsoever.

That is… odd. I’ve got a 5-month old videocard that draws more power than my fridge, and the almost-latest drivers for them. One would think I should at least be able to get OpenGL 1.2 on my machine…

Something is amiss. I’d like thing which are amiss to at least throw an error my way so I know where to look.

glewinfo runs fine ? Then check its source code, you may spot a difference explaining the different behaviour.

Thanks. I tried to:
A. copy some of the important-looking glewinfo stuff into my project: same result.
B. compile glewinfo from source (to see if it’s the compiler or something else), got linker errors I haven’t been able to solve yet.

Still to try:
C. try to use glew without SDL in a new project, to see if it works at all on my system/compiler/IDE.
D. try to use SDL 1.2 instead of 1.3, since SDL creates the OpenGL context that might be the problem.