SFML community forums

Help => General => Topic started by: CJ_COIMBRA on April 07, 2012, 05:33:55 pm

Title: SFML 1.6 on newest Xcode
Post by: CJ_COIMBRA on April 07, 2012, 05:33:55 pm
I am trying to get one of my projects to Mac but I'm new to all this mac thing. I followed the tutorial for the 1.6 with Xcode, but I couldn't find the Developer folder to put the project templates in. I searched about this and it happens that the new Xcode is a bundle and the Developer folder is gone (or somewhere inside the bundle whatever is it).

So where and how could I place the templates in the right place now?

If there isn't a way to place this templates, just the .frameworks will do the job? I mean, can I go without the templates? If so, does somebody care to share a minimal example? I tried just to put some #includes and but I get errors while building.

Xcode version is 4.3.2 I believe and OSX 10.7.3.

Also, since the project is really advanced right now, I would like to keep it 1.6. 

Thanks, any aditional info would be helpful!
Title: Re: SFML 1.6 on newest Xcode
Post by: Hiura on April 07, 2012, 07:12:34 pm
Templates for SFML 1.6 work only with Xcode 3. There is no replacement for this version of SFML. (SFML 2 has working Xcode 4 templates.)

Quote
If there isn't a way to place this templates, just the .frameworks will do the job?
Yes. You only need to add the frameworks to your project like you would do it for Cocoa framework for example. Apple's doc. (https://developer.apple.com/library/ios/#recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html#//apple_ref/doc/uid/TP40010155-CH17-SW1)
Title: Re: SFML 1.6 on newest Xcode
Post by: CJ_COIMBRA on April 07, 2012, 11:02:29 pm
Cool! Thanks, it's working now!

I now it sounded like a stupid question but I am new to all this mac and xcode thing. I even took 10 minutes to find the goddamn power button!

By the way, for this app to work on another mac I'll have to send those .framework files together right? Or does xcode already arrange that somehow?
Title: Re: SFML 1.6 on newest Xcode
Post by: Hiura on April 07, 2012, 11:15:00 pm
By the way, for this app to work on another mac I'll have to send those .framework files together right? Or does xcode already arrange that somehow?
By default Xcode does nothing. The best way to distribute these frameworks with you application is to copy them to your application bundle.

Have a look at this post : http://stackoverflow.com/questions/8102609/build-cocoa-application-bundle-with-private-dylib-framework  ;)
Title: Re: SFML 1.6 on newest Xcode
Post by: CJ_COIMBRA on April 08, 2012, 07:40:15 pm
Another quick question:

How can I load images from a relative path? I mean on Windows I just leave my image loading code with

someImage.LoadFromFile("GFX/someImage.png");

I've loaded from full path on mac just to test and it's ok:

apple_img.LoadFromFile("/Users/christian/Documents/SFMLAPP/apple_ex.png");

But obviously won't work on another computer.
Title: Re: SFML 1.6 on newest Xcode
Post by: Hiura on April 08, 2012, 08:23:53 pm
You can include resources into your application bundle pretty much the same way than frameworks.

I think SFML 1.6 made you application bundle's resource path the working directory. So you can juste use "someImage.png" in your code and it will automatically find that file.


If I'm wrong about SFML 1.6 behaviour :

In order to use them we provide these two files : ResourcePath.hpp (https://github.com/SFML/SFML/blob/master/tools/xcode/templates/SFML/SFML%20Application%20Base.xctemplate/ResourcePath.hpp) & ResourcePath.mm (https://github.com/SFML/SFML/blob/master/tools/xcode/templates/SFML/SFML%20Application%20Base.xctemplate/ResourcePath.mm).

Simply add them to your project and use resourcePath() to locate your application bundle's resource path. You'll probably need to link your project against Foundation.framework.
Title: Re: SFML 1.6 on newest Xcode
Post by: Ceylo on April 08, 2012, 09:36:04 pm
I think SFML 1.6 made you application bundle's resource path the working directory. So you can juste use "someImage.png" in your code and it will automatically find that file.
This is right, with SFML 1.6 the relative paths are relative to the Resources directory (your_app.app/Contents/Resources), wherever you put your application. Thus you should copy your images there (or in a subdirectory).
Title: Re: SFML 1.6 on newest Xcode
Post by: CJ_COIMBRA on April 08, 2012, 11:14:05 pm
Ceylo,

myImage.LoadFromFile("my_app.app/Contents/Resources/myImage.png");

Is this what you mean?
Title: Re: SFML 1.6 on newest Xcode
Post by: Hiura on April 08, 2012, 11:15:06 pm
simply

myImage.LoadFromFile("myImage.png");
Title: Re: SFML 1.6 on newest Xcode
Post by: Ceylo on April 08, 2012, 11:18:40 pm
simply

myImage.LoadFromFile("myImage.png");
Yup. The your_app.app/Contents/Resources thing was to tell you where to put your file. But once your file is at your_app.app/Contents/Resources/myImage.png, just use the code Hiura gave here :) .

Ceylo
Title: Re: SFML 1.6 on newest Xcode
Post by: CJ_COIMBRA on April 08, 2012, 11:20:15 pm
Ah, ok.

Thanks guys, for the help and patience!
Title: Re: SFML 1.6 on newest Xcode
Post by: CJ_COIMBRA on April 08, 2012, 11:50:39 pm
Oh, let me abuse a little bit more:

Since I am not using those project templates , what kind of project is best for me to create sfml programs on Xcode? Command Line Tool ? Empty ?

Which one should be used? 
Title: Re: SFML 1.6 on newest Xcode
Post by: Hiura on April 09, 2012, 12:05:16 pm
If you start a new "Command Line Tool" project you won't be able to store any file in the application bundle (.app) because there isn't one. You get only an "raw" executable.

If you want to create an application bundle, start a new Cocoa Application project, then remove all sources and frameworks from the project (but keep "PROJECTNAME-Info.plist"!). Finally, add your source code, resources, .... That should be enough I think.
Title: Re: SFML 1.6 on newest Xcode
Post by: Ceylo on April 09, 2012, 12:26:43 pm
If you start a new "Command Line Tool" project you won't be able to store any file in the application bundle (.app) because there isn't one. You get only an "raw" executable.

If you want to create an application bundle, start a new Cocoa Application project, then remove all sources and frameworks from the project (but keep "PROJECTNAME-Info.plist"!). Finally, add your source code, resources, .... That should be enough I think.
If I remember well, you may also need to disable the prefix header precompilation.
Title: Re: SFML 1.6 on newest Xcode
Post by: CJ_COIMBRA on April 09, 2012, 02:50:12 pm
Thanks again! I´ll try this later after work.

By the way, I little off-topic now, supose I won´t use SFML, which library is best to develop games on OS/X ?
This cocoa thing looks like GUI-oriented but I might be terribly wrong. I´ve read something about the cocos2d too. Did you guys have any contact with other libraries?
Title: Re: SFML 1.6 on newest Xcode
Post by: Hiura on April 09, 2012, 11:07:37 pm
Cocoa is indeed more for GUI than for games but you can easily use opengl with it (e.g. with NSOpenGLView) and play with it.

I don't know cocos2d so I can't tell if it's good or not.