2013-11-22 18:56:18 +01:00
|
|
|
// -*- objc -*-
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2013-11-23 18:00:09 +01:00
|
|
|
#include <OpenGL/gl.h>
|
2013-11-22 18:56:18 +01:00
|
|
|
|
|
|
|
#import "ebiten_controller.h"
|
|
|
|
#import "ebiten_window.h"
|
|
|
|
|
2013-11-23 18:00:09 +01:00
|
|
|
static NSOpenGLContext* glContext_;
|
|
|
|
|
2013-11-23 17:17:22 +01:00
|
|
|
void StartApplication() {
|
|
|
|
EbitenController* controller = [[EbitenController alloc] init];
|
|
|
|
NSApplication* app = [NSApplication sharedApplication];
|
|
|
|
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
[app setDelegate:controller];
|
|
|
|
[app finishLaunching];
|
|
|
|
[app activateIgnoringOtherApps:YES];
|
|
|
|
}
|
|
|
|
|
2013-11-23 18:00:09 +01:00
|
|
|
void* CreateGLContext() {
|
|
|
|
NSOpenGLPixelFormatAttribute attributes[] = {
|
|
|
|
NSOpenGLPFAWindow,
|
|
|
|
NSOpenGLPFADoubleBuffer,
|
|
|
|
NSOpenGLPFAAccelerated,
|
|
|
|
NSOpenGLPFADepthSize, 32,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
|
|
|
|
initWithAttributes:attributes];
|
|
|
|
NSOpenGLContext* glContext = [[NSOpenGLContext alloc] initWithFormat:format
|
|
|
|
shareContext:nil];
|
|
|
|
[format release];
|
|
|
|
return glContext;
|
|
|
|
}
|
|
|
|
|
2013-11-23 17:17:22 +01:00
|
|
|
void* CreateWindow(size_t width, size_t height, const char* title) {
|
|
|
|
NSSize size = NSMakeSize(width, height);
|
|
|
|
EbitenWindow* window = [[EbitenWindow alloc]
|
|
|
|
initWithSize:size];
|
|
|
|
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
|
|
|
[window makeKeyAndOrderFront:nil];
|
2013-11-23 18:00:09 +01:00
|
|
|
glContext_ = CreateGLContext();
|
|
|
|
[glContext_ makeCurrentContext];
|
2013-11-23 17:17:22 +01:00
|
|
|
return window;
|
|
|
|
}
|
2013-11-22 18:56:18 +01:00
|
|
|
|
2013-11-23 11:31:10 +01:00
|
|
|
void PollEvents(void) {
|
|
|
|
for (;;) {
|
|
|
|
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
|
|
|
untilDate:[NSDate distantPast]
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
if (event == nil) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-23 17:17:22 +01:00
|
|
|
void BeginDrawing(void* window) {
|
2013-11-23 18:00:09 +01:00
|
|
|
[glContext_ setView:[(EbitenWindow*)window contentView]];
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2013-11-22 18:56:18 +01:00
|
|
|
}
|
|
|
|
|
2013-11-23 17:17:22 +01:00
|
|
|
void EndDrawing(void* window) {
|
2013-11-23 18:00:09 +01:00
|
|
|
[glContext_ flushBuffer];
|
2013-11-22 18:56:18 +01:00
|
|
|
}
|