*** empty log message ***

This commit is contained in:
Elias Naur 2003-10-24 05:51:50 +00:00
parent 86cedb9425
commit 7d5992c02e
4 changed files with 38 additions and 14 deletions

View File

@ -201,16 +201,15 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode(JNIEnv * env, jclas
Display *disp = XOpenDisplay(NULL); Display *disp = XOpenDisplay(NULL);
if (disp == NULL) { if (disp == NULL) {
#ifdef _DEBUG throwException(env, "Could not open X connection.");
printf("Could not open X connection\n");
#endif
return; return;
} }
screen = DefaultScreen(disp); screen = DefaultScreen(disp);
if (setMode(disp, screen, width, height, true)) { if (setMode(disp, screen, width, height, true)) {
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;"); jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
env->SetStaticObjectField(clazz, fid_initialMode, mode); env->SetStaticObjectField(clazz, fid_initialMode, mode);
} } else
throwException(env, "Could not switch mode.");
XCloseDisplay(disp); XCloseDisplay(disp);
} }

View File

@ -44,9 +44,8 @@
#include <jni.h> #include <jni.h>
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
extern void setQuitRequested(void);
extern void resetMode(JNIEnv *env); extern void resetMode(JNIEnv *env);
extern void switchMode(JNIEnv *env, long width, long height, long bpp, long freq); extern bool switchMode(JNIEnv *env, long width, long height, long bpp, long freq);
extern void handleKeyboardEvent(EventRef event); extern void handleKeyboardEvent(EventRef event);
#endif /* _LWJGL_WINDOW_H_INCLUDED_ */ #endif /* _LWJGL_WINDOW_H_INCLUDED_ */

View File

@ -93,12 +93,30 @@ static void releaseDisplay(void) {
} }
} }
void switchMode(JNIEnv *env, long width, long height, long bpp, long freq) { bool switchMode(JNIEnv *env, long width, long height, long bpp, long freq) {
init(env); init(env);
captureDisplay(); captureDisplay();
CFDictionaryRef displayMode = CGDisplayBestModeForParametersAndRefreshRate(kCGDirectMainDisplay, bpp, width, height, freq, NULL); CFArrayRef modes = CGDisplayAvailableModes(kCGDirectMainDisplay);
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode); int size = CFArrayGetCount(modes);
saveMode(env, width, height, bpp, freq); for (int i = 0; i < size; i++) {
CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, i);
long mode_width;
long mode_height;
long mode_bpp;
long mode_freq;
getDictLong(mode, kCGDisplayWidth, &mode_width);
getDictLong(mode, kCGDisplayHeight, &mode_height);
getDictLong(mode, kCGDisplayRefreshRate, &mode_freq);
getDictLong(mode, kCGDisplayBitsPerPixel, &mode_bpp);
if (width == mode_width && height == mode_height && bpp == mode_bpp && mode_freq == freq) {
CGDisplayErr err = CGDisplaySwitchToMode(kCGDirectMainDisplay, mode);
if (!err) {
saveMode(env, width, height, bpp, freq);
return true;
}
}
}
return false;
} }
void resetMode(JNIEnv *env) { void resetMode(JNIEnv *env) {
@ -123,7 +141,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode(JNIEnv * env, jclas
int height = env->GetIntField(mode, fid_height); int height = env->GetIntField(mode, fid_height);
int bpp = env->GetIntField(mode, fid_bpp); int bpp = env->GetIntField(mode, fid_bpp);
int freq = env->GetIntField(mode, fid_freq); int freq = env->GetIntField(mode, fid_freq);
switchMode(env, width, height, bpp, freq); if (!switchMode(env, width, height, bpp, freq)) {
throwException(env, "Could not switch mode.");
}
} }
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes(JNIEnv * env, jclass clazz) { JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes(JNIEnv * env, jclass clazz) {

View File

@ -103,7 +103,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested(JNIEnv
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) { 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) {
vsync_enabled = false; vsync_enabled = false;
current_fullscreen = fullscreen == JNI_FALSE; current_fullscreen = fullscreen == JNI_TRUE;
if (!extgl_Open()) { if (!extgl_Open()) {
throwException(env, "Could not load gl library"); throwException(env, "Could not load gl library");
return; return;
@ -112,8 +112,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass
throwException(env, "Could not load agl symbols"); throwException(env, "Could not load agl symbols");
return; return;
} }
if (current_fullscreen) if (!current_fullscreen) {
switchMode(env, width, height, bpp, 60); if (!switchMode(env, width, height, bpp, 60)) {
destroyMode(env, clazz);
extgl_Close();
throwException(env, "Could not switch mode.");
return;
}
}
if (!createFullscreenContext(env, bpp, alpha, depth, stencil)) { if (!createFullscreenContext(env, bpp, alpha, depth, stencil)) {
destroyMode(env, clazz); destroyMode(env, clazz);
extgl_Close(); extgl_Close();