iPhone development on Windows – A basic framework starter kit

Debug in VS, play test on the real HW

Debug in VS, play test on the real HW

UPDATE 11/3/2010: This humble project has blossomed into a full featured SDK for Win, OS X, iOS, Android, and WebOS – check it out at www.protonsdk.com

Well, I’ve mostly finished up some mysterious projects and am hoping to have more time to do random junk like post here.

One of the secret missions was an iPhone port of a popular PC 3D shooter.  The reason this went so smoothly is… I didn’t write it on a mac!

Why write iPhone stuff on a PC?

Two words:  Visual Studio.

I don’t really have anything (major) against Apple’s Xcode, but hey, I’m just more productive with the IDE I spent the last ten years with.

My handy-dandy Win/iPhone cross-platform development kit

I’ve had a few questions about my setup, so I’ve put together a basic framework showing how you can cleanly develop in a cross-platform way.

If you are writing a GL ES game, don’t need much in the way of the iPhone UI frameworks, and want to keep your code portable this can work out great.

Keep in mind you can basically use any C++ library out there on the iPhone with a little tweaking.

Here is the simplest GL ES project you can imagine, ready to run under VS and Xcode/iPhone – you just need to share the drive it resides on with your OSX box or vice-versa.

Download it here

Here is the Programmer Readme.txt it comes with:

** Seth’s basic framework for cross-platform iPhone development **

This barebones framework gets you started by:

* Processes multi-touch input using the MessageManager from both OSX/iPhone and Windows (there is no GUI or anything, so you can only see
it is even doing anything by watching the debug messages)
* Sets up GLES for direct, fast rendering
* Handles coordinate and GL rotation when the phone is rotated (or L and P on Windows)
* Same source runs on windows, OSX/iPhone, only a small amount of platform specific “glue” is used, and is isolated
* Clean separation between shared files and app-level files, shows the organization I usually use
* Because we link to the PowerVR emulator library, we can also handle PVR compressed textures, exactly like an iPhone does
* Some helpful batch files including in RTApp/scripts to handle some boring tasks

To run included windows .exe:  Double click RTApp/bin/winRTApp.exe

To compile on windows:  Open the RTApp/windows/RTApp.sln file with Visual Studio 2005 or newer.  You might have to set the “start in” directory to ../bin when running from VS.
To compile on iPhone or OSX: Use XCode to open the RTApp.xcodeproj file.

A requirement to run on windows is to install the PowerVR GLES1.1 emulation SDK.
http://www.imgtec.com/PowerVR/insider/sdkdownloads/#GLES1b

After installing, copy the contents of the PowerVR_EMU/Builds into shared/win/PowerVR.  (You will need to make that directory..)  After that, the windows version
should compile and run.  Alternatively, just tweak the VS project settings to use your PowerVR paths.

You should probably also locate the libgles_cm.dll and update the one I have in RTApp/bin with it as well.

For hassle free cross platform sound, I used FMOD (not in this starter kit).

34 thoughts on “iPhone development on Windows – A basic framework starter kit

  1. Andy

    I keep getting these errors. I have followed your steps completely. I have looked for the dir and file and they are not to be found.

    1>Compiling…
    1>main.cpp
    1>d:\imagination technologies\powervr sdk\ogles-1.1_windows_pcemulation_2.04.24.0765\builds\ogles\include\gles\egl.h(12) : fatal error C1083: Cannot open include file: ‘EGL/egl.h’: No such file or directory

    Any Help?

    Thanks
    Andy

  2. Seth Post author

    Andy: Yikes. It looks the powerVR guys stopped including EGL support in their latest version.

    No problem, just download these, and unzip them into the OGLES/Include/GLES directory (overwriting what is there) and you should be good to go.

  3. Andy

    THanks that helped.

    Now I am getting the following error.

    1>Linking…
    1>LINK : fatal error LNK1104: cannot open file ‘libgles_cm.lib’

    I have found the file. It is in the path. It is not read only. Any ideas?

  4. Seth Post author

    VS doesn’t look at the regular windows path, it must be a directory entered specifically for libraries in VS. I think it’s because you didn’t copy the powervr files into the places suggested in the readme that it can’t find it?

    The easiest way is probably just to add your dir to the library paths though.

    To do that:

    In VC, right click the winRTApp in the solution explorer and choose properties.

    Then, click on “Linker” in the properties tree. In the right pain, add the .lib directory to the “Additional Library Directories” parameter.

    The path you should add is:

    d:\imagination technologies\powervr sdk\ogles-1.1_windows_pcemulation_2.04.24.0765\builds\OGLES\WindowsPC\Lib

    Good luck!

  5. James

    I use the same setup, and for the same reason. I tried forcing myself to use XCode exclusively for a few months, but my fingers just never got as happy with the keyboard shortcuts as they are in VS.

  6. hiddenLurc

    First: Thank you for this great thing. I followed your steps and the project does compile without errors. But trying to run the exe the following exception apprears:
    First-chance exception at 0x698460a7 in winRTApp.exe: 0xC0000005: Access violation reading location 0x00000000.

  7. virus2566

    I have to thank you for find and hard work. I have been looking for a solution like this for a while. Compiles and runs like a champ!

  8. Jeff

    Awesome, I’ve been looking for just this since, oh, June ’08ish :).

    I’m hitting the same issue as hiddenLurc above – you’ve gotten us 95% closer to being able to play around with iPhone dev, and while it’s not your job to do tech support on our computers, I’m hoping you can get us that final 5% there ;-).

    I’m not sure if this helps, but a debug dump shows that the OpenGL ES emulation is getting loaded, and the line that it’s dying on is the call to glDrawArrays(GL_TRIANGLES, 0, 3) [in RenderUtils.cpp, line 42]

    Here’s the VS debug dump:
    ‘winRTApp.exe’: Loaded ‘C:\Users\jeffsim\Desktop\iPhone\RTApp\bin\winRTApp.exe’, Symbols loaded.
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\ntdll.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\kernel32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Users\jeffsim\Desktop\iPhone\RTApp\bin\libgles_cm.dll’, Binary was not built with debug information.
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\user32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\gdi32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\advapi32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\rpcrt4.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\dbghelp.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\msvcrt.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\shimeng.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\apphelp.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\AppPatch\AcLayers.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\shell32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\shlwapi.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\ole32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\oleaut32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\userenv.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\secur32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\winspool.drv’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\mpr.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\imm32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\msctf.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\lpk.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\usp10.dll’
    OGLESPCViewer Version 2, 15/04/05

    OpenGL ES desktop PC emulation viewer for MBX IP cores
    Copyright Imagination Technologies Ltd 2004-2005.

    Reading oglespcviewer.cfg file…
    Using profile: PowerVR MBX1 With VGP – GENERIC PROFILE
    ‘winRTApp.exe’: Loaded ‘C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.16497_none_5cc0004408832c27\comctl32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\uxtheme.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Program Files\MMTaskbar\shellhook.dll’, Binary was not built with debug information.
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\opengl32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\glu32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\ddraw.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\dciman32.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\setupapi.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\dwmapi.dll’
    ‘winRTApp.exe’: Loaded ‘C:\Windows\System32\nvoglv32.dll’
    The thread ‘Win32 Thread’ (0x16c8) has exited with code 0 (0x0).
    The thread ‘Win32 Thread’ (0x15a8) has exited with code 0 (0x0).
    The thread ‘Win32 Thread’ (0x1570) has exited with code 0 (0x0).
    Save path is
    First-chance exception at 0x696832e0 in winRTApp.exe: 0xC0000005: Access violation reading location 0x00000000.
    Unhandled exception at 0x696832e0 in winRTApp.exe: 0xC0000005: Access violation reading location 0x00000000.

    Again – thanks for posting your solution!

  9. Seth Post author

    Hey guys.. hmm… how about this, if you take the original .zip and run the included .exe version (without re-compiling), does it work ok?

    If this crashes, it might be a bug in PowerVR emulator stuff or incompatibility with your graphics card. (Newer nvidia/ATI cards work best maybe?)

    If that DOES work, might want to make sure you update the .dll in the .exe’s dir to the latest one that came with the SDK. (So the .lib and .dll doesn’t mismatch…)

  10. Jeff

    It crashes when I run the included exe as well (doesn’t give any debug/stack info though).

    The machine has an NVIDIA GTX280 in it, updated drivers. Vista 32, SP2.

    Interestingly, I ran it on a fresh Vista 64bit box (ATI 4850, SP2), and both precompiled exe & VS compiled exe run (yay!) :-). Can’t think of anything dramatically different between the machines other than graphics cards…

    At any rate, I’m good to go (although my productivity is about to drop dramatically) – happy to provide any other config details if anyone else hits the same issue…

    Cheers (and thanks again!)
    Jeff

  11. Pingback: On Games and Code

  12. Andrew

    LORD would be really awesome on iPhone. I imagine it working somewhat similarly to Kingdoms Live

  13. atilim

    First of all, thank you for such a great framework. 🙂

    If your application crashes, try to put
    glDisableClientState(GL_NORMAL_ARRAY);
    before rendering the triangle. I hope it helps.


    atilim

  14. AlaskaJohn

    Thanks atilim!

    First tried running RTApp.exe as distributed and it crashed.
    Tried a different machine with better graphics card, and it crashed.
    Then compiled code, which also crashed on rendering triangles.

    Added “glDisableClientState(GL_NORMAL_ARRAY);” as suggested above, and it runs great.

    Another tool people may find useful for PC development of macs is RealVNC Viewer on the PC connected to Vine VNC Server on the mac. So far, we have tried it with two concurrent sessions logged into a single mac mini and it all worked surprisingly well.
    VineVNC Server at http://www.testplant.com/multidesktop.html
    (Their link for the PC viewer does not work, but you can find it on the RealVNC site at http://www.realvnc.com/ )

    -John

  15. Jason

    I’m interested in developing apps for the iPhone. I don’t have a Mac, but a Windows machine running Visa. Can I use this setup to develop apps and sell them on Apple’s Store? If not, what is the “cheapest” configuration of a Mac (new or used) that I will need to get?

    Thanks
    Jason
    jason.wu001@yahoo.com

  16. Seth Post author

    Jason – Yep, you still need to pick up an intel based Mac to make the final builds to test on a real iDevice (a must) and to package the final distribution in the App Store.

    I bought a $600 Mac-Mini, upgraded the ram to 1 GB and it works ok. Little slow.

  17. hugh

    Hi Seth,
    It’s awesome! If I want to control the sound devices of an iPhone, such as microphone and speaker, I assume I can’t use the framework you provided here. Right? What about managing files?
    Best regards,
    Hugh

  18. Seth Post author

    Hugh – this framework has no sound stuff and not much file handling, it’s very basic, just meant to get ya started.

  19. Klank

    Sorry, haven’t looked at the code yet, but allow me one quick question. Does it need to be C++ or could we use C# to program for the iphone with your framework?

  20. Seth Post author

    Klank – No, you have to use C/C++ with this framework. Really, it’s just an example to show how you don’t have to use Obj-C (minus some glue code on the mac side) and can test your stuff on Windows.

  21. William Prince

    Seth,

    Your code looks incredible and I can’t wait to get it working, but I hit a little snag. The code compiles fine, but I get a weird run time error. I saved a screenshot of it, and you can see it here:

    http://i434.photobucket.com/albums/qq63/johngottiv2/Work/debug_error.jpg

    I am working with VC++ 2008 Express, if that makes any difference. I am thinking it has something to do with my overall linker options, but I’m not sure. I think all the PowerVR stuff is included correctly though, since there are no compile errors. Thanks in advance!

    -William

  22. Seth Post author

    William – hrm, really not sure on that one. Like you said, maybe linker options. Or maybe the .lib and .dll of the PowerVR files are different versions? Might want to make sure you don’t see two versions anywhere.

  23. Anthony

    I can’t seem to download anything from the powerVR site. I get

    Microsoft JET Database Engine error ‘80040e10’

    No value given for one or more required parameters.

    /powervr/insider/powervr-login.asp, line 52

    which I am pretty confident is an issue on there side, is there naywhere else I can download what I need to make this work?

  24. Etek

    Hello,
    Managed to get your project to work under windows. Got rid of all the issues by rewriting all libs and dlls from the project with the ones from the PowerVR installation.
    My problem is under Xcode. I’m using iOS 4 right now and I get this base sdk is missing. Even if I change the Base SDK to all configurations to Iphone Device Iphone 4, the drop down bar still says Base sdk is missing. Any idea? I did the same with all my older projects and had no problems.

    Thank you so much for this.

  25. Seth Post author

    The rule of thumb is always change the base SDK to the latest version – (if you need to target OS 2.2.1 or such, then that should be set under “Deployment target”.

    But you tried this. Hmm. There are actually TWO places where you can set this – in that project I might have set both, and the second one is overriding the first one.

    Clicking the main project root under “Groups and files” is the first place – clicking the project name under “targets” is the second place, check both of those locations.

    What I usually do new is hit delete on any generic settings under “target”, so the main settings will be used instead.

  26. Ken

    I followed all the steps and it compiled and linked just fine, but get an exception in main.cpp at line 196:

    eglDisplay = eglGetDisplay((NativeDisplayType) hDC);

    Microsoft C++ exception: std::runtime_error at memory location 0x0018fa80

    I am running on a Windows 7 machine, so perhaps that is the problem? Anyone run into this problem and if so, do you have a solution?

  27. etek

    Hello,

    I’m using someone’s gluLookAt since it’s missing from OpenGL ES and it works flawlessly in portrait mode with your code. Things go weird when forcing landscape mode, what I’m looking at, doesn’t appear in the middle of the screen, but to the right.
    What are you using instead of gluLookAt? Or do you know hot to make it work in landscape?

  28. Nate

    do i write the code in C++?(i think so but im not sure)
    and i cant find axact instructions on how to use this or to download visual studio
    please help

Leave a Reply

Your email address will not be published. Required fields are marked *