Gosu Forums - Not logged in
Forum Gosu Homepage Help Search Register Login
Previous Next Up Topic Gosu / Gosu on iPad, iPhone & iPod Touch / Creating a Gosu/C++ iPhone game
By jlnr (dev) Date 2009-02-21 12:39 Edited 2010-07-24 08:41
Hey,

this is not a proper Wiki page because I don't think the iPhone port will be officially supported for a while. Anyway, if anyone wants to port a C++ game to the iPhone, here's the steps as far as I remember:

One-time:
• install boost as shown on the GettingStartedOnOsx wiki page
• check out Gosu from SVN, build Gosu Touch for both Release and Debug

For new projects:
• create new OpenGL ES project
• set up development key as usual
• get rid of main.m and the .nib file
• add Gosu's headers to the include path (I add /opt/local/include and /usr/local/include, and put a symlink named 'Gosu' in there that links to the framework's headers, so #include <Gosu/xxx.hpp> will work)
• add -lgosutouch to the linker flags for Release, -lgosutouch-sim to the linker flags for Debug, and make sure the 'lib' folder of Gosu is in the library search path
• add CoreGraphics.framework, OpenAL.framework, AudioToolbox.framework and AVFoundation.framework to your project
• comment out the main function, instead implement this global function: Gosu::Window& windowInstance() { static MyWindowSubclass w; return w; }

See the other thread on this board for all the version numbers (Device x.x.x, Simulator x.x.x, use gcc x.x.x etc.)

Missing: Accelerometer support is not there yet (just like on OS X, sadly), but you can already handle touchesBegan/Moved/Ended as a replacement for buttonDown.

Things to note: Touches' coordinates are in screen coordinates (e.g. 0…480, 0…320 on iPhone <4), same for drawing coordinates. You can change both using the undocumented Graphics::setResolution and Input::setMouseFactors if you need to.
By hima Date 2009-03-03 17:25
Wow this is interesting! I don't owe a mac but is it possible to use PC to develop a game for iPhone? Maybe through VM or something?
By ramenudle Date 2009-03-03 21:44
Not through means that don't void the warranty on your iPhone...I could be wrong, but that's the impression I got when I looked into it. There's no official SDK for Windows iirc.
By jlnr (dev) Date 2009-03-04 01:00 Edited 2009-03-04 01:05
Officially, the SDK only works on Intel Macs, even cheap used PowerPC Macs can't be used out of the box. Installing OS X in a VM is supposedly possible but probably illegal in most places in the world (not sure :)), and I have no idea if that or jailbreaking will be a pleasant trip. But if you have some Gosu/C++ code that you'd like to see running on an iPhone/iPod, I can try to package it up and send it back.
By hima Date 2009-03-20 03:39
If it works, that would be SUPER!! :D
Date 2009-03-24 20:19
[topic branch moved]
By rolando Date 2009-03-25 01:06
this is my main.mm (had to rename it main.mm in order to put a c++ class there):

#import <UIKit/UIKit.h>
#import <Gosu/Gosu.hpp>

class GameWindow : public Gosu::Window
{
public:
  GameWindow() : Window(480, 320, true)
  {
  }
 
  void update()
  {
  }
 
  void draw()
  {
  }
};

Gosu::Window& windowInstance() {
  static GameWindow w;
  return w;
}

PS: thanks for the great job!!!
Edit: I'm using SDK 2.2, I have installed SDK 3.0 in another directory for testing purposes though.
By rolando Date 2009-03-25 13:54 Edited 2009-03-25 14:27
one tip: you can create a "fat" version of the libgosutouch.a with lipo:

$ lipo -create libgosutouch-sim.a libgosutouch.a -output libgosutouch-fat.a
$ file libgosutouch-fat.a
libgosutouch-fat.a: Mach-O universal binary with 2 architectures
libgosutouch-fat.a (for architecture i386):  current ar archive
libgosutouch-fat.a (for architecture cputype (12) cpusubtype (6)):  current ar archive

That way, you only add as libgosutouch-fat.a as an existing framework in you project and don't need to include the extra linking flags.
r./
By jlnr (dev) Date 2009-03-25 15:55
Hmm, II wonder if I can automate the creation of the fat file with Xcode? Would be very handy.

BTW, I checked and it turns out that Image's constructor does work with PNG files and even uses UIImage, but only the one that takes a filename. If you want to load PNGs from memory, you'll need the workaround I mentioned.
By rolando Date 2009-03-26 13:09
Regarding the automation of the fat library: I'm almost there, I still don't know if applescripting a little it could be fully automated. The problem: I don't know how to tell XCode to change platform.
The approach:
create 3 new targets: 1 for device, 1 for simulator and 1 for the fat version. You have to choose the static library template when creating the new target. For each of the targets (except the fat) add all the sources and required frameworks.
For the fat target, add the simulator and device version to the targets, so they will be compiled before (they are set as a dependency). Add a new build phase -> new run script build phase to the target, and use a script like this (change it to suit your needs):

mkdir -p lib
lipo -create build/$CONFIGURATION-iphoneos/libXXXSimulator.a build/$CONFIGURATION-iphonesimulator/libXXXDevice.a -output lib/libXXX.a

the env variable $CONFIGURATION is set by XCode and can be any of Debug, Release or Distribution.
This would work great if the simulator or device targets kept their platform settings, so the solution here is to compile each target before building the fat library, that way you make sure that the platform is set correctly for each version of the static library.
HTH,
r./
By jlnr (dev) Date 2009-03-26 21:21
Thanks, I will try that.

For now, I've fixed PNG loading, and the resolution is 480x320 by default now (it was weirdly stretched before, unless you called graphics().setResolution(...)).
By Maverick Date 2009-05-25 05:13
Julian, I have a question about making an iPhone game. I have an idea for one, but the game is designed to hold the iPhone vertically. You're demo shows you holding it horizontally. Is there anyway to specify how I want the game to be held or is it limited to horizontal for now? Thanks.
By jlnr (dev) Date 2009-05-25 07:18
Horizontal for now. Patching Gosu so that the screen resolution decides this would be very easy though. (320x480 -> vertical layout) I'll actually put that on the ToDo :)
By Maverick Date 2009-06-14 21:30
I don't see the template for an OpenGL ES project. Also I don't have access to the SVN so I can't view the touch demo you're talking about.
By jlnr (dev) Date 2009-06-14 21:37
Which version of the iPhone SDK do you have installed? And everyone has access to SVN, just see the GoogleCode page under "Source" :)
By Maverick Date 2009-06-16 18:30
There's nothing there about Gosu Touch. Do I have to be a member of Google Code to view anything?
By jlnr (dev) Date 2009-06-16 23:23
You have to open the Xcode project in the mac folder, select Gosu Touch and build it. There are no prebuilt binaries :)
By ? Date 2010-04-20 01:16
Hello, I am trying to use gosu for an iPhone game. I have set everything up according to the instructions, but have hit one final snag. Using rolando's code above (in my main.mm):

#include "main.h"

#import <UIKit/UIKit.h>
#import <Gosu/Gosu.hpp>

class GameWindow : public Gosu::Window
{
public:
  GameWindow() : Window(480, 320, true)
  {
  }
 
  void update()
  {
  }
 
  void draw()
  {
  }
};

Gosu::Window& windowInstance() {
  static GameWindow w;
  return w;
}

I get the following error about the missing main function, which got replaced by windowInstance()

Undefined symbols:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Any help would be greatly appreciated to aid me on my quest
By jlnr (dev) Date 2010-04-20 07:21
Weird, _main should be included in libgosutouch.a. Did you run into any trouble compiling the Touch version of Gosu? It actually had compilation bugs until later last night. (Or are you even decrescendo from IRC?)
By ? Date 2010-04-20 13:54
Ah very close, I am decrescendo's friend working on the same game. I updated Gosu last night and re-compiled with no errors, but that _main error still appeared. This morning I completely deleted Gosu and checked out a clean copy (just in case I tampered with a file), built just fine but still _main error. Do you think it could be a problem with my project? Should I try and create a new project?
By jlnr (dev) Date 2010-04-21 06:28
Hmmm, maybe you should really create one small project for testing. I can compile and link my iPhone game just fine. :|

Man, Xcode project templates are so hopelessly overdue :(
By Basic Date 2010-06-10 20:41
Sorry to resurect this thread but it seemed better than starting a new one.

does drawLine(...) not work on the iphone? I think I did read somewhere that openGL ES doesn't have it, is that right?

Are there any other things that are not supported?
By jlnr (dev) Date 2010-06-12 03:01
drawLine and drawTriangle are hackishly mapped to drawQuad for now.

In the long term, drawLine should be replaced by some drawQuad solution anyway; GL_LINEs are horribly inconsistent across platforms and drivers :(
By jlnr (dev) Date 2010-06-12 03:38
On a completely unrelated note, the "Ruby in App Store" thing keeps being exciting: http://www.appleoutsider.com/2010/06/10/hello-lua/
By Basic Date 2010-06-12 07:58
hmmm, I reckon it will only be for big dev's like unity. could be wrong, and here's hoping.

The drawLine draws nothing for me, quads are more suitable for what I'm doing anyway.
Previous Next Up Topic Gosu / Gosu on iPad, iPhone & iPod Touch / Creating a Gosu/C++ iPhone game

Powered by mwForum 2.20.0 © 1999-2009 Markus Wichitill