iDevGames Forums
Cross Platform using C and Opengl - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Programming Languages & Scripting (/forum-8.html)
+--- Thread: Cross Platform using C and Opengl (/thread-9688.html)



Cross Platform using C and Opengl - matt_new_york - Jan 6, 2012 01:23 PM

I'd like to hear some thoughts about cross platform programming. I want to run programs on Android, iPad, iPhone, Mac, and yes, Windows. I need intense hardware accelerated graphics, so I use Opengl and C. I have found that code to be portable to everything and I use a wrapper for each platform. The wrapper is needed only to give me an opengl window, internet access ala geturl or equivalent, and of course, user touches. GUI is also entirely in Opengl since I don't want to recreate a different GUI for every platform.

Anyone have a better idea for cross platform? ( I am ducking now... ) Rasp


RE: Cross Platform using C and Opengl - bronxbomber92 - Jan 6, 2012 03:23 PM

You described generically what I believe most developers do.

Another option to consider is using a 3rd party software stack that does all of the abstraction for you. A popular example of this is Unity (which can build applications for all of the platforms you mentioned).


RE: Cross Platform using C and Opengl - ThemsAllTook - Jan 6, 2012 05:48 PM

What you describe is exactly what I do, and I'm quite happy with it. In case you want to use any of my stuff for reference, it's all open source: http://libstem.org/


RE: Cross Platform using C and Opengl - GolfHacker - Jan 12, 2012 10:31 PM

Ditto. Except that I'll add that I use SDL for audio, input, etc. SDL and auxiliary libs like SDL_mixer provide a great cross-platform solution for non-graphics parts of my games. Also, some of my games use OpenGL for graphics and some use the SDL graphics capability.

SDL 1.3 supports iPad, iPhone, and Android. I'm still using SDL 1.2.14, but I plan to port my custom game engine to SDL 1.3 later this year when I port one of my games over to IOS for the first time. You'll find SDL 1.3 over at the Galaxy Gameworks site: http://www.galaxygameworks.com/products.html


RE: Cross Platform using C and Opengl - JustinFic - Jan 13, 2012 01:57 PM

This is essentially what I use as well: SDL for application level stuff, SDL_mixer for sound, SDL_image for texture loading, OpenGL for graphics, written in C++. It's worked phenomenally for me, and I've been using this combo since 2004.

(Jan 12, 2012 10:31 PM)GolfHacker Wrote:  You'll find SDL 1.3 over at the Galaxy Gameworks site: http://www.galaxygameworks.com/products.html

OMG. You just made my day. How did I never see that site? I know it's pre-release but I want to work 1.3 into my engine asap.


RE: Cross Platform using C and Opengl - Skorche - Jan 13, 2012 02:28 PM

Do people really still use SDL_image for texture loading? In my experience getting SDL to load textures correctly so that it supports more than just formats that SDL decides to decompress directly to 32bit RGBA is a real PITA. Certainly more so than using libPNG and libJPEG directly, and certainly a lot slower if you load a lot of large textures.

The libPNG bundled is probably pretty ancient, but this will load palleted or grayscale PNGs with no trouble, will load them correctly for OpenGL (SDL_image makes them upside down), and can easily be changed to load alpha or luminance textures:
http://files.slembcke.net/misc/PNGTexture.tar.gz


RE: Cross Platform using C and Opengl - JustinFic - Jan 13, 2012 08:31 PM

(Jan 13, 2012 02:28 PM)Skorche Wrote:  Do people really still use SDL_image for texture loading? In my experience getting SDL to load textures correctly so that it supports more than just formats that SDL decides to decompress directly to 32bit RGBA is a real PITA.

I've actually never had a problem with it. I don't do anything crazy with it, just use the one line call to load pngs and jpegs. But it's never misbehaved on me.


RE: Cross Platform using C and Opengl - GolfHacker - Jan 14, 2012 11:08 PM

(Jan 13, 2012 01:57 PM)JustinFic Wrote:  OMG. You just made my day. How did I never see that site? I know it's pre-release but I want to work 1.3 into my engine asap.

Heh! You're welcome!
I use FreeImage to load the various graphic file formats for my game. It's nice to be able to load any image format with the same small block of code (versus dealing with all the individual libraries for the various file formats), and the performance is decent.