cocos2d-x for Mac OS X ?

Big thanks to Nat Weiss.
The pull request is merged into cocos2d-x.
You can download and have a try.

This has issues on the Retina MBP. Mostly it works, but font rendering is garbled. If I coerce mine to run at native resolution (something Apple doesn’t even allow!), it works fine, but at any standard resolution it looks bad (See attached screenshot, that’s supposed to say Hello World, and also the framerate display)

I’m happy to help debug, and I’ve tried to a little bit, but I don’t know very much about, well, any of this :slight_smile:

Hmm. I’m baffled as to why it would not show up at all like that on retina modes, but show up when you change the resolution. I would think, if anything, it would just look blurry in retina mode. Unfortunately I don’t have a MBP and right now I wouldn’t even have a clue where to start debugging. I’ll have a look on the interwebs to see if I can find any known issues with Freetype and Retina displays. Hopefully this is something that already has a fix.

The only thing I really know about the Retina display is that if you set your resolution to 1920x1200 (the highest Apple approved resolution), then behind the scenes it’s actually rendering everything at twice that (3840x2400) and then downsizing it to the actual display resolution (2880x1800)

I stepped through some stuff looking for suspicious numbers related to those resolutions, but I don’t really know where to look, so not surprisingly, I didn’t find anything immediately obvious. Still, my guess is that there’s something somewhere that’s finding and using the wrong one of those resolutions.

I’ve found a thread here http://www.cocos2d-iphone.org/forum/topic/36096 relating to the iPhone version that claims to fix it. In fact, it looks like there are two fixes in there. It might be 2-3 weeks before I have time to get to it though. I’m behind schedule and trying to catch up as quickly as possible. But fixing this is crucial to finishing the project I’m behind on, so it will definitely become a priority at some point in the near future, if nobody else beats me to it.

There is a serious bug regarding cocos2dx support for OS X. If you look in to file TargetConditionals.h, you will see that when compiling for OS X, these macros are defined:
@
#define TARGET_OS_MAC 1
#define TARGET_OS_WIN32 0
#define TARGET_OS_UNIX 0
#define TARGET_OS_EMBEDDED 0
#define TARGET_OS_IPHONE 0
#define TARGET_IPHONE_SIMULATOR 0
@

In CCPlatformConfig.h we see this code, which will always evaluate true. You need to check TARGET_OS_IPHONE==1, not defined(TARGET_OS_IPHONE).
@
#if ! CC_TARGET_PLATFORM && (defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR))
#undef CC_TARGET_PLATFORM
#define CC_TARGET_PLATFORM CC_PLATFORM_IOS
#define CC_SUPPORT_PVRTC
#endif
@
This took me a long time to figure out. Now I have to see if my game actually runs.

Oh ImperialPenguin already explained that. If only I had read his post more carefully :frowning:

When I run my game, the screen is blank. I can tell from the console that the game is running and responding to clicks. I’ve tried following the example in helloworld. Looking at the code, I can’t see how the cocos CCEGLView gets hooked up with the EAGLView that gets created via the NIB loading process.

AppController.mm is the file that does the hookup. What does that file look like for you? I’ve got a couple of different versions that I use, one that uses a nib file and one that doesn’t. I’m not sure which version you are using but the solution should be in that file. If you are using a nib file, you’ll ned to setup the nib to include a glview and connect that to eaglview. My file that doesn’t use a nib, looks like the code below. If the version you using was changed from what I wrote, it might be completely different.

   NSRect rect = NSMakeRect(650, 350, 800, 480);    
    window = [[NSWindow alloc] initWithContentRect: rect styleMask:( NSClosableWindowMask | NSTitledWindowMask) backing:NSBackingStoreBuffered defer:YES];

    rect = NSMakeRect(0, 0, 800, 480);    
    glView = [[EAGLView alloc] initWithFrame:rect];
    [glView initWithFrame:rect];
    [window setContentView:glView];

    cocos2d::CCEGLView * pMainWnd = new cocos2d::CCEGLView();
    pMainWnd->Create(800, 480, 480, 320);

    [window setTitle:@"Cocos2d-x Tests"];

    [window makeKeyAndOrderFront:self];

That creates an 800x480 window with a 480x320 viewport. I use that functionality for creating the simulator in CatHide. You’ll probably want to adjust it for a more standard desktop size.

The header to the above looks like this:

@interface AppController : NSObject 
{
    NSWindow    *window;
    EAGLView    *glView;
}

IIRC The actual CatHide simulator uses a nib file so I could easily create the menu. I don’t have that code handy at the moment to post it.

Hi, I’m using the one with the NIB. In AppController.mm is basically identical to yours, I have this:
@
AppDelegate s_sharedApplication;

  • (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    [glView_ initWithFrame:CGRectMake(0,0,640,960)];
    cocos2d::CCApplication::sharedApplication()>run;
    }
    @
    Then in AppDelegate.cpp I have:
    @
    bool AppDelegate::applicationDidFinishLaunching {
    CCDirector *pDirector = CCDirector::sharedDirector;
    pDirector
    >setOpenGLView(CCEGLView::sharedOpenGLView());
    //… level load + scene init, which is the same as my iPhone version
    @

AppController (which is actually the Obj-C app delegate), is hooked up in the NIB as the delegate of First Responder, and the glView and window are also hooked up. I just did it again, to make sure. I’m actually going to set the window size to match the iPhone; the goal is to use the Mac app to help the level designer see his levels, without needing to mess with XCode.

Btw, I based my code on the helloworld sample listed earlier in this project. I had to make a few changes to get it to run with the gles20 branch. If there is a sample mac app that runs on the current version of the gles20 branch, that might help me understand the problem.

My game is running almost perfectly on Mac (non-retina as retina gives me some problems with TTF labels).

Only problem left for now is text input. How do I get CCTextFieldTTF to accept input from the keyboard ?

My game is running almost perfectly on Mac (non-retina as retina gives me some problems with TTF labels).

Only problem left for now is text input. How do I get CCTextFieldTTF to accept input from the keyboard ?

Hi,

I want run my game in Mac. It is currently for iPad . I am using cocos2d-x 2.0. Is there any way to run it on mac with existing code.

:slight_smile: