Setup an iOS app

Hey,

I’m somewhat confused about iOS support.

What’s done: I successfully tested the SDL demos for iOS. My next step would be to follow the video section of the migration guide (http://wiki.libsdl.org/MigrationGuide#Video), simply to understand how to setup an SDL app. In fact, I simply try to create a window + renderer, and draw something simple on the display. But for some reason it just don’t work (I’m using the iPhone simulator).

Here’s an excerpt from the source. It should simply create a window + renderer, clears the background to red, wait a little and exit …

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

SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(NULL, 0, 0, 320, 480,
                            SDL_WINDOW_OPENGL |
                            SDL_WINDOW_BORDERLESS);
renderer = SDL_CreateRenderer(window, -1, 0);

SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(5000);

SDL_Quit();

return 0;

}

… but somehow it just hangs. No red screen, not borderless, and doesn’t exit (even if I press the button).

I know, the SDL demos create an OpenGL context, but wonder what’s the proper way to setup a SDL2 program for iOS.

thanks

Try pumping events (via SDL_PumpEvents(), or SDL_PollEvent()) at least once before rendering. For some reason that escapes me, SDL on iOS needs to do this at least once before content will get rendered.

Cheers,
– David L.

Isn’t that due to the callback mechanism or the gamecenter loop?
I recall a lot of discussion about this.

VittorioOn Thu, Sep 19, 2013 at 1:38 AM, DLudwig wrote:

Try pumping events (via SDL_PumpEvents(), or SDL_PollEvent()) at least once
before rendering. For some reason that escapes me, SDL on iOS needs to do
this at least once before content will get rendered.

If you try to quit on iOS, your app will hang.

You’re not supposed to quit/exit on iOS or Android. The user will switch
to another app and the OS will decide when to kill your app.On 9/19/2013 12:45 AM, Laz-Roc wrote:

Hey,

I’m somewhat confused about iOS support.

What’s done: I successfully tested the SDL demos for iOS. My next step
would be to follow the video section of the migration guide
http://wiki.libsdl.org/MigrationGuide#Video, simply to understand
how to setup an SDL app. In fact, I simply try to create a window +
renderer, and draw something simple on the display. But for some
reason it just don’t work (I’m using the iPhone simulator).

Here’s an excerpt from the source. It should simply create a window +
renderer, clears the background to red, wait a little and exit …

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

SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(NULL, 0, 0, 320, 480,
                            SDL_WINDOW_OPENGL |

SDL_WINDOW_BORDERLESS);
renderer = SDL_CreateRenderer(window, -1, 0);

SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(5000);

SDL_Quit();

return 0;

}

… but somehow it just hangs. No red screen, not borderless, and
doesn’t exit (even if I press the button).

I know, the SDL demos create an OpenGL context, but wonder what’s the
proper way to setup a SDL2 program for iOS.

thanks


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming

Wait… So you mean that SDL_Quit() should not be called at all for Android or iOS?On Sep 19, 2013, at 1:19 PM, Pallav Nawani wrote:

If you try to quit on iOS, your app will hang.

You’re not supposed to quit/exit on iOS or Android. The user will switch to another app and the OS will decide when to kill your app.

On 9/19/2013 12:45 AM, Laz-Roc wrote:

Hey,

I’m somewhat confused about iOS support.

What’s done: I successfully tested the SDL demos for iOS. My next step would be to follow the video section of the migration guide http://wiki.libsdl.org/MigrationGuide#Video, simply to understand how to setup an SDL app. In fact, I simply try to create a window + renderer, and draw something simple on the display. But for some reason it just don’t work (I’m using the iPhone simulator).

Here’s an excerpt from the source. It should simply create a window + renderer, clears the background to red, wait a little and exit …

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

SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(NULL, 0, 0, 320, 480,
SDL_WINDOW_OPENGL |
SDL_WINDOW_BORDERLESS);
renderer = SDL_CreateRenderer(window, -1, 0);

SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(5000);

SDL_Quit();

return 0;
}

… but somehow it just hangs. No red screen, not borderless, and doesn’t exit (even if I press the button).

I know, the SDL demos create an OpenGL context, but wonder what’s the proper way to setup a SDL2 program for iOS.

thanks


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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

That just deinitializes the subsystems.

What it means is that the program should never finish (i.e. never
reach the end of main(), never call exit(), etc.). Try that and the
phone is bound to spazz out.

2013/9/19, neoaggelos at gmail.com :> Wait… So you mean that SDL_Quit() should not be called at all for Android

or iOS?

On Sep 19, 2013, at 1:19 PM, Pallav Nawani wrote:

If you try to quit on iOS, your app will hang.

You’re not supposed to quit/exit on iOS or Android. The user will switch
to another app and the OS will decide when to kill your app.

On 9/19/2013 12:45 AM, Laz-Roc wrote:

Hey,

I’m somewhat confused about iOS support.

What’s done: I successfully tested the SDL demos for iOS. My next step
would be to follow the video section of the migration guide
http://wiki.libsdl.org/MigrationGuide#Video, simply to understand how
to setup an SDL app. In fact, I simply try to create a window + renderer,
and draw something simple on the display. But for some reason it just
don’t work (I’m using the iPhone simulator).

Here’s an excerpt from the source. It should simply create a window +
renderer, clears the background to red, wait a little and exit …

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

SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(NULL, 0, 0, 320, 480,
SDL_WINDOW_OPENGL |
SDL_WINDOW_BORDERLESS);
renderer = SDL_CreateRenderer(window, -1, 0);

SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(5000);

SDL_Quit();

return 0;
}

… but somehow it just hangs. No red screen, not borderless, and doesn’t
exit (even if I press the button).

I know, the SDL demos create an OpenGL context, but wonder what’s the
proper way to setup a SDL2 program for iOS.

thanks


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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

That is correct.On 9/19/2013 5:24 PM, neoaggelos at gmail.com wrote:

Wait… So you mean that SDL_Quit() should not be called at all for Android or iOS?

On Sep 19, 2013, at 1:19 PM, Pallav Nawani <@Pallav_Nawani> wrote:

If you try to quit on iOS, your app will hang.

You’re not supposed to quit/exit on iOS or Android. The user will switch to another app and the OS will decide when to kill your app.

On 9/19/2013 12:45 AM, Laz-Roc wrote:

Hey,

I’m somewhat confused about iOS support.

What’s done: I successfully tested the SDL demos for iOS. My next step would be to follow the video section of the migration guide http://wiki.libsdl.org/MigrationGuide#Video, simply to understand how to setup an SDL app. In fact, I simply try to create a window + renderer, and draw something simple on the display. But for some reason it just don’t work (I’m using the iPhone simulator).

Here’s an excerpt from the source. It should simply create a window + renderer, clears the background to red, wait a little and exit …

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

SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(NULL, 0, 0, 320, 480,
                            SDL_WINDOW_OPENGL |

SDL_WINDOW_BORDERLESS);
renderer = SDL_CreateRenderer(window, -1, 0);

SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(5000);

SDL_Quit();

return 0;

}

… but somehow it just hangs. No red screen, not borderless, and doesn’t exit (even if I press the button).

I know, the SDL demos create an OpenGL context, but wonder what’s the proper way to setup a SDL2 program for iOS.

thanks


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

Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming

Not only it will spazz out, but your app won’t pass the Applestore review.
VittorioOn Thu, Sep 19, 2013 at 2:39 PM, Sik the hedgehog <sik.the.hedgehog at gmail.com> wrote:

That just deinitializes the subsystems.

What it means is that the program should never finish (i.e. never
reach the end of main(), never call exit(), etc.). Try that and the
phone is bound to spazz out.

Well, that’s weird. For me using exit() works on Android – it just quits the app.On Sep 19, 2013, at 3:41 PM, Pallav Nawani wrote:

That is correct.

On 9/19/2013 5:24 PM, @Aggelos_Kolaitis wrote:

Wait… So you mean that SDL_Quit() should not be called at all for Android or iOS?

On Sep 19, 2013, at 1:19 PM, Pallav Nawani wrote:

If you try to quit on iOS, your app will hang.

You’re not supposed to quit/exit on iOS or Android. The user will switch to another app and the OS will decide when to kill your app.

On 9/19/2013 12:45 AM, Laz-Roc wrote:

Hey,

I’m somewhat confused about iOS support.

What’s done: I successfully tested the SDL demos for iOS. My next step would be to follow the video section of the migration guide http://wiki.libsdl.org/MigrationGuide#Video, simply to understand how to setup an SDL app. In fact, I simply try to create a window + renderer, and draw something simple on the display. But for some reason it just don’t work (I’m using the iPhone simulator).

Here’s an excerpt from the source. It should simply create a window + renderer, clears the background to red, wait a little and exit …

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

SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(NULL, 0, 0, 320, 480,
SDL_WINDOW_OPENGL |
SDL_WINDOW_BORDERLESS);
renderer = SDL_CreateRenderer(window, -1, 0);

SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(5000);

SDL_Quit();

return 0;
}

… but somehow it just hangs. No red screen, not borderless, and doesn’t exit (even if I press the button).

I know, the SDL demos create an OpenGL context, but wonder what’s the proper way to setup a SDL2 program for iOS.

thanks


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

Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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

Try pumping events (via SDL_PumpEvents(), or SDL_PollEvent()) at least once before rendering.

Thanks for the hint. That was the missing link for the setup, after adding something like this …

Code:
bool done = false;
while (!done) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
// checking for events here …
}
// rendering here …
}

What still confuses me is, that the home button won’t bring me out of the app, and hangs again. Maybe it’s an issue with the simulator, but when I tried NeHe’s iOS Tutorial (http://nehe.gamedev.net/tutorial/ios_lesson_01__setting_up_gl_es/44001/) (Objective-C + OpenGLES - SDL) everything seems to work perfect.

Laz-Roc wrote:

What still confuses me is, that the home button won’t bring me out of the app, and hangs again. Maybe it’s an issue with the simulator, but when I tried NeHe’s iOS Tutorial (http://nehe.gamedev.net/tutorial/ios_lesson_01__setting_up_gl_es/44001/) (Objective-C + OpenGLES - SDL) everything seems to work perfect.

I don’t see this behavior on my own iPhone (a 4S running iOS 7), where pressing the home button brings up the home screen. Perhaps my code is different than yours, or there’s a key difference in hardware/OS/etc. What code are you using now to get this behavior? Here is a link to the app code I used to try to reproduce this: http://pastebin.com/SqbXDTEU

Cheers,
– David L.

Vittorio Giovara wrote:

Isn’t that due to the callback mechanism or the gamecenter loop?
I recall a lot of discussion about this.

I think that it’s something like this. I remember looking into it myself a ways back, and figured it had something to do with some iOS-internal, possibly undocumented callbacks not getting processed, but I don’t remember much more than that.

Cheers,
– David L.

I don’t see this behavior on my own iPhone (a 4S running iOS 7), where pressing the home button brings up the home screen. Perhaps my code is different than yours, or there’s a key difference in hardware/OS/etc. What code are you using now to get this behavior? Here is a link to the app code I used to try to reproduce this: http://pastebin.com/SqbXDTEU

That’s exactly the same code I have. Good to know that it’s running on a real device. I’m using OSX 10.6.8 and Xcode 4.2 with iOS SDK 5.0 right now, and just try some things with the simulator to check if it’s worth getting some new hardware.

Google’s guidelines on the application life-cycle do not have the
concept of apps quitting by themselves. It is clearly mentioned that the
app life-cycle is managed by the system. However, in practice, Android
is based on Linux so calling exit() on Android might well work.

This is guaranteed to hang your app on iOS however.On 9/19/2013 6:34 PM, neoaggelos at gmail.com wrote:

Well, that’s weird. For me using exit() works on Android – it just quits the app.

On Sep 19, 2013, at 3:41 PM, Pallav Nawani <@Pallav_Nawani> wrote:

That is correct.

On 9/19/2013 5:24 PM, neoaggelos at gmail.com wrote:

Wait… So you mean that SDL_Quit() should not be called at all for Android or iOS?

On Sep 19, 2013, at 1:19 PM, Pallav Nawani <@Pallav_Nawani> wrote:

If you try to quit on iOS, your app will hang.

You’re not supposed to quit/exit on iOS or Android. The user will switch to another app and the OS will decide when to kill your app.

On 9/19/2013 12:45 AM, Laz-Roc wrote:

Hey,

I’m somewhat confused about iOS support.

What’s done: I successfully tested the SDL demos for iOS. My next step would be to follow the video section of the migration guide http://wiki.libsdl.org/MigrationGuide#Video, simply to understand how to setup an SDL app. In fact, I simply try to create a window + renderer, and draw something simple on the display. But for some reason it just don’t work (I’m using the iPhone simulator).

Here’s an excerpt from the source. It should simply create a window + renderer, clears the background to red, wait a little and exit …

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

SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(NULL, 0, 0, 320, 480,
                            SDL_WINDOW_OPENGL |

SDL_WINDOW_BORDERLESS);
renderer = SDL_CreateRenderer(window, -1, 0);

SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(5000);

SDL_Quit();

return 0;

}

… but somehow it just hangs. No red screen, not borderless, and doesn’t exit (even if I press the button).

I know, the SDL demos create an OpenGL context, but wonder what’s the proper way to setup a SDL2 program for iOS.

thanks


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

Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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

Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming


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
.


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming