Newbie Inquiries

Apprentice
Posts: 12
Joined: 2009.12
Post: #1
Hey everyone, I'm Doobfoo. I stumbled upon this forum and have found something great!

Some brief information about myself. I have been a freelance web designer for the past few years. I have worked with the following; xhtml, css, php, mysql, sql, actionscript, javascript.

I am highly interested in game development. As far as my setup goes, I run two Intel Macs. I do however, use Windows XP.

The past few days I have been researching on my options for going down this path. I would like to create games for the OS X, and Windows eventually. I am confused with a few things on the Macintosh side, though.

If I am to create a game on OS X, am I to use Objective-C/C++? Or solely C++? Is Objective-C/C++ only for regular application development on the OS X platform?

I am also interested in developing games for the iPhone. The iPhone then only uses Objective-C and Cocoa with OpenGL support?

Do I need to learn two different languages if I want to develop for OS X/Windows and the iPhone?

Regards.
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #2
You can use SDL for a cross-platform "windowing" library to set up you game environment on Windows, OS X, Linux, and I believe iPhone too.

Mainly, the language(s) you'll use primarily for game programming will be C/C++. In addition, on the iPhone, unless SDL covers everything, you'll only need to learn a very small amount of Objective-C. OpenGL will be what you'll use for graphics.

If you're planning on doing 3D games primarily, I would very highly recommend you look into using Unity3D.
Quote this message in a reply
Member
Posts: 21
Joined: 2009.12
Post: #3
I've actually replicated some of the core SDL functionality on my own --Partially for the learning experience (I was completely new to Objective-C/ Cocoa), and partially because I have eventual plans of making an event-driven 3D application (non game) with an emphasis on platform-specific user interfaces. In other words, I want this to look and behave like a "Mac" app to Mac users, and a "Windows" app to windows users. As far as I know, I could've used SDL to help achieve this goal; however, I didn't need that much from SDL, and like I said, recreating the needed functionality has been a good learning experience.

However, my most immediate goal is to make a Mac game, and hopefully make a buck in the process. And for this, my duplicated efforts have been largely pointless, and at times, frustrating. Implementing a C wrapper library around a heavily object-oriented API is not without its challenges. In fact, it's been significantly more challenging than implementing the same C interface in WIN32 (and even Carbon, for that matter). However, I will say this: Apple's pure object-oriented approach with Cocoa makes a lot of sense for developing event-driven applications. Though my experience has largely been aimed at short-circuiting Apple's design, I've also come to appreciate what they've provided --It's quite unlike anything I've ever used before. Now, if they'd only adopt C# syntax, then it'd be perfect Wink

Like AJ said, you're certainly free to use C/C++. There's multiple ways of doing this, but my preference is to wrap any Cocoa stuff I need in C. To do this, I make three files: a standard C header file, an Objective-C++ header file, and an Objective-C++ "mm" file for the implementation. I hope this example will clarify (forgive me if it's not syntactically correct, I just took a small snippet from my Input code):

"GameInput.h"
Code:
/* INTERFACE FILE : MUST NOT INCLUDE PLATFORM-SPECIFIC CODE */

#ifndef  __GAME_INPUT__
#define  __GAME_INPUT__

// Don't include anything that depends on Cocoa, here.
#include <stdint.h>

// **********************************************************
// GAME_KEY enum
// Each GAME_KEY will be processed as an actual, physical key on
// the keyboard --Irrespective of case, regional layout, or
// modifier combination.
// **********************************************************
enum GAME_KEY {
    GAME_KEY_A,  GAME_KEY_B,  GAME_KEY_C
};

// ----------------------------------------------------------
// IsGameKeyPressed
// Returns the most recently recorded state of the key.
// ----------------------------------------------------------
bool IsGameKeyPressed(GAME_KEY key);

#endif

"GameInputApple.h"
Code:
#ifdef __APPLE__

#ifndef __GAME_INPUT_APPLE__
#define __GAME_INPUT_APPLE__

#include "GameInput.h"
#include <Cocoa/Cocoa.h> //Now, I include Cocoa.

// ----------------------------------------------------------
// MyApplicationMain Class
// Used to process events
// ----------------------------------------------------------
@interface MyApplication : NSApplication {}
- (void)sendEvent:(NSEvent *)anEvent;
@end

#endif // __GAME_INPUT_APPLE__
#endif // __APPLE__

"GameInputApple.mm"
Code:
#ifdef __APPLE__

#include "GameInputApple.h"

namespace GameInput {
    // ----------------------------------------------------------
    // Setup AppleKeyMap
    // ----------------------------------------------------------
    void SetupAppleKeyMap() {
        AppleKeyMap[GAME_KEY_A] = 0;
        AppleKeyMap[GAME_KEY_B] = 11;
        AppleKeyMap[GAME_KEY_C] = 8;
       }
}

@implementation MyApplication

- (void)sendEvent:(NSEvent *)anEvent {
    
    NSEventType type = [anEvent type];
    
    switch (type) {
        case NSKeyUp:
            gKeyState[[anEvent keyCode]] = false;
            break;            
        case NSKeyDown:
            gKeyState[[anEvent keyCode]] = true;
            break;
        default:
            break;
    }
}
@end

// ----------------------------------------------------------
// IsKeyboardKeyPressed
// Returns the most recently recorded state of the key.
// ----------------------------------------------------------
bool IsGameKeyPressed(GAME_KEY key) {
    return gKeyState[AppleKeyMap[key]];
}

#endif // __APPLE__
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #4
Yeah, there's nothing wrong with writing your own stuff instead of using SDL, but it takes time to learn to deal with the little issues that pop up. It's a little easier now in Leopard. One notable feature that will cause pain and grief will be implementing HID support for joystick input, which SDL conveniently handles for you.
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2009.12
Post: #5
Thanks for the awesome posts guys. So I should start like this.

Learn C++, I have the book C++ Primer. Learn OpenGL and SDL + Unity3D. I have access to Luxology Modo and 3ds Max for modeling.

If I want to learn how to create normal applications for the OS X platform/iPhone then Objective-C/Cocoa is the way to go then.
Quote this message in a reply
Member
Posts: 21
Joined: 2009.12
Post: #6
Yes, I've heard nothing but scary stuff about HID... I'm hoping Pangea's book will guide me through the rough waters. It's an outstanding book, and completely free (very Carbon-centric, tho). The company's legacy stretches back well into the "Classic" era, so this is understandable.
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2009.12
Post: #7
I've been reading that you can use C++ for normal applications as the core language, then Objective-C++ for the GUI implementation of Cocoa. What are your thoughts on this vs regular Objective-C/Cocoa?
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #8
Doobfoo Wrote:Learn C++, I have the book C++ Primer. Learn OpenGL and SDL + Unity3D.
If you're going to do Unity3D then there's no need to learn C++ or OpenGL or SDL, since it's a full-fledged game engine all on its own. For Unity you'll need to learn C#.

Doobfoo Wrote:If I want to learn how to create normal applications for the OS X platform/iPhone then Objective-C/Cocoa is the way to go then.
That is correct.

Mister T Wrote:Yes, I've heard nothing but scary stuff about HID... I'm hoping Pangea's book will guide me through the rough waters. It's an outstanding book, and completely free (very Carbon-centric, tho). The company's legacy stretches back well into the "Classic" era, so this is understandable.
It's a good book. I bought it back when it came out (before it was free). I used it to initially figure out HID. Unfortunately, as you mentioned, the book is old now and only uses Carbon. There are newer HID APIs in Leopard which are a bit different. There's no easy way of dealing with HID, other than SDL I suppose. There is also ddhidlib, but I've heard there may be some issues with Leopard compatibility so YMMV.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
Mister T Wrote:Yes, I've heard nothing but scary stuff about HID... I'm hoping Pangea's book will guide me through the rough waters. It's an outstanding book, and completely free (very Carbon-centric, tho). The company's legacy stretches back well into the "Classic" era, so this is understandable.

The Pangea book covers the old, deprecated HID API.
Quote this message in a reply
Member
Posts: 21
Joined: 2009.12
Post: #10
I see, so HID is different, now... Bummer.
Quote this message in a reply
Member
Posts: 254
Joined: 2005.10
Post: #11
Mister T Wrote:I see, so HID is different, now... Bummer.

Better... or so they say. Sneaky
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2009.12
Post: #12
I decided to narrow my interests down to the iPhone. I'm currently reading Programming in Objective-C 2.0 by Stephen G. Kochan. Once I familiarize myself with this I assume it is best for me to move onto C++ and OpenGL. Do all iPhone games utilize OpenGL?
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #13
Doobfoo Wrote:... I assume it is best for me to move onto C++ and OpenGL. ...
I prefer C, but the choice is yours.

Doobfoo Wrote:Do all iPhone games utilize OpenGL?
Pretty much, yes.
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2009.12
Post: #14
AnotherJake Wrote:I prefer C, but the choice is yours.


Pretty much, yes.


Thank you for your time and advice AnotherJake. I will keep you all updated with my progress!
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #15
Doobfoo Wrote:I decided to narrow my interests down to the iPhone. I'm currently reading Programming in Objective-C 2.0 by Stephen G. Kochan. Once I familiarize myself with this I assume it is best for me to move onto C++ and OpenGL. Do all iPhone games utilize OpenGL?

If you've already learned Objective-C, and are deploying exclusively to the iPhone, then I see little reason to bother with C++.

Short of a hidden std::makeDukeNukemForever part of the STL, I don't think that the additional pains of C++ will really be worth your while.

Objective-C and C++ use entirely different patterns for constructing systems and intermingling the two will be difficult at best. Objective-C, on the other hand, is a light layer on top of C. Intermingling Objective-C and C is easier (though still quite difficult if you're not on top of your game).

You could use CoreAnimation for your game, but I would highly suggest going with OpenGL, as CoreAnimation's uses are quite limited. You can do a lot of interesting things with CoreAnimation, but when you hit the ceiling of what it's designed to do, you usually hit that ceiling very hard.

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Post Reply