SDL and the iphone , a retraction

Well this Girl is willing to admit when she is wrong.

Over the last few days I made some comments and I know other reviewers have made similar comments that sdl wasn’t ready for the iphone, that it was hard to use and had limited functionality.

Well I think I will have to retract that.

The more I use sdl the more I like it, will it replace open gl for my game coding, no not entirely, I’ve recently started playing with opengles2 and think there are huge performance increases.

But for porting projects from linux such as those based on ffmpeg or games that I want to be cross platform SDL works beautiful, it may even be worth the 100.00 license fee, except I have a tendency to want to share my code.

One issue I had was I couldn’t find any samples of mixing iphone sdk with sdl, welll I still can’t, but thats probably because sdl is not widely used now on the iphone or used mostly for highly graphical games and simulations that might not have a ui.

As usual I just set out and put together some samples myself.

My first attempt was rather crude, I copy the uikit folder from the sdl distribution and in xcode excluded it from their, than I created a selectot in a viewcontroller to launch my c program. This worked but seemed a lot like a hack.

Then I encountered a app that was ported some time ago and was converted for full screen sdl, I wanted to add a ui to it, but for the life of me I couldn’t find what options they used to compile it. all I knew was that it was sdl 1.3 revision 4404.

So this time I pulled the appdelegate from the svn, copied it into my project along with a few required headers, And as I though when I ran my project it picked up my modified app delegate which had a navigation controller which immediately took you into a tabbed menu system.

All in all, it worked beautifully and I had the best of both the sdk and sdl worlds.

Buttom line, to do anything sdkish in sdl all you have to do is get hold of the uikitappdelegate.

I will reiterate one thing I said before and that is SDL is one of those frameworks you either hate or love.

I think my relationship has gone from hate to Love.

Congratulations on a very cool implementation. Once you learn to use it that is.

If sdl has any really lacking, its that there very little documentation aimed at the mobile platforms, but than again what package does have that.
That platform is constantly in flux right now.

SDL 1.3 doesn’t really have decent documentation period outside of what’s in the header files.

It also doesn’t have any tutorials for it, excepting some OpenGLES tutorials that use it for events and windowing.
Perhaps you could make some tutorials and code samples for using SDL alongside UIKit, and post them here or host them elsewhere.

A little history lesson might be in order. Maybe this has been covered
in one of the other mammoth threads, but I didn’t notice it.

In case you weren’t aware, the iPhone port of SDL was a Google code
project by a student either this summer or the one preceding it. I
imagine that the extent of that port was just getting the API to work
on the iPhone, and I doubt the student had the time (possibly not even
the inclination) to see how easy or hard it was to write an app from
scratch on the phone, the focus was probably on porting existing
applications.

This is also the reason you are finding it hard to get documentation
or examples. Documenting your own experience might be valuable for
those who will follow in your footsteps.

Though a dedicated SDL_iPhone library could be useful too, if there
are common cases for SDL programs to shield developers from the native
APIs.

Glad you are coming around to liking SDL =)

– BrianOn 19 February 2010 02:26, michelleC wrote:

Well this Girl is willing to admit when she is wrong.

I can respect that, because I’ve had occassion to help college students out with projects. The internet is great for students, I’ve recently helped some students get an apple push notification server up and running , I never even heard of the place they are from its somewhere in the netherlands.

We’ve had occassion at my job to bring in interns from local colleges, they usually feel rushed and don’t always complete the over ambitious projects they are give. And they are not expected to (I don’t come up with the projects or the policy), deadlines are all part of the learning process.

I see reason now for a dedicated iphone extension, just better documentation, I had problems getting the latest version of 1.3 to work with an app, its because an early version of sdl was used and I don’t know how these folks compiled it , I will explore that though.

But the point here, is without recompiling the library I was able to get a lot of integration.

Some days ago , maybe is was missed because it was in another part of this forum, I put out a sample of my first attempt at the integration, I am refining that and will put out more code samples and doc. I may be that I end up producing the doc you are talking about that, I have no problem with that, SDL’s code structure is not that bad to follow.

I kind of created a flow for my self and figured out all the major integration points.

http://sol3.typepad.com/tagalong_developer_journa/2010/02/sdl-and-coaca-revisted.html

This may interest you to, its one of the apps I am developing which uses sdl

http://www.idevgames.com/forum/showthread.php?t=18860

All and all a bit challenging, interesting and sometimes fun learning experience.

Brian Barrett wrote:> A little history lesson might be in order. Maybe this has been covered

in one of the other mammoth threads, but I didn’t notice it.

In case you weren’t aware, the iPhone port of SDL was a Google code
project by a student either this summer or the one preceding it. I
imagine that the extent of that port was just getting the API to work
on the iPhone, and I doubt the student had the time (possibly not even
the inclination) to see how easy or hard it was to write an app from
scratch on the phone, the focus was probably on porting existing
applications.

This is also the reason you are finding it hard to get documentation
or examples. Documenting your own experience might be valuable for
those who will follow in your footsteps.

Though a dedicated SDL_iPhone library could be useful too, if there
are common cases for SDL programs to shield developers from the native
APIs.

Glad you are coming around to liking SDL =)

– Brian

On 19 February 2010 02:26, michelleC <@michelleC> wrote:

Well this Girl is willing to admit when she is wrong.


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

mandarx wrote:

michelleC wrote:

I created a selectot in a viewcontroller to launch my c program.

Questions about iPhone development:

I’m reading a book “Beginning iPhone Development: Exploring the iPhone SDK” (Apress) http://apress.com/book/view/1430216263

it says that it’s better to write in obj-c

is really obj-c more performant than c or c++ on iPhone?

is it possible to write in c++ on iPhone?

does SDL require c or c++ code, or it works even with obj-c ??

thanks for your answers!!

I don’t remember that quote in the book, I will have to look at that, I read that book sometime ago, its a great beginners book.

From what Ii understand objective-c code is somewhat slower than pure c code.

You can mix the two as much as you like.

Usually c code will be prefixed with c .

Yes you can use C++ on the iphone, there is a good open source framwork you can use openframeworks.

http://www.openframeworks.cc/

I haven’t tried it with sdl but there is no reason I can see it won’t work.

if you download my code sample, your notice that I use both c and objective c

In the viewcontroller I call a modified version of the PostFinishProcessing selector to actually navigate to my sdl application, one caveat sdl_quit doesn’t seem to work, so I remove the objects from memory myself.

mandarx wrote:

michelleC wrote:

I created a selectot in a viewcontroller to launch my c program.

Questions about iPhone development:

I’m reading a book “Beginning iPhone Development: Exploring the iPhone SDK” (Apress) http://apress.com/book/view/1430216263

it says that it’s better to write in obj-c

is really obj-c more performant than c or c++ on iPhone?

is it possible to write in c++ on iPhone?

does SDL require c or c++ code, or it works even with obj-c ??

thanks for your answers!!

SDL will work with objective-C. Objective-C will compile any C code, no issues.
It’s possible to write C++ on the Mac, so I don’t see why it would be an issue on the iPhone. I think that gobjc has support for Objective-C++, which lets you mix C++ and Objective-C code together; but I may be wrong on that.
The book probably suggests writing purely in Obj-C for two reasons:

  1. All of Apple’s APIs are in Obj-C; not using Obj-C would prevent you from accessing them directly. Since iPhone licensing prevents dynamic linking, I doubt many “handy” C/C++ libraries have been ported – meaning that you’ll probably need to use the Obj-C APIs for most applications anyway.
  2. Obj-C 2.0 has a garbage collector, meaning you don’t need to worry about freeing the memory you use. This makes life much easier on the developer.
  3. This guy was probably paid by Apple to write the book – so why wouldn’t he encourage it?

Great, I’m glad to hear it’s working out for you!

I don’t have as much experience on the iPhone platform as you do, so
I’m really looking forward to any tutorials or documentation you put
together. I would definitely like to add it to the 1.3 wiki:
http://wiki.libsdl.org/

Thanks! :)On Thu, Feb 18, 2010 at 6:26 PM, michelleC wrote:

Well this Girl is willing to admit when she is wrong.

Over the last few days I made some comments and I know other reviewers have
made similar comments that sdl wasn’t ready for the iphone, that it was hard
to use and had limited functionality.

Well I think I will have to retract that.

The more I use sdl the more I like it, will it replace open gl for my game
coding, no not entirely, I’ve recently started playing with opengles2 and
think there are huge performance increases.

But for porting projects from linux such as those based on ffmpeg or games
that I want to be cross platform SDL works beautiful, it may even be worth
the 100.00 license fee, except I have a tendency to want to share my code.

One issue I had was I couldn’t find any samples of mixing iphone sdk with
sdl, welll I still can’t, but thats probably because sdl is not widely used
now on the iphone or used mostly for highly graphical games and simulations
that might not have a ui.

As usual I just set out and put together some samples myself.

My first attempt was rather crude, I copy the uikit folder from the sdl
distribution and in xcode excluded it from their, than I created a selectot
in a viewcontroller to launch my c program. This worked but seemed a lot
like a hack.

Then I encountered a app that was ported some time ago and was converted for
full screen sdl, I wanted to add a ui to it, but for the life of me I
couldn’t find what options they used to compile it. all I knew was that it
was sdl 1.3 revision 4404.

So this time I pulled the appdelegate from the svn, copied it into my
project along with a few required headers, And as I though when I ran my
project it picked up my modified app delegate which had a navigation
controller which immediately took you into a tabbed menu system.

All in all, it worked beautifully and I had the best of both the sdk and sdl
worlds.

Buttom line, to do anything sdkish in sdl all you have to do is get hold of
the uikitappdelegate.

I will reiterate one thing I said before and that is SDL is one of those
frameworks you either hate or love.

I think my relationship has gone from hate to Love.

Congratulations on a very cool implementation. Once you learn to use it that
is.

If sdl has any really lacking, its that there very little documentation
aimed at the mobile platforms, but than again what package does have that.
That platform is constantly in flux right now.


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


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

michelleC wrote:

You can mix the two as much as you like.

Yes you can use C++ on the iphone, there is a good open source framwork you can use openframeworks.

http://www.openframeworks.cc/

great, thanks for sharing

michelleC wrote:

if you download my code sample, your notice that I use both c and objective c

I followed your links but I didn’t find any code…

where can I download it??

MandarX------------------------
http://mandarx.xoom.it/index.php?lang=eng

nfries88 wrote:

SDL will work with objective-C. Objective-C will compile any C code, no issues.
It’s possible to write C++ on the Mac, so I don’t see why it would be an issue on the iPhone.

you never know!! you know apple!

thank you for your answer

MandarX------------------------
http://mandarx.xoom.it/index.php?lang=eng

[quote=“nfries88”]
mandarx wrote:

michelleC wrote:

I created a selectot in a viewcontroller to launch my c program.

  1. This guy was probably paid by Apple to write the book – so why wouldn’t he encourage it?

Cool. But I don’t think it works that way.

I was recently approached by a couple publishers to write an iphone book. I declined because I would rather code. I think they look for either people who submit a lot of apps, or post a lot of blogs or something. apple has very little input.

Its not quite true that you have to use objective c to call the apple api.

You can mix c and objective c without an issue.

if you want to seperate the code

you can create a .m or .mm (c++)

for instance

void
OpenURL(const char *url)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
}

Than in your header code the prototype like this

void OpenURL(const char *url);

you can now call the method open url from your c or c++ code.

You could use the above for instance to retrieve information from a website while inside your game loop.

Here’s an example of calling your sdl c code (can be adopted for any c or c++) from a view controller

  • (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:NO];
    tabBar.selectedItem = [tabBar.items objectAtIndex:0];
    SDLUIKitDelegate *appDelegate = [SDLUIKitDelegate sharedAppDelegate];
    [appDelegate postProcessing:@“0”];

    }

postProcessing is a convience method that calls a method on the delegate that executes the main method in your c program.

  • (void) postProcessing:(NSString*)tab {

    [self performSelector:@selector(postFinishLaunch:) withObject:tab
    afterDelay:0.0];
    }

Code the above in the SDL_uikitAppDelegate or whatever class is your app delegate.

Notice that the tab index for the tab on the viewcontroller is being passed to the c program.

The c programs main method has a case statement that executes a particular sdl demo based on the tab value.

You can play with the completed example with this demo, build the demo (download the zip) against a recent sdl 1.3 source

the svn will ask for a password and username , please use test for both.

Be paitent with the server, its an old mac mini that is getting a lot of traffic lately because some of my projects have become more popular.
Right now I have no other place to host the demo.

D:\newice\2213\Demo\Demo\

this link
http://sol3.typepad.com/tagalong_developer_journa/2010/02/sdl-and-coaca-revisted.html
the svn server is listed there, its the same one used in other posts and the password and userid are both test.

Maybe you missed the link, its about the middle of the post.

please download demo.zip and build against a recent version of sdl 1.3

http://99.139.107.194/svn/test/sdldml/sdldml/

mandarx wrote:>

michelleC wrote:

You can mix the two as much as you like.

Yes you can use C++ on the iphone, there is a good open source framwork you can use openframeworks.

http://www.openframeworks.cc/

great, thanks for sharing

michelleC wrote:

if you download my code sample, your notice that I use both c and objective c

I followed your links but I didn’t find any code…

where can I download it??

MandarX

If you like I can put together some content based on the demo I created and explanding on it with some exerpts from the StreamX viewer I describe.

Your wiki and my blog can dual host that content , I have no problem with that. I’ll see what I can do early next week. This weekend is devoted to the all important task called Income Tax.

Sam Lantinga wrote:> Great, I’m glad to hear it’s working out for you!

I don’t have as much experience on the iPhone platform as you do, so
I’m really looking forward to any tutorials or documentation you put
together. I would definitely like to add it to the 1.3 wiki:
http://wiki.libsdl.org/

Thanks! :slight_smile:

On Thu, Feb 18, 2010 at 6:26 PM, michelleC <@michelleC> wrote:

Well this Girl is willing to admit when she is wrong.

Over the last few days I made some comments and I know other reviewers have
made similar comments that sdl wasn’t ready for the iphone, that it was hard
to use and had limited functionality.

Well I think I will have to retract that.

The more I use sdl the more I like it, will it replace open gl for my game
coding, no not entirely, I’ve recently started playing with opengles2 and
think there are huge performance increases.

But for porting projects from linux such as those based on ffmpeg or games
that I want to be cross platform SDL works beautiful, it may even be worth
the 100.00 license fee, except I have a tendency to want to share my code.

One issue I had was I couldn’t find any samples of mixing iphone sdk with
sdl, welll I still can’t, but thats probably because sdl is not widely used
now on the iphone or used mostly for highly graphical games and simulations
that might not have a ui.

As usual I just set out and put together some samples myself.

My first attempt was rather crude, I copy the uikit folder from the sdl
distribution and in xcode excluded it from their, than I created a selectot
in a viewcontroller to launch my c program. This worked but seemed a lot
like a hack.

Then I encountered a app that was ported some time ago and was converted for
full screen sdl, I wanted to add a ui to it, but for the life of me I
couldn’t find what options they used to compile it. all I knew was that it
was sdl 1.3 revision 4404.

So this time I pulled the appdelegate from the svn, copied it into my
project along with a few required headers, And as I though when I ran my
project it picked up my modified app delegate which had a navigation
controller which immediately took you into a tabbed menu system.

All in all, it worked beautifully and I had the best of both the sdk and sdl
worlds.

Buttom line, to do anything sdkish in sdl all you have to do is get hold of
the uikitappdelegate.

I will reiterate one thing I said before and that is SDL is one of those
frameworks you either hate or love.

I think my relationship has gone from hate to Love.

Congratulations on a very cool implementation. Once you learn to use it that
is.

If sdl has any really lacking, its that there very little documentation
aimed at the mobile platforms, but than again what package does have that.
That platform is constantly in flux right now.


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


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC


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

michelleC wrote:

Its not quite true that you have to use objective c to call the apple api.

You can mix c and objective c without an issue.

if you want to seperate the code

you can create a .m or .mm (c++)

for instance

void
OpenURL(const char *url)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
}

Than in your header code the prototype like this

void OpenURL(const char *url);

Yes, I’ve assisted in porting some C++ code to mac, I’m well aware of the ability to make C functions that use Obj-C code internally. That’s also how SDL on Mac/iPhone works (duh).
The fact of the matter is that unless/until someone makes a C or C++ Cocoa wrapper; developers will have to use Obj-C to use most of the Cocoa APIs.
I’m just glad that SDL minimizes that need as much as it does. I really hope SDL 1.3 gets clipboard support too (Sam has already said something about adding it), then most apps will have no need to use Cocoa directly.

I don’t see why NeXT chose Obj-C for NeXTStep anyway. I guess that C++ hadn’t matured enough by '89 for it to be used?

I don’t see why NeXT chose Obj-C for NeXTStep anyway. I guess that C++ hadn’t matured enough by '89 for it to be used?

Heck, C++ hasn’t matured enough by 2010 to be worth using! ;)>From: nfries88

Subject: Re: [SDL] SDL and the iphone , a retraction

Maybe I am not getting the big picture here, but whats the big deal about having to mix in objective-c code, there all varients of c anyway.

As for clipboard support.

How do you feel that would eliminate having to call objective-c functions.

There are different ways to use the clipboard, but are you talking about having the sdl code put information on the clipboard and than swap back to the ui and get the info off the clipboard.

I think that is possible, uikit window and the sdl window swaping being the key window.

I don’t do that, every execution of my app is a new instance. I let the iphone manage the cleaning up of resources for me, I just destroy and window and renderer and pop back to the ii

nfries88 wrote:>

michelleC wrote:

Its not quite true that you have to use objective c to call the apple api.

You can mix c and objective c without an issue.

if you want to seperate the code

you can create a .m or .mm (c++)

for instance

void
OpenURL(const char *url)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
}

Than in your header code the prototype like this

void OpenURL(const char *url);

Yes, I’ve assisted in porting some C++ code to mac, I’m well aware of the ability to make C functions that use Obj-C code internally. That’s also how SDL on Mac/iPhone works (duh).
The fact of the matter is that unless/until someone makes a C or C++ Cocoa wrapper; developers will have to use Obj-C to use most of the Cocoa APIs.
I’m just glad that SDL minimizes that need as much as it does. I really hope SDL 1.3 gets clipboard support too (Sam has already said something about adding it), then most apps will have no need to use Cocoa directly.

I don’t see why NeXT chose Obj-C for NeXTStep anyway. I guess that C++ hadn’t matured enough by '89 for it to be used?

[/quote]

I don’t see why NeXT chose Obj-C for NeXTStep anyway. I guess that C++ hadn’t matured enough by '89 for it to be used?[/quote]

Maybe I am one of the few people on the planet that like objective-c.

Maybe its because I grew up with Smalltalk, in fact I use to program with smalltalk, lisp and prolog a lot.

So when I first used objective-c some of it seemed very familar, like an old friend coming back after a long time.

But I understand there are a lot of developers who don’t like it.

I’d take objective-c any day over javaME.

Basically yes, C++ was crap back in '89. It only became good after the
inclusion of STL as part of the standard (and then again most C++ code
out there still doesn’t use modern C++ idioms correctly, since the
language makes it so easy to NOT do so).

Arguably Objective C makes more sense than C++ in a GUI context
anyway, due to its messaging-like method calls (that are very
reminiscent of Smalltalk).

Objective C never caught on outside of the Next/Apple bubble but that
doesn’t mean it’s a bad language.On Fri, Feb 19, 2010 at 14:19, nfries88 wrote:

I don’t see why NeXT chose Obj-C for NeXTStep anyway. I guess that C++ hadn’t matured enough by '89 for it to be used?

  • SR

Objective-c is becoming more popular now with the introduction of the iphone.

I’m all for reviving smalltalk.

I always said that the biggest problem with smalltalk is the hardware just wasn’t ready for the language.

The interface of the Star looks primitive by todays standard BUT compared to dos it was light years ahead.

A new updated smalltalk would be interested, I know some new versions have come out, but not treated seriously

Most Smalltalk old timers are actually doing Ruby nowadays. Just go to a
Ruby conference and
check the amount of developers with Smalltalk background, and you will find
lots of them.On Fri, Feb 19, 2010 at 9:23 PM, michelleC wrote:

Objective-c is becoming more popular now with the introduction of the
iphone.

I’m all for reviving smalltalk.

I always said that the biggest problem with smalltalk is the hardware just
wasn’t ready for the language.

The interface of the Star looks primitive by todays standard BUT compared
to dos it was light years ahead.

A new updated smalltalk would be interested, I know some new versions have
come out, but not treated seriously


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

You can still share your code even if you purchase an SDL license.On Thu, Feb 18, 2010 at 9:26 PM, michelleC wrote:

But for porting projects from linux such as those based on ffmpeg or games
that I want to be cross platform SDL works beautiful, it may even be worth
the 100.00 license fee, except I have a tendency to want to share my code.


http://codebad.com/