[SDL] Are there any working SDL Android examples?

Ryan C. Gordon icculus at icculus.org
Tue Jul 26 00:09:54 PDT 2011

> Dimitris: so avoid legacy functions like SDL_SetVideoMode?

In theory, if all you want is the 1.2 API, SDL_SetVideoMode() _should_ 
do the right thing...it just wraps the 1.3 API with some limitations 
(like the inability to have multiple windows, etc).

That being said, the 1.2 emulation is not perfect in places, so you're 
probably safer using the 1.3 API directly if you can.

> I've actually been unable to find any example code that uses
> SDL_CreateWindow, even in the SDL1.3 examples directory. Could you give
> me an example, and is there anything I should try to strip out?


Sadly, all the important parts are all abstracted out to common.c (where 
it handles multiple windows and all sorts of options you don't care 
about, etc), but you should be able to find what you need easily enough.

Using the SDL 1.3 API isn't much more complicated that 1.2:

   // this is untested, so forgive minor typos, please...

   // just like 1.2 (but DO check return values!)

   // Make a window...
   win = SDL_CreateWindow("My Application",
             640, 480,

   // Create a GL context for that window...
   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
   // etc...

   // Make the major version 2 if you want GLES2 on Android.
   ctx = SDL_GL_CreateContext(win);
   SDL_GL_MakeCurrent(win, ctx);

   // You might want this to turn on/off vsync...
   SDL_GL_SwapInterval(1);  // 1 == vsync, 0 == no vsync.

   // Now you can draw with OpenGL calls.

   // Use this instead of SDL 1.2's SDL_GL_SwapBuffers()...

   // At shutdown, you clean up...
   SDL_GL_MakeCurrent(NULL, NULL);

   // And finally, just like 1.2...

Some of this was just being pedantic (you don't actually have to do the 
SDL_GL_MakeCurrent() calls), but that's about all you need to know about 
SDL's video subsystem to move a 1.2 OpenGL app to 1.3.

That being said, I can't account for bugs in our Android port. If you 
find one, please report it.

I was really worried for a long time about moving from the 1.2 API, 
which I'm extremely comfortable with, to 1.3, but the API is 
surprisingly comfortable too...it feels easy like 1.2, but without 1.2's 


More information about the SDL mailing list