(Mac) games without Cocoa!?

Member
Posts: 60
Joined: 2013.03
Post: #1
Hello all. I have been plugging away at Objective-C, and although it is a slow process I have been enjoying it. Now that I am getting more and more excited to actually make games, I have been thinking about portability, and was thinking about eventually learning C++. My question does not have to do with C++, but I was wondering if it is possible to make a Mac game or application that uses no Cocoa (and thus, not Obj-C) at all? For instance, using C++ to make an entire game on the Mac be easily ported to PC.

The only reason I am wondering is because I would like to have games on Mac and PC, and not have to completely rewrite the game from Cocoa...

Thanks!
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #2
Yep, definitely doable. One popular way is by using SDL.
Quote this message in a reply
Member
Posts: 60
Joined: 2013.03
Post: #3
Ooh, thanks. Going to read that now. Smile

I will edit this post if I have a question about it, which I probably will!

Edit: Oh, and here's a question already! Basically, the way that would work, is you use C++ and SDL, and you can make games that work on Windows and MacOSX 100% independent of Cocoa and Objective-C? Cool, if so!
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #4
Quote:Basically, the way that would work, is you use C++ and SDL, and you can make games that work on Windows and MacOSX 100% independent of Cocoa and Objective-C?

Right, no Cocoa/Obj-C needed. There are tons of games which are cross-platform compatible between Windows/Linux/OS X that are made using SDL and a pure C/C++ game code base.
Quote this message in a reply
Member
Posts: 60
Joined: 2013.03
Post: #5
(Jun 23, 2013 04:02 PM)AnotherJake Wrote:  
Quote:Basically, the way that would work, is you use C++ and SDL, and you can make games that work on Windows and MacOSX 100% independent of Cocoa and Objective-C?

Right, no Cocoa/Obj-C needed. There are tons of games which are cross-platform compatible between Windows/Linux/OS X that are made using SDL and a pure C/C++ game code base.


Awesome!! That is great! Thanks so much.
Basically, building a window is more from scratch using graphics such as OpenGL, I would assume?


Edit: Alright. Tiny bit confused (I am a complete beginner, after all!)::

1. Is SDL basically taking the place of Cocoa - being a library...?

2. If you use SDL and C++ on a Mac to make games for Mac and PC, you are still coding in normal C++, so I could learn from just a generic "C++" book, correct?

3. SDL does not have to be installed on the player's (of the game made using SDL and C++) computer does it?

Basically, what is SDL and how does it work? Rasp

Thanks! Grin
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #6
Quote:1. Is SDL basically taking the place of Cocoa - being a library...?

I suppose you could look at it like that. On the Mac, SDL actually uses Cocoa behind the scenes to create the window and interact with various OS services to gather input and hook up sound, etc. You use OpenGL in that window for your graphics. On other platforms it uses the local system libraries to do the same things. What you are presented with is an API that more or less works the same on all platforms that it supports, so you don't need to know how to manage those nitty gritty details for each platform.

Quote:3. SDL does not have to be installed on the player's (of the game made using SDL and C++) computer does it?

One way or another the SDL library has to be present on the player's computer. On the Mac you would include it inside the application's bundle so that the player wouldn't have to install it themselves.

Quote:2. If you use SDL and C++ on a Mac to make games for Mac and PC, you are still coding in normal C++, so I could learn from just a generic "C++" book, correct?

Yes. However, I should point out that you need to know C before you can learn C++. C++ is powerful, but that comes at the expense of complication. It is definitely not for beginners.
Quote this message in a reply
Member
Posts: 60
Joined: 2013.03
Post: #7
(Jun 24, 2013 06:42 AM)AnotherJake Wrote:  
Quote:1. Is SDL basically taking the place of Cocoa - being a library...?

I suppose you could look at it like that. On the Mac, SDL actually uses Cocoa behind the scenes to create the window and interact with various OS services to gather input and hook up sound, etc. You use OpenGL in that window for your graphics. On other platforms it uses the local system libraries to do the same things. What you are presented with is an API that more or less works the same on all platforms that it supports, so you don't need to know how to manage those nitty gritty details for each platform.

Quote:3. SDL does not have to be installed on the player's (of the game made using SDL and C++) computer does it?

One way or another the SDL library has to be present on the player's computer. On the Mac you would include it inside the application's bundle so that the player wouldn't have to install it themselves.

Quote:2. If you use SDL and C++ on a Mac to make games for Mac and PC, you are still coding in normal C++, so I could learn from just a generic "C++" book, correct?

Yes. However, I should point out that you need to know C before you can learn C++. C++ is powerful, but that comes at the expense of complication. It is definitely not for beginners.

Thank you!

Hmm... Simply because I would like to learn a language that I can use and not have to learn to simply learn another, is Java a viable option for making cross platform games on the Mac? I am coming from a few months experience with Obj-C but want to try something else because of the little amount of resources available, and not being cross platform.

Thanks again for all the help.

edit: I see many threads with people saying that C++ can be a great language to start with, depending on how you learn and want to learn, not simply because other languages can be easy after it, as they might not, but because you are in control and although it can be harder it can pay off... Thoughts? Rasp
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #8
(Jun 24, 2013 06:54 AM)Evan Stallings Wrote:  Hmm... Simply because I would like to learn a language that I can use and not have to learn to simply learn another, is Java a viable option for making cross platform games on the Mac? I am coming from a few months experience with Obj-C but want to try something else because of the little amount of resources available, and not being cross platform.

This is actually a tough question to answer in a broad sense. First, Java is a no-go IMHO.

I wish I had some great advice for you about what direction to take, but if you're determined to stick to a "bare-bones" cross-platform compatible language, your only two practical choices are C and C++. I and many other indies prefer C, while many others prefer C++. There are valid arguments for either.

Quote:I see many threads with people saying that C++ can be a great language to start with, depending on how you learn and want to learn, not simply because other languages can be easy after it, as they might not, but because you are in control and although it can be harder it can pay off... Thoughts?

I disagree that anyone should start directly with C++. You can read Bruce Eckel's "Thinking in C++", and the first thing he does is redirect you to learn C first, then come back -- and I agree with him. I suppose if you really want maximum punishment you might start directly with C++ somehow, but my observation has been that folks who choose that path start off by writing incomprehensible garbage, and often do not ever learn to write anything better than that.

But the choice, of course, is yours to make. If you think you can do it, then go for it.
Quote this message in a reply
Member
Posts: 60
Joined: 2013.03
Post: #9
(Jun 24, 2013 08:21 AM)AnotherJake Wrote:  
(Jun 24, 2013 06:54 AM)Evan Stallings Wrote:  Hmm... Simply because I would like to learn a language that I can use and not have to learn to simply learn another, is Java a viable option for making cross platform games on the Mac? I am coming from a few months experience with Obj-C but want to try something else because of the little amount of resources available, and not being cross platform.

This is actually a tough question to answer in a broad sense. First, Java is a no-go IMHO.

I wish I had some great advice for you about what direction to take, but if you're determined to stick to a "bare-bones" cross-platform compatible language, your only two practical choices are C and C++. I and many other indies prefer C, while many others prefer C++. There are valid arguments for either.

Quote:I see many threads with people saying that C++ can be a great language to start with, depending on how you learn and want to learn, not simply because other languages can be easy after it, as they might not, but because you are in control and although it can be harder it can pay off... Thoughts?

I disagree that anyone should start directly with C++. You can read Bruce Eckel's "Thinking in C++", and the first thing he does is redirect you to learn C first, then come back -- and I agree with him. I suppose if you really want maximum punishment you might start directly with C++ somehow, but my observation has been that folks who choose that path start off by writing incomprehensible garbage, and often do not ever learn to write anything better than that.

But the choice, of course, is yours to make. If you think you can do it, then go for it.

Huh. Ok. I'm a little stumped, as I do want to stick to "Bare-Bones Cross Compatible" and have no idea what to do. C# and Unity are looking more and more appealing, but I want to make games my way, not use a program such as Unity3d.

Is C itself a viable option for making cross platform games? You said you prefer it.

My choices seem to be:

1. C++ using QT - that would make it independent of any Obj-C/Cocoa and cross platform, correct?

2. C++ using SDL, which I still don't know much about or what "it uses Cocoa" means...

3. Java, which many say is good and many say is bad. I like the idea of it, but I dunno.

3. C# and Unity, which I am very hesitant to do because Unity is almost kind of a game-making program, right?

Thanks.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #10
(Jun 24, 2013 08:26 AM)Evan Stallings Wrote:  Huh. Ok. I'm a little stumped, as I do want to stick to "Bare-Bones Cross Compatible" and have no idea what to do.

In all honesty, even those of us who've been doing this for many years are stumped by this same topic quite frequently. Here's what I can tell you: Apple and Microsoft are the big dogs and they each want to lock you into their respective platforms by offering you support libraries that are hard to pass up. I got sucked into XNA on Windows/Xbox one time and almost stayed there. I got sucked into Cocoa/Obj-C on OS X/iOS and almost stayed there.

Quote:C# and Unity are looking more and more appealing, but I want to make games my way, not use a program such as Unity3d.

Nothing wrong with being the stubborn type and going it alone, as long as you understand what you're up against (i.e. a steep learning curve). There is pay-off in creating your own flexibility and avoiding engines/libraries, but the price is up-front development time, often measured in multiple years.

Quote:Is C itself a viable option for making cross platform games? You said you prefer it.

C is most definitely a viable option. Yes, I prefer C over C++, but that's mostly because I have written so much back-end support for myself in C over the years that I have no need for C++ third-party support libs like Boost, STL, etc. While the AAA game industry overwhelmingly prefers C++, indie game developers not so much. I would wildly estimate that with indies it is more like 50/50 C vs C++. C is an extremely powerful language. It's really just an abstraction layer for assembly language, so it's super fast. Some developers you may be familiar with who use or used C: Brian Greenstone (Pangea Software) uses C for all his games. John Carmack (id Software) used C for almost all of their games up until Doom 3 -- go download the Quake 3 source code, which is almost all C. Bungie used C for their games up until Halo. I would wildly guess that at least a third of the developers here at iDevGames use C and/or Objective-C; maybe another third use C++; and the final third use something else.

I have moved away from Cocoa/Objective-C except for windowing, input and native GUI stuff (the windowing and input could be replaced by SDL if I wanted to). My game code itself is now almost entirely cross-platform compatible C.

I don't honestly have a recommendation for either C or C++, except that I am against the idea of starting with C++, but that's just my opinion. I have many things I dislike about C++, but they generally involve other programmers' poor coding habits, not the language itself.

Quote:My choices seem to be: ...

Of those, I haven't used QT, so I wouldn't know anything about it. There are many third-party support frameworks/libraries for use with C++. You will undoubtedly find something that replaces what you'd normally use Cocoa for.

SDL using Cocoa underneath means that it calls Cocoa to create a window for you behind the scenes. You can effectively pretend that it has nothing to do with Cocoa from your point of view. On all platforms, you practically have to call an OS support library of some sort to create a window and gather user input from the keyboard and start up the sound card, etc. Therefore there will necessarily have to be at least *some* platform dependent code just to get the basic environment set up. That's what SDL is designed to do for you so you don't have to learn how to do the basics on each system. We sometimes call that the "windowing layer" or "OS layer" or "platform code". Your game sits on top of that and can be entirely C or C++.

Quote:Unity is almost kind of a game-making program, right?

Yes.
Quote this message in a reply
Member
Posts: 60
Joined: 2013.03
Post: #11
(Jun 24, 2013 09:17 AM)AnotherJake Wrote:  *snip*

What you said in the previous post, AnotherJake.

So basically, SDL is something that figures out what computer you are using, and makes the code for you to run on that specific computer. So for Mac, Cocoa, and so on? So you would have to tell people to go download SDL in order to play the game? ...Hmmmm.

I think what I am going to do is download Unity, play around with it, learn some basic C#, and hopefully make some for-fun games to get me excited and interested, then move to either C, C++ or Java.

What's your grudge against Java, anyway? Rasp

Thanks!

EDIT: Java looks extremely appealing due to its amazing level of portability... Does developing a Java game on Mac use any Cocoa? Apparently its "code once, run anywhere" which I like.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #12
(Jun 24, 2013 09:22 AM)Evan Stallings Wrote:  So basically, SDL is something that figures out what computer you are using, and makes the code for you to run on that specific computer.

Yes, more or less.

Quote:So you would have to tell people to go download SDL in order to play the game? ...Hmmmm.

No, you include it with the game. As I mentioned earlier, on the Mac you would simply include it in the app bundle. The player would have no need to know that SDL is there.

Quote:I think what I am going to do is download Unity, play around with it, learn some basic C#, and hopefully make some for-fun games to get me excited and interested, then move to either C, C++ or Java.

Sounds like a great plan. C# is an excellent language. Too bad there isn't more cross-platform support for it.

Quote:What's your grudge against Java, anyway? ... Apparently its "code once, run anywhere" which I like.

Yeah, that's how it's advertised. In reality it doesn't have the support it should have. There are lots of issues with Java, but in the end it just doesn't deliver what we expected. Do a search for "why java sucks".
Quote this message in a reply
Member
Posts: 60
Joined: 2013.03
Post: #13
(Jun 24, 2013 09:55 AM)AnotherJake Wrote:  
(Jun 24, 2013 09:22 AM)Evan Stallings Wrote:  So basically, SDL is something that figures out what computer you are using, and makes the code for you to run on that specific computer.

Yes, more or less.

Quote:So you would have to tell people to go download SDL in order to play the game? ...Hmmmm.

No, you include it with the game. As I mentioned earlier, on the Mac you would simply include it in the app bundle. The player would have no need to know that SDL is there.

Quote:I think what I am going to do is download Unity, play around with it, learn some basic C#, and hopefully make some for-fun games to get me excited and interested, then move to either C, C++ or Java.

Sounds like a great plan. C# is an excellent language. Too bad there isn't more cross-platform support for it.

Quote:What's your grudge against Java, anyway? ... Apparently its "code once, run anywhere" which I like.

Yeah, that's how it's advertised. In reality it doesn't have the support it should have. There are lots of issues with Java, but in the end it just doesn't deliver what we expected. Do a search for "why java sucks".

Darn. Something sounds perfect, and then it turns out not to be! When you say C# doesn't have cross-compatibility support you mean without Unity, correct? Because Unity makes it pretty simple. Rasp

Alright. I will play around with Unity for fun.

How does C work? Do you need some kind of SDL-like thing to make it cross compatible? C is procedural too, isn't that kind of a negative now-a-days?

Thanks again.
Quote this message in a reply
Moderator
Posts: 452
Joined: 2008.04
Post: #14
So I'm the resident Java guy around here, I guess. I wrote several of my own games in Java, most notably the ones I put in iDevGames contests. I used to recommend Java, but I don't anymore for a few reasons. Apple used to really push Java, but now they're really trying to kill it. The JVM isn't bundled with the OS anymore. Now that Oracle owns java, we've really seen the language stagnate.

Every platform you deploy to on Java will require some platform specific code and separate builds if you want the application bundled in a remotely native way. But that's true for just about everything... it's just not a magic bullet.

It sounds like you've got a good understanding of what SDL offers you. If you're okay writing your own OpenGL code, I'd also recommend GLFW instead of SDL. It also provides windowing and input, so you won't need Cocoa, but I think it's simpler than SDL.

With Unity, you'll have a very different game development experience than writing your own engine.

Howling Moon Software - CrayonBall for Mac and iPhone, Contract Game Dev Work
Quote this message in a reply
Member
Posts: 60
Joined: 2013.03
Post: #15
(Jun 24, 2013 10:18 AM)AndyKorth Wrote:  So I'm the resident Java guy around here, I guess. I wrote several of my own games in Java, most notably the ones I put in iDevGames contests. I used to recommend Java, but I don't anymore for a few reasons. Apple used to really push Java, but now they're really trying to kill it. The JVM isn't bundled with the OS anymore. Now that Oracle owns java, we've really seen the language stagnate.

Every platform you deploy to on Java will require some platform specific code and separate builds if you want the application bundled in a remotely native way. But that's true for just about everything... it's just not a magic bullet.

It sounds like you've got a good understanding of what SDL offers you. If you're okay writing your own OpenGL code, I'd also recommend GLFW instead of SDL. It also provides windowing and input, so you won't need Cocoa, but I think it's simpler than SDL.

With Unity, you'll have a very different game development experience than writing your own engine.

Thanks!

So it sounds that SDL or GLFW + C++ is the way to go? Ok. Ok... Rasp

I will play with Unity (I just forced myself to get it today) to get something on the screen that will encourage me, whilst slowly learning C++...

Thank you very much.

Edit: Wait, quick question. The way SDL and GLFW work, I assume, is that you make your game or app, with normal C++ code, and build it, and you can deploy it to any computer (Mac and PC) and it will automatically run if SDL was inside of what you distributed? How would you distribute it on PC to make sure it would work? Smile
Quote this message in a reply
Post Reply