Are there any working SDL Android examples?

#include “SDL.h”

int main(int argc, char* argv[])
{
SDL_Window* window;
SDL_Renderer* renderer;

    // Initialize SDL.
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
            return 1;

    // Create the window where we will draw.
    window = SDL_CreateWindow("SDL_RenderClear",
                    SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                    512, 512,
                    SDL_WINDOW_SHOWN);

    // We must call SDL_CreateRenderer in order for draw calls to

affect this window.
renderer = SDL_CreateRenderer(window, -1, 0);

    // Select the color for drawing. It is set to red here.
    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);

    whiile(!quit) {
    // Clear the entire screen to our selected color.
    SDL_RenderClear(renderer);

    // Up until now everything was drawn behind the scenes.
    // This will show the new, red contents of the window.
    SDL_RenderPresent(renderer);

     // Give us time to see the window.
    SDL_Delay(50);
    }





    // Always be sure to clean up
    SDL_Quit();
    return 0;

}On Tue, Jul 26, 2011 at 11:53 AM, William Dyce wrote:

Dimitris: never actually used the renderer before. The documentation is
pretty good though. I’m guessing SDL_RENDERER_ACCELERATED isn’t going to
work, any suggestions for what kind?

Just trying to get Code::Blocks to compile my project using SDL 1.3 rather
than 1.2 so I can do some tests on Linux as well as Android. This is looking
good so far though guys - thanks very much for all of you help :slight_smile:

William

On 26 July 2011 18:28, Dimitris Zenios <@Dimitris_Zenios> wrote:

William you can create a renderer for the window and do render present
on the renderer.hat way you will not need the opengl code.You will use
the SDL rendering api

On Tue, Jul 26, 2011 at 10:54 AM, William Dyce wrote:

You beauty :smiley:

I combined the Dimitris and Ryan’s examples (attached): I’ve never been
so
happy to see a red rectangle :stuck_out_tongue: 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 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


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks for the code - it works fine on both the emulator and the hardware.
Guess I’ll do things this way rather than setting up OpenGL manually (GLES
versions and so on). I don’t see any disadvantages, so long as it runs, and
it’s a lot less start-up code to worry about.

WilliamOn 26 July 2011 19:05, Dimitris Zenios <dimitris.zenios at gmail.com> wrote:

#include “SDL.h”

int main(int argc, char* argv[])
{
SDL_Window* window;
SDL_Renderer* renderer;

   // Initialize SDL.
   if (SDL_Init(SDL_INIT_VIDEO) < 0)
           return 1;

   // Create the window where we will draw.
   window = SDL_CreateWindow("SDL_RenderClear",
                    SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                    512, 512,
                   SDL_WINDOW_SHOWN);

   // We must call SDL_CreateRenderer in order for draw calls to

affect this window.
renderer = SDL_CreateRenderer(window, -1, 0);

   // Select the color for drawing. It is set to red here.
   SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);

   whiile(!quit) {
   // Clear the entire screen to our selected color.
   SDL_RenderClear(renderer);

   // Up until now everything was drawn behind the scenes.
   // This will show the new, red contents of the window.
   SDL_RenderPresent(renderer);

    // Give us time to see the window.
   SDL_Delay(50);
   }





   // Always be sure to clean up
   SDL_Quit();
   return 0;

}

On Tue, Jul 26, 2011 at 11:53 AM, William Dyce <@William_Dyce> wrote:

Dimitris: never actually used the renderer before. The documentation is
pretty good though. I’m guessing SDL_RENDERER_ACCELERATED isn’t going to
work, any suggestions for what kind?

Just trying to get Code::Blocks to compile my project using SDL 1.3
rather
than 1.2 so I can do some tests on Linux as well as Android. This is
looking
good so far though guys - thanks very much for all of you help :slight_smile:

William

On 26 July 2011 18:28, Dimitris Zenios <dimitris.zenios at gmail.com> wrote:

William you can create a renderer for the window and do render present
on the renderer.hat way you will not need the opengl code.You will use
the SDL rendering api

On Tue, Jul 26, 2011 at 10:54 AM, William Dyce <@William_Dyce> wrote:

You beauty :smiley:

I combined the Dimitris and Ryan’s examples (attached): I’ve never
been

so
happy to see a red rectangle :stuck_out_tongue: 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 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


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks for the info, I was looking into this too myself.
Just one more question: how do I force the window to start in the device’s native resolution? Just setting 0 for both width and height in SDL_CreateWindow?
Or do I have to actually know the device’s resolution before setting it?

What ever you pass it will be overwritten by the native screen resolution.On Tue, Jul 26, 2011 at 5:55 PM, josebagar <joseba.gar at gmail.com> wrote:

Thanks for the info, I was looking into this too myself.
Just one more question: how do I force the window to start in the device’s
native resolution? Just setting 0 for both width and height in
SDL_CreateWindow?
Or do I have to actually know the device’s resolution before setting it?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Dimitris Zenios wrote:

What ever you pass it will be overwritten by the native screen resolution.

Thanks for the info, I was looking into this too myself.
Just one more question: how do I force the window to start in the device’s
native resolution? Just setting 0 for both width and height in
SDL_CreateWindow?
Or do I have to actually know the device’s resolution before setting it?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks. I’m working with a game engine that sits on top of SDL so that’s probably the cause of the video mode not being set correctly, then.> On Tue, Jul 26, 2011 at 5:55 PM, josebagar <@josebagar> wrote:

That’s very interesting to know - is there any way of knowing what this
resolution is from inside the App? Actually it probably doesn’t matter if
everything will just be scaled anyway…On 27 July 2011 06:15, josebagar <joseba.gar at gmail.com> wrote:

**

Dimitris Zenios wrote:

What ever you pass it will be overwritten by the native screen
resolution.

On Tue, Jul 26, 2011 at 5:55 PM, josebagar <> wrote:

Quote:

Thanks for the info, I was looking into this too myself.
Just one more question: how do I force the window to start in the device’s
native resolution? Just setting 0 for both width and height in
SDL_CreateWindow?
Or do I have to actually know the device’s resolution before setting it?


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks. I’m working with a game engine that sits on top of SDL so that’s
probably the cause of the video mode not being set correctly, then.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Once you create the window you can call SDL_GetWindowSize to retrieve the
native size of the screenOn Wed, Jul 27, 2011 at 8:38 AM, William Dyce wrote:

That’s very interesting to know - is there any way of knowing what this
resolution is from inside the App? Actually it probably doesn’t matter if
everything will just be scaled anyway…

On 27 July 2011 06:15, josebagar <joseba.gar at gmail.com> wrote:

**

Dimitris Zenios wrote:

What ever you pass it will be overwritten by the native screen
resolution.

On Tue, Jul 26, 2011 at 5:55 PM, josebagar <> wrote:

Quote:

Thanks for the info, I was looking into this too myself.
Just one more question: how do I force the window to start in the device’s
native resolution? Just setting 0 for both width and height in
SDL_CreateWindow?
Or do I have to actually know the device’s resolution before setting it?


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks. I’m working with a game engine that sits on top of SDL so that’s
probably the cause of the video mode not being set correctly, then.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Fantastic :smiley: thought we might have to go through the JNI or something.
That’s good new.On 27 July 2011 16:25, Dimitris Zenios <dimitris.zenios at gmail.com> wrote:

Once you create the window you can call SDL_GetWindowSize to retrieve the
native size of the screen

On Wed, Jul 27, 2011 at 8:38 AM, William Dyce <@William_Dyce> wrote:

That’s very interesting to know - is there any way of knowing what this
resolution is from inside the App? Actually it probably doesn’t matter if
everything will just be scaled anyway…

On 27 July 2011 06:15, josebagar <joseba.gar at gmail.com> wrote:

**

Dimitris Zenios wrote:

What ever you pass it will be overwritten by the native screen
resolution.

On Tue, Jul 26, 2011 at 5:55 PM, josebagar <> wrote:

Quote:

Thanks for the info, I was looking into this too myself.
Just one more question: how do I force the window to start in the
device’s
native resolution? Just setting 0 for both width and height in
SDL_CreateWindow?
Or do I have to actually know the device’s resolution before setting it?


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks. I’m working with a game engine that sits on top of SDL so that’s
probably the cause of the video mode not being set correctly, then.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Once you create the window you can call SDL_GetWindowSize to retrieve
the native size of the screen

SDL_GetDisplayMode() should work, too, and will make your code portable
to other systems that you don’t really want a 0x0 size window on. :slight_smile:

(At least, I hope it does. Android devs: is this working?)

–ryan.

SDL_GetDisplayMode() should work, too, and will make your code portable to
other systems that you don’t really want a 0x0 size window on. :slight_smile:

I suppose I could hard-code for Desktops if the mobiles are doing to
override whatever resolution I choose. Developing for radically different
screen resolutions is quite new to me: in the past I’ve just open a window
with a sufficiently low resolution that almost all computer these days would
have. I guess I’m going to need to be a bit more clever this time…

Ryan: while I have you, is it possible to rotate sprites in SDL 1.3? I
remember giving up trying to do it in 1.2…

Thanks,

WilliamOn 28 July 2011 14:01, Ryan C. Gordon wrote:

Once you create the window you can call SDL_GetWindowSize to retrieve

the native size of the screen

SDL_GetDisplayMode() should work, too, and will make your code portable to
other systems that you don’t really want a 0x0 size window on. :slight_smile:

(At least, I hope it does. Android devs: is this working?)

–ryan.

_____________**
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/**listinfo.cgi/sdl-libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org