|
From: Elias N. <eli...@us...> - 2003-09-29 12:38:19
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/macosx In directory sc8-pr-cvs1:/tmp/cvs-serv22446/src/native/macosx Modified Files: org_lwjgl_opengl_Window.cpp Log Message: Various Mac stuff Index: org_lwjgl_opengl_Window.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_opengl_Window.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_opengl_Window.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- org_lwjgl_opengl_Window.cpp 26 Sep 2003 18:36:54 -0000 1.6 +++ org_lwjgl_opengl_Window.cpp 29 Sep 2003 09:26:20 -0000 1.7 @@ -42,6 +42,7 @@ #include <Carbon/Carbon.h> #include <JavaVM/jni.h> #include "org_lwjgl_opengl_Window.h" +#include "extgl.h" static WindowRef win_ref; static bool close_requested; @@ -56,24 +57,9 @@ env->DeleteLocalRef(cls); } -/*static void dumpRootMenu() { - MenuRef root = AcquireRootMenu(); - if (root == NULL) - printf("NULL menu\n"); - UInt16 count = CountMenuItems(root); - printf("item count: %d\n", count); - for (int i = 0; i < count; i++) { - Str255 menu_text; - GetMenuItemText(root, i, menu_text); - printf("Item text: %s\n", menu_text); - } - ReleaseMenu(root); -} -*/ static void setWindowTitle(JNIEnv *env, jstring title_obj) { const char* title = env->GetStringUTFChars(title_obj, NULL); - int str_len = env->GetStringUTFLength(title_obj); - CFStringRef cf_title = CFStringCreateWithBytes(NULL, (const UInt8*)title, str_len, kCFStringEncodingUTF8, false); + CFStringRef cf_title = CFStringCreateWithCStringNoCopy(NULL, title, kCFStringEncodingUTF8, kCFAllocatorNull); if (cf_title == NULL) { #ifdef _DEBUG printf("Could not set window title\n"); @@ -81,18 +67,8 @@ return; } SetWindowTitleWithCFString(win_ref, cf_title); -/* MenuRef root; - OSStatus err = CreateNewMenu(1, 0, &root); - assert(err == noErr); - MenuItemIndex item_index; - err = AppendMenuItemTextWithCFString(root, cf_title, 0, FOUR_CHAR_CODE('1234'), &item_index); - assert(err == noErr); - err = SetRootMenu(root); - assert(err == noErr); - ReleaseMenu(root);*/ CFRelease(cf_title); env->ReleaseStringUTFChars(title_obj, title); -// dumpRootMenu(); } static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event, void *user_data) { @@ -102,37 +78,47 @@ } static void registerEventHandlers(JNIEnv *env) { - /*EventTargetRef event_target = GetWindowEventTarget(win_ref); - status = InstallStandardEventHandler(event_target); - if (noErr != status) { - DisposeWindow(win_ref); - throwException(env, "Could not install default window event handler"); - return; - }*/ - EventTypeSpec event_types[1]; + EventTypeSpec event_type; OSStatus err; EventHandlerUPP handler_upp = NewEventHandlerUPP(doQuit); - event_types[0].eventClass = kEventClassWindow; - event_types[0].eventKind = kEventWindowClose; - err = InstallWindowEventHandler(win_ref, handler_upp, 1, event_types, NULL, NULL); + event_type.eventClass = kEventClassWindow; + event_type.eventKind = kEventWindowClose; + err = InstallWindowEventHandler(win_ref, handler_upp, 1, &event_type, NULL, NULL); if (noErr != err) { DisposeEventHandlerUPP(handler_upp); throwException(env, "Could not register window event handler"); return; } - event_types[0].eventClass = kEventClassApplication; - event_types[0].eventKind = kEventAppQuit; - /*event_types[1].eventClass = kEventClassAppleEvent; - event_types[1].eventKind = kEventAppleEvent;*/ - err = InstallApplicationEventHandler(handler_upp, 1, event_types, NULL, NULL); - if (noErr != err) { - DisposeEventHandlerUPP(handler_upp); - throwException(env, "Could not register application event handler"); - return; - } DisposeEventHandlerUPP(handler_upp); } +static void destroy(void) { + DisposeWindow(win_ref); + extgl_Close(); +} + +static bool createContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint stencil) { + SetPort(GetWindowPort(win_ref)); + GLint attrib[] = {AGL_RGBA, + AGL_DOUBLEBUFFER, + AGL_ACCELERATED, + AGL_SINGLE_RENDERER, + AGL_FULLSCREEN, + AGL_MINIMUM_POLICY, + AGL_PIXEL_SIZE, bpp, + AGL_DEPTH_SIZE, depth, + AGL_ALPHA_SIZE, alpha, + AGL_STENCIL_SIZE, stencil, + AGL_NONE}; + AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, attrib); + if (format == NULL) { + throwException(env, "Could not find matching pixel format"); + return false; + } +printf("Found matching pixel format\n "); + aglDestroyPixelFormat(format); + return true; +} JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested(JNIEnv *, jclass) { const bool saved = close_requested; @@ -140,50 +126,22 @@ return saved; } -/*OSErr aehandler(const AppleEvent * theAppleEvent, AppleEvent * reply, SInt32 handlerRefcon) { - printf("handler called\n"); - return noErr; -} -*/ - JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass clazz, jstring title, jint x, jint y, jint width, jint height, jboolean fullscreen, jint bpp, jint alpha, jint depth, jint stencil, jobject ext_set) { Rect rect; OSStatus status; const WindowAttributes window_attr = kWindowCloseBoxAttribute| kWindowCollapseBoxAttribute| kWindowStandardHandlerAttribute; -// CPSEnableForegroundOperation(); - /*//AEObjectInit(); - AEEventHandlerUPP handler = NewAEEventHandlerUPP(aehandler); - if (noErr != AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, handler, 0, FALSE)) - printf("error\n"); - if (noErr != AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, handler, 0, FALSE)) - printf("error\n"); - if (noErr != AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, handler, 0, FALSE)) - printf("error\n"); - if (noErr != AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, handler, 0, FALSE)) - printf("error\n"); - DisposeAEEventHandlerUPP(handler);*/ - /* - * Hacks to activate the application window - */ - /*CFBundleRef bundle = CFBundleGetMainBundle(); - if (bundle != NULL) { - printf("bundle != NULL\n"); - CFRelease(bundle); - }*/ - /*ProcessSerialNumber PSN; - GetCurrentProcess(&PSN); - SetFrontProcess(&PSN);*/ - EventLoopRef queue = GetCurrentEventLoop(); - EventLoopRef main = GetMainEventLoop(); - QuitEventLoop(queue); - QuitEventLoop(main); - /*if (queue == main) - printf("equals\n");*/ SetRect(&rect, x, y, x + width, y + height); close_requested = false; - + if (!extgl_Open()) { + throwException(env, "Could not load gl library"); + return; + } + if (!extgl_InitAGL(env, ext_set)) { + throwException(env, "Could not load agl function pointers"); + return; + } status = CreateNewWindow(kDocumentWindowClass, window_attr, &rect, &win_ref); if (noErr != status) { throwException(env, "Could not create window"); @@ -193,43 +151,27 @@ setWindowTitle(env, title); const RGBColor background_color = { 0, 0, 0 }; SetWindowContentColor(win_ref, &background_color); - status = TransitionWindow(win_ref, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL); - if (noErr != status) { + if (!createContext(env, bpp, alpha, depth, stencil)) { DisposeWindow(win_ref); - throwException(env, "Could not show window"); + extgl_Close(); return; } + if (!extgl_Initialize(env, ext_set)) { + destroy(); + throwException(env, "Could not load gl function pointers"); + return; + } + TransitionWindow(win_ref, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL); SelectWindow(win_ref); - InitCursor(); -//QuitApplicationEventLoop(); -//RunApplicationEventLoop(); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_update (JNIEnv *env, jclass clazz) { - /*EventRef event; - OSStatus err; - int num_events = GetNumEventsInQueue(GetCurrentEventQueue()); - for (int i = 0; i < num_events; i++) { - UInt32 class_type = GetEventClass(event); - UInt32 kind = GetEventKind(event); - UInt32 test = FOUR_CHAR_CODE('eppc'); - EventTime event_time = GetEventTime(event); - //UInt32 test = FOUR_CHAR_CODE('appl'); - printf("recieved event: %x %x %x at %f\n", class_type, kind, test, event_time); - err = ReceiveNextEvent(0, NULL, 0, true, &event); - /* if (kind == kEventClassAppleEvent) - AEProcessAppleEvent(event);*/ - /* ReleaseEvent(event); - } - //RunCurrentEventLoop(0); -/* if (eventLoopTimedOutErr != RunCurrentEventLoop(0)) - printf("Could not run current event loop\n");*/ } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy (JNIEnv *env, jclass clazz) { - DisposeWindow(win_ref); + destroy(); } |