[SDL] Are there any working SDL Android examples?

William Dyce wilbefast at gmail.com
Tue Jul 26 00:54:54 PDT 2011


You beauty :D

I combined the Dimitris and Ryan's examples (attached): I've never been so
happy to see a red rectangle :P The next step is getting an image to draw,
then I'll give input a shot. That is, after I do a bit of probing to figure
out why it's working now when it wasn't before. I think it may be that we're
now calling OpenGL functions like *glClearColor *and *SDL_GL_SwapWindow *rather
than the higher-level *SDL_FillRect*, and *SDL_Flip*.

Any reason why SDL_Flip might not be working? This all has me very
curious... I'll need to get SDL 1.3 set up so I can test things on Linux as
well - pity you can't just be a noob install it through Synaptic (which is
what I've generally done for 1.2).

William

On 26 July 2011 17:09, Ryan C. Gordon <icculus at icculus.org> wrote:

>
>  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?
>>
>
> SDL/test/testgles.c
>
> 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!)
>  SDL_Init(SDL_INIT_VIDEO);
>  SDL_GL_LoadLibrary(NULL);
>
>  // Make a window...
>  win = SDL_CreateWindow("My Application",
>            SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
>            640, 480,
>            SDL_WINDOW_FULLSCREEN | SDL_WINDOW_SHOWN |
>            SDL_WINDOW_OPENGL);
>
>  // 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.
>
>  SDL_GL_SetAttribute(SDL_GL_**CONTEXT_MAJOR_VERSION, 1);
>  SDL_GL_SetAttribute(SDL_GL_**CONTEXT_MAJOR_VERSION, 0);
>  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()...
>  SDL_GL_SwapWindow(win);
>
>  // At shutdown, you clean up...
>  SDL_GL_MakeCurrent(NULL, NULL);
>  SDL_GL_DeleteContext(ctx);
>  SDL_DestroyWindow(win);
>
>  // And finally, just like 1.2...
>  SDL_Quit();
>
>
> 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 limitations.
>
> --ryan.
>
>
> ______________________________**_________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/**listinfo.cgi/sdl-libsdl.org<http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110726/66ce91e9/attachment-0008.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 1534 bytes
Desc: not available
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110726/66ce91e9/attachment-0008.cpp>


More information about the SDL mailing list