Question

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?

Was it helpful?

Solution 3

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.

OTHER TIPS

Do not mix SDL_OPENGL with other flags in the SDL_SetVideoMode() call. Well, you can use SDL_FULLSCREEN, but you don't need the SDL_HWSURFACE.

Particularly, the SDL_GL_DOUBLEBUFFER is not used that way. Intead do:

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);

What happens when you type glxgears in the terminal? If a window doesn't popup that shows gears spinning, something's wrong with your installation.

If you do see a window with gears spinning, you haven't initialized the OpenGL context properly as Nicol Bolas suggested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top