Search code examples
linuxopenglsdlnvidiamesa

OpenGL Linux not reading GL_VERSION


I have a simple OpenGL program using SDL on Linux that just attempts to load and print the OpenGL version.

cout << "GL_VERSION  : " << glGetString(GL_VERSION) << endl;

When I run the program it just hangs, with the output as below... it basically appears to be "waiting" for the OpenGL library to respond:

GL_VERSION  : 

It is linked against the Nvidia Ubuntu OpenGL libraries (nvidia-current-dev pkg). I do have Mesa installed on system also, but as you can see from 'lsof' it appears Nvidia is being used.

sdl-hack 29491 x  mem    REG               8,18 34639056 4212198 /usr/lib/nvidia-current/libnvidia-glcore.so.295.40
sdl-hack 29491 x  mem    REG               8,18    11728 4212207 /usr/lib/nvidia-current/tls/libnvidia-tls.so.295.40
sdl-hack 29491 x  mem    REG               8,18  1054832 4212209 /usr/lib/nvidia-current/libGL.so.295.40

Please note that I did have to install 'libglu1-mesa-dev' to provide glu.h as this is not part of the Nvidia dev pkg.

Not really sure how to debug this one, can someone point me in the right direction?


Solution

  • I solved this. I had followed the code at the link below to get an initial working version:

    http://www.sdltutorials.com/sdl-opengl-tutorial-basics

    The article notes a number of set attribute calls:

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,        8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,      8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,       8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,      8);
    
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,      16);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,        32);
    
    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,    8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,    8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,    8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,    8);
    
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,  1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,  2);
    

    These were after the SDL_Init but before SDL_SetVideoMode calls. Removing them made the program work fine!

    The strange thing is, the issue only occurred on Linux with both Mesa and Nvidia GL libraries. Mac OSX was fine.