Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
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 2011-11-09 22:42
Revised:

• check out Gosu from git
• create new OpenGL ES project
• set up signing stuff as usual
• get rid of main.m and the .nib file; also of the prefix header & its settings if you want
• 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; }

Then follow this explanation, just instead of ˚CorePlot.xcodeproj use GosuTouch.xcodeproj`:

http://code.google.com/p/core-plot/wiki/UsingCorePlotInApplications

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.
Parent - By jlnr (dev) Date 2012-03-05 11:19
This is what the result should look like.
Parent - By jlnr (dev) Date 2012-03-05 11:22 Edited 2013-07-08 00:12
Current version numbers: I use Xcode 4.2/4.3, LLVM 3.x compiler, current iOS SDK but Gosu works with OS Deployment Version down to 3.0 (*all* iOS devices ever shipped).
- 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-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.
- - By jontebol Date 2011-02-12 12:08
Ok I'm trying to increase the userbase of Gosu Touch by many percent here... by jumping on the wagon...

I've followed all of the steps above, and gotten so far as getting the simulator up in debug mode. However... I must be missing something vital, because when the simulator starts my app, it just quits it again immediately... Basically, nothing happens... Xcode just tells me "Debugging terminated" without throwing any errors or anything like that... It's almost as if I'm missing a game loop or something, as if the program just finishes running, but Gosu::Window should take care of that for me, right?

I'm using the most recent version of the SDK...

I'm practically a complete noob with both XCode, C++ and Iphone dev... I managed to create a small game demo in Objective-C and cocos2d for iphone earlier (like 2 years ago), but since I'm working on a game in Gosu now (in Ruby, currently), I'd love to be able to get it running...

One thing I was unsure of was what to do with Gosu Touch once I'd built it... Does it matter where it lies? I mean, when I built it, it seems to have ended up in a folder called "build" in the source folder of Gosu. I haven't entered that search path anywhere in my xcode project, so how could it matter that I built it? I've just entered the header search path and lib path... Could this be related to my problems? I mean, doesn't the build need to be included in my project somehow?

Anyways, any help would be greatly appreciated. It would be totally awesome to use Gosu on the IPhone, even if it means I have to learn C++ (which doesn't seem all that daunting actually)...
Parent - - By jlnr (dev) Date 2011-02-13 06:54
Welcome aboard! ;)

> One thing I was unsure of was what to do with Gosu Touch once I'd built it


It should be in <gosuroot>/lib, but it doesn't really matter as long as you adjust the following step:

>>• 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


But a missing Gosu library should actually lead to linker errors on build... Can you see the runtime error in the console window (cmd+shift+R)?
Parent - - By jontebol Date 2011-02-13 12:48
Thanx! :)

Gee... I'd forgotten about that window. I knew there was important runtime information somewhere... :) Turns out, I just had to delete the reference to the MainWindow-xib file from the plist file in order to get it working. I now have a working Gosu Touch project! Wohoo! Totally awesome actually... :)

I noticed however that changing the screen size doesn't seem to have any effect whatsoever. I have an IPhone 4 so I'd like to use a resolution of 960x640 but it doesn't seem to want to do that... Any tips?

Btw, what's the best way of adding resources to the project? I've tried with a png image and got it working just by putting it in the resources folder in XCode... Is that the way to go generally?

Thanks for your help, it's greatly appreciated! And as always... for the lib itself... :)
Parent - By jlnr (dev) Date 2011-02-13 18:54
Hmmm. You can just call "graphics().setResolution(960, 640)", but I think this should be the default maybe. But you can rest assured that if you draw something at 0.5, 0.5, this will actually be @ 1, 1 on the iPhone 4. I think this is what Apple is doing with UIKit too.
Parent - - By jontebol Date 2011-02-15 22:24
Ok, so it seems I must have done some step wrong, because I can't get it to compile for the device (my Iphone 4)...

These are the errors I get:

Build gosutouchtest of project gosutouchtest with configuration Debug

Ld build/gosutouchtest.build/Debug-iphoneos/gosutouchtest.build/Objects-normal/armv6/gosutouchtest normal armv6
cd /Users/jonte/dev/iosapps/gosutouchtest
setenv IPHONEOS_DEPLOYMENT_TARGET 4.2
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -L/Users/jonte/dev/iosapps/gosutouchtest/build/Debug-iphoneos -L/Users/jonte/dev/games/gosu-source/lib -F/Users/jonte/dev/iosapps/gosutouchtest/build/Debug-iphoneos -filelist /Users/jonte/dev/iosapps/gosutouchtest/build/gosutouchtest.build/Debug-iphoneos/gosutouchtest.build/Objects-normal/armv6/gosutouchtest.LinkFileList -dead_strip -lgosutouch-sim -miphoneos-version-min=4.2 -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -framework CoreGraphics -framework OpenAL -framework AudioToolbox -framework AVFoundation -o /Users/jonte/dev/iosapps/gosutouchtest/build/gosutouchtest.build/Debug-iphoneos/gosutouchtest.build/Objects-normal/armv6/gosutouchtest

ld: warning: in /Users/jonte/dev/games/gosu-source/lib/libgosutouch-sim.a, file was built for unsupported file format which is not the architecture being linked (armv6)
Undefined symbols:
  "_main", referenced from:
      start in crt1.3.1.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Ld build/gosutouchtest.build/Debug-iphoneos/gosutouchtest.build/Objects-normal/armv7/gosutouchtest normal armv7
cd /Users/jonte/dev/iosapps/gosutouchtest
setenv IPHONEOS_DEPLOYMENT_TARGET 4.2
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -L/Users/jonte/dev/iosapps/gosutouchtest/build/Debug-iphoneos -L/Users/jonte/dev/games/gosu-source/lib -F/Users/jonte/dev/iosapps/gosutouchtest/build/Debug-iphoneos -filelist /Users/jonte/dev/iosapps/gosutouchtest/build/gosutouchtest.build/Debug-iphoneos/gosutouchtest.build/Objects-normal/armv7/gosutouchtest.LinkFileList -dead_strip -lgosutouch-sim -miphoneos-version-min=4.2 -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -framework CoreGraphics -framework OpenAL -framework AudioToolbox -framework AVFoundation -o /Users/jonte/dev/iosapps/gosutouchtest/build/gosutouchtest.build/Debug-iphoneos/gosutouchtest.build/Objects-normal/armv7/gosutouchtest

ld: warning: in /Users/jonte/dev/games/gosu-source/lib/libgosutouch-sim.a, file was built for unsupported file format which is not the architecture being linked (armv7)
Undefined symbols:
  "_main", referenced from:
      start in crt1.3.1.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Parent - By jlnr (dev) Date 2011-02-16 00:07
Oh, is the default for iOS projects to compile for armv6 and armv7 now? I think I only compile my game (and Gosu) for armv6. You can probably either fix it by compiling Gosu for both platforms, or your game for armv6. (Target options, architectures)
Up Topic Gosu / Gosu on iPad, iPhone & iPod Touch / Creating a Gosu/C++ iPhone game

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill