2013-10-12 20:17:51 +02:00
|
|
|
// -*- objc -*-
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#import "ebiten_controller.h"
|
|
|
|
#import "ebiten_opengl_view.h"
|
|
|
|
#import "ebiten_window.h"
|
|
|
|
|
2013-10-13 16:06:05 +02:00
|
|
|
static NSWindow* generateWindow(size_t width, size_t height, size_t scale, const char* title) {
|
2013-10-12 20:17:51 +02:00
|
|
|
EbitenWindow* window = [[EbitenWindow alloc]
|
2013-10-13 16:06:05 +02:00
|
|
|
initWithSize:NSMakeSize(width * scale, height * scale)];
|
2013-10-12 20:17:51 +02:00
|
|
|
assert(window != nil);
|
|
|
|
|
2013-10-13 16:06:05 +02:00
|
|
|
NSRect const rect = NSMakeRect(0, 0, width * scale, height * scale);
|
2013-10-12 20:17:51 +02:00
|
|
|
NSOpenGLPixelFormatAttribute const attributes[] = {
|
|
|
|
NSOpenGLPFAWindow,
|
|
|
|
NSOpenGLPFADoubleBuffer,
|
|
|
|
NSOpenGLPFAAccelerated,
|
|
|
|
NSOpenGLPFADepthSize, 32,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
|
|
|
|
initWithAttributes:attributes];
|
|
|
|
EbitenOpenGLView* glView =
|
|
|
|
[[EbitenOpenGLView alloc] initWithFrame:rect
|
|
|
|
pixelFormat:format];
|
2013-10-13 10:36:18 +02:00
|
|
|
[window setContentView:glView];
|
2013-10-13 16:06:05 +02:00
|
|
|
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
2013-10-12 20:17:51 +02:00
|
|
|
//[window makeFirstResponder:glView];
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2013-10-13 10:36:18 +02:00
|
|
|
void Run(size_t width, size_t height, size_t scale, const char* title) {
|
2013-10-12 20:17:51 +02:00
|
|
|
@autoreleasepool {
|
2013-10-13 16:06:05 +02:00
|
|
|
NSWindow* window = generateWindow(width, height, scale, title);
|
2013-10-12 20:17:51 +02:00
|
|
|
EbitenController* controller = [[EbitenController alloc]
|
|
|
|
initWithWindow:window];
|
|
|
|
NSApplication* app = [NSApplication sharedApplication];
|
|
|
|
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
[app setDelegate:controller];
|
|
|
|
[app finishLaunching];
|
|
|
|
[app activateIgnoringOtherApps:YES];
|
|
|
|
[app run];
|
|
|
|
}
|
|
|
|
}
|