
I had my first look at SDL some years ago, when Wing Extrem from Wildbits told me about a library which could work either in Windows or Linux and was very nice for making games
. I remember that I managed to compile the .lib for visual studio but didn’t manage to go much further.
Since then, I have been finding lots of projects which use SDL as their base, which makes them really portable across platforms, and I decided to have a more in-depth look at it this time, since there’s no point in fighting the masses :-)
So I was toying with some tutorials, specially Sol’s Graphics for beginners tutorials and the Me and Mark Publishing SDL and OpenGL tutorial and wondered if it would be possible to get the same main.cpp compiled and working on our ubuntu computer…
I had absolutely no idea of how to get something compiled with SDL and OpenGL in linux; the last time I tried to compile a demo for linux it ended up being a frustrating experience which almost caused me a trauma, so I was slightly scared of trying it again. But I decided to go ahead since it was just a plain .cpp file!
Googled a bit and found an straightforward way of compiling:
gcc main.cpp -o main.o `sdl-config --cflags --libs` -lGL -lGLUIf that’s not ridiculously simple you tell me what it is. In Mac, for being able to get a [Cocoa] window, you need to prepare a tedious series of files and Objective C wrappers, just for being able to open a window and having decent event processing. Thanks god the nice people from SDL provide some XCode templates for getting started!
Immediate conclusion: apparently it’s easier to develop OpenGL stuff in Linux than in Mac, unless there’s some hidden automagic going on without my knowledge.
Of course there are a couple of minor details; because this is a computer which acts primarily as a file server, we have never bothered to make OpenGL work and all that, and as a consequence, it doesn’t have hardware acceleration. This forced me to comment out the multisampling part, or I would get a Couldn’t find matching GLX visual
error message each time I tried to execute the program. It’s also reporting that polygon stipple is being done by software rendering, but at least it does it.
This has left me wondering why there’s not more people making demos for linux. I still need to find out how it would work with more complicated code bases and things like cmake, but it looks as truly doable now that I managed to get my first program working. Hmmm…
Sources
Should you want to fully experience the 0xFF00FF background plus a randomly noise-texturized rotating triangle, simply compile this little file using this ultrasimple bash script and let yourself carried away :-)

Corsario
uhm!!! very nice colors!!! ;).
Nice to see your return to GL coding!
iq
triangle of the death with pixelillos ruidosos!!! Gimme a bit more time a que pille un Mac y la montamos sin sdl…
sole
no estoy segura de que quiera montar todo el tema sin sdl!
Tijuanero
Hey Soledad, do you speak spanish?? Oh well, that question is actually irrelevant… Anyways, how can I program with OpenGL under linux, I’m able to compile a ‘hello world’ however if I add the #import it doesn’t work, I get an error saying it doesn’t exist, is there a library I have to install?? I’m usig Ubuntu 7.04
Thanks in advance…
sole
Hello!
You obviously need to make sure the libraries are included (not ‘imported’). Without the error message you get is pretty hard to help you but anyway, the easiest way of knowing which packages you need is to copy and paste the error into google’s search box and it will probably show you the solution.
Or paste the error here and we can try to find out what’s wrong with your config :)
Tijuanero
Thanks! I figured it out… can’t remember what it is but I know I’ve fixed it
So, Sole, I can play with GLUT and that stuff, but do you know if I can use GTK to have like a window with menus and stuff like that?? you know like if I want to program a CAD software and have mnus (like in Windows)…. I’ve been playing a little bit with GTK and I got this MonoDevelop software but it’s good for C#, but I want to use C/C++…
Any suggestions???
Tijuanero
If you have any suggestions, let me know…
sole
I haven’t programmed anything gtk-wise, the most I did was tinker a bit with pygtk. But obviously it should be possible to have something like an “OpenGL View” or something (OpenGL widget, etc) that lets you have an OpenGL context and accepts your gl* instructions there.
As to how to do that… well… I don’t know that yet :)
Maybe you could search for “gtk custom components opengl” or something in you-know-which-search-engine… can’t think of anything useful now, sorry! If I find it I’ll write it down here :D
JK
Something missing :(
$ gcc sdl_opengl_main.cpp -o sdl_opengl_main.o `sdl-config –cflags –libs` -lGL -lGLU
Usage: sdl-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]
/tmp/ccaMbvU3.o: In function `render()’:
sdl_opengl_main.cpp:(.text+0×68): undefined reference to `SDL_LockSurface’
sdl_opengl_main.cpp:(.text+0×78): undefined reference to `SDL_GetTicks’
sdl_opengl_main.cpp:(.text+0x1b6): undefined reference to `SDL_UnlockSurface’
sdl_opengl_main.cpp:(.text+0x1e3): undefined reference to `SDL_UpdateRect’
/tmp/ccaMbvU3.o: In function `main’:
sdl_opengl_main.cpp:(.text+0x21a): undefined reference to `SDL_Init’
sdl_opengl_main.cpp:(.text+0×226): undefined reference to `SDL_GetError’
sdl_opengl_main.cpp:(.text+0×253): undefined reference to `SDL_Quit’
sdl_opengl_main.cpp:(.text+0x26c): undefined reference to `SDL_GL_SetAttribute’
sdl_opengl_main.cpp:(.text+0×280): undefined reference to `SDL_GL_SetAttribute’
sdl_opengl_main.cpp:(.text+0×294): undefined reference to `SDL_GL_SetAttribute’
sdl_opengl_main.cpp:(.text+0x2a8): undefined reference to `SDL_GL_SetAttribute’
sdl_opengl_main.cpp:(.text+0x2bc): undefined reference to `SDL_GL_SetAttribute’
sdl_opengl_main.cpp:(.text+0x2eb): undefined reference to `SDL_SetVideoMode’
sdl_opengl_main.cpp:(.text+0x2fe): undefined reference to `SDL_GetError’
sdl_opengl_main.cpp:(.text+0x32e): undefined reference to `SDL_GL_SwapBuffers’
sdl_opengl_main.cpp:(.text+0×371): undefined reference to `SDL_PollEvent’
collect2: ld returned 1 exit status
sole
Try having a look at the error message :) It is actually pointing out what’s wrong: the dashes.
Make sure you enter this:
sdl-config - -cflags - -clibsIn your code it has a dash instead of two hyphens, it’s a problem with the blog formatting two hyphens like a dash. Just remove the extra space between dashes: – -