mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
Add CreateGLContext
This commit is contained in:
parent
638da2ed2c
commit
0628d1342f
@ -7,7 +7,9 @@ package cocoa
|
||||
// #include "input.h"
|
||||
//
|
||||
// void StartApplication(void);
|
||||
// void* CreateWindow(size_t width, size_t height, const char* title);
|
||||
// void* CreateGLContext(void* sharedGLContext);
|
||||
// void SetCurrentGLContext(void* glContext);
|
||||
// void* CreateWindow(size_t width, size_t height, const char* title, void* glContext);
|
||||
// void PollEvents(void);
|
||||
// void BeginDrawing(void* window);
|
||||
// void EndDrawing(void* window);
|
||||
@ -77,14 +79,17 @@ func New(screenWidth, screenHeight, screenScale int, title string) *UI {
|
||||
|
||||
C.StartApplication()
|
||||
|
||||
ui.window = C.CreateWindow(C.size_t(ui.screenWidth * ui.screenScale),
|
||||
C.size_t(ui.screenHeight * ui.screenScale),
|
||||
cTitle)
|
||||
context := C.CreateGLContext(unsafe.Pointer(nil))
|
||||
C.SetCurrentGLContext(context);
|
||||
ui.graphicsDevice = opengl.NewDevice(
|
||||
ui.screenWidth,
|
||||
ui.screenHeight,
|
||||
ui.screenScale)
|
||||
|
||||
ui.window = C.CreateWindow(C.size_t(ui.screenWidth * ui.screenScale),
|
||||
C.size_t(ui.screenHeight * ui.screenScale),
|
||||
cTitle,
|
||||
context)
|
||||
currentUI = ui
|
||||
return ui
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ void StartApplication() {
|
||||
[app activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
void* CreateGLContext() {
|
||||
void* CreateGLContext(void* sharedGLContext) {
|
||||
NSOpenGLPixelFormatAttribute attributes[] = {
|
||||
NSOpenGLPFAWindow,
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
@ -25,24 +25,27 @@ void* CreateGLContext() {
|
||||
};
|
||||
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
|
||||
initWithAttributes:attributes];
|
||||
NSOpenGLContext* glContext = [[NSOpenGLContext alloc] initWithFormat:format
|
||||
shareContext:nil];
|
||||
NSOpenGLContext* glContext =
|
||||
[[NSOpenGLContext alloc] initWithFormat:format
|
||||
shareContext:(NSOpenGLContext*)sharedGLContext];
|
||||
[format release];
|
||||
return glContext;
|
||||
}
|
||||
|
||||
void* CreateWindow(size_t width, size_t height, const char* title) {
|
||||
NSOpenGLContext* glContext = CreateGLContext();
|
||||
[glContext makeCurrentContext];
|
||||
void SetCurrentGLContext(void* glContext) {
|
||||
[(NSOpenGLContext*)glContext makeCurrentContext];
|
||||
}
|
||||
|
||||
// This takes the ownership of glContext.
|
||||
void* CreateWindow(size_t width, size_t height, const char* title, void* glContext) {
|
||||
NSSize size = NSMakeSize(width, height);
|
||||
EbitenWindow* window = [[EbitenWindow alloc]
|
||||
initWithSize:size
|
||||
glContext:glContext];
|
||||
glContext:(NSOpenGLContext*)glContext];
|
||||
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
||||
[window makeKeyAndOrderFront:nil];
|
||||
|
||||
[glContext setView:[window contentView]];
|
||||
[(NSOpenGLContext*)glContext setView:[window contentView]];
|
||||
|
||||
return window;
|
||||
}
|
||||
@ -61,6 +64,7 @@ void PollEvents(void) {
|
||||
}
|
||||
|
||||
void BeginDrawing(void* window) {
|
||||
[[(EbitenWindow*)window glContext] makeCurrentContext];
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user