mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
Have EbitenWindow have a NSOpenGLContext
This commit is contained in:
parent
3c979825db
commit
638da2ed2c
@ -24,6 +24,11 @@
|
||||
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
|
||||
(void)aNotification;
|
||||
[self initMenu];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(windowClosing:)
|
||||
name:NSWindowWillCloseNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:
|
||||
@ -32,4 +37,9 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)windowClosing:(NSNotification*)aNotification {
|
||||
(void)aNotification;
|
||||
[NSApp terminate:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -6,9 +6,15 @@
|
||||
|
||||
#import "ebiten_content_view.h"
|
||||
|
||||
@implementation EbitenWindow
|
||||
@implementation EbitenWindow {
|
||||
@private
|
||||
NSOpenGLContext* glContext_;
|
||||
}
|
||||
|
||||
- (id)initWithSize:(NSSize)size
|
||||
glContext:(NSOpenGLContext*)glContext {
|
||||
self->glContext_ = glContext;
|
||||
|
||||
- (id)initWithSize:(NSSize)size {
|
||||
NSUInteger style = (NSTitledWindowMask | NSClosableWindowMask |
|
||||
NSMiniaturizableWindowMask);
|
||||
NSRect windowRect =
|
||||
@ -39,6 +45,10 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSOpenGLContext*)glContext {
|
||||
return self->glContext_;
|
||||
}
|
||||
|
||||
- (BOOL)windowShouldClose:(id)sender {
|
||||
if ([sender isDocumentEdited]) {
|
||||
// TODO: add the application's name
|
||||
@ -63,7 +73,8 @@
|
||||
(void)alert;
|
||||
(void)contextInfo;
|
||||
if (returnCode == NSAlertDefaultReturn) {
|
||||
[NSApp terminate:nil];
|
||||
[self->glContext_ release];
|
||||
[self close];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,9 @@
|
||||
|
||||
@interface EbitenWindow : NSWindow<NSWindowDelegate>
|
||||
|
||||
- (id)initWithSize:(NSSize)size;
|
||||
- (id)initWithSize:(NSSize)size
|
||||
glContext:(NSOpenGLContext*)glContext;
|
||||
- (NSOpenGLContext*)glContext;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -6,8 +6,6 @@
|
||||
#import "ebiten_controller.h"
|
||||
#import "ebiten_window.h"
|
||||
|
||||
static NSOpenGLContext* glContext_;
|
||||
|
||||
void StartApplication() {
|
||||
EbitenController* controller = [[EbitenController alloc] init];
|
||||
NSApplication* app = [NSApplication sharedApplication];
|
||||
@ -34,13 +32,18 @@ void* CreateGLContext() {
|
||||
}
|
||||
|
||||
void* CreateWindow(size_t width, size_t height, const char* title) {
|
||||
NSOpenGLContext* glContext = CreateGLContext();
|
||||
[glContext makeCurrentContext];
|
||||
|
||||
NSSize size = NSMakeSize(width, height);
|
||||
EbitenWindow* window = [[EbitenWindow alloc]
|
||||
initWithSize:size];
|
||||
initWithSize:size
|
||||
glContext:glContext];
|
||||
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
||||
[window makeKeyAndOrderFront:nil];
|
||||
glContext_ = CreateGLContext();
|
||||
[glContext_ makeCurrentContext];
|
||||
|
||||
[glContext setView:[window contentView]];
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
@ -58,10 +61,9 @@ void PollEvents(void) {
|
||||
}
|
||||
|
||||
void BeginDrawing(void* window) {
|
||||
[glContext_ setView:[(EbitenWindow*)window contentView]];
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void EndDrawing(void* window) {
|
||||
[glContext_ flushBuffer];
|
||||
[[(EbitenWindow*)window glContext] flushBuffer];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user