Linux/win32 changes for 0.6

This commit is contained in:
Elias Naur 2003-03-30 19:26:39 +00:00
parent d4dbc47949
commit bc33d3ff2b
17 changed files with 627 additions and 457 deletions

View File

@ -114,14 +114,14 @@ public abstract class Window {
*/
public final void setTitle(String newTitle) {
title = newTitle;
nSetTitle();
nSetTitle(title);
}
/**
* Native implementation of setTitle(). This will read the window's title member
* and stash it in the native title of the window.
*/
private native void nSetTitle();
private native void nSetTitle(String title);
/**
* @return true if the user or operating system has asked the window to close
@ -156,13 +156,10 @@ public abstract class Window {
*/
public final void paint() {
dirty = false;
swapBuffers();
doPaint();
}
/**
* Swap the buffers.
*/
private native void swapBuffers();
protected abstract void doPaint();
/**
* Create the window.
@ -188,7 +185,6 @@ public abstract class Window {
if (!created)
return;
doDestroy();
nDestroy();
currentWindow = null;
created = false;
}
@ -198,10 +194,6 @@ public abstract class Window {
*/
protected abstract void doDestroy();
/**
* Natively destroy the window
*/
private native void nDestroy();
/**
* @return the native window handle

View File

@ -133,6 +133,15 @@ public class BaseGL extends Window {
protected void doCreate() throws Exception {
nCreate(getTitle(), x, y, getWidth(), getHeight(), color, alpha, depth, stencil, fullscreen);
}
protected void doPaint() {
swapBuffers();
}
/**
* Swap the buffers.
*/
private native void swapBuffers();
/**
* Native method to create a windowed GL

View File

@ -2498,7 +2498,6 @@ int extgl_InitGLX(Display *disp, int screen)
glXGetProcAddressARB = (glXGetProcAddressARBPROC) dlsym(lib_gl_handle, "glXGetProcAddressARB");
if (glXGetProcAddressARB == NULL)
return 1;
if (extgl_InitGLX12() != 0)
return 1;
extgl_InitGLXSupportedExtensions(disp, screen);
@ -3235,19 +3234,17 @@ int extgl_Initialize()
}
#ifdef _X11
int extgl_Open(Display *disp, int screen)
int extgl_Open()
{
lib_gl_handle = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL);
if (lib_gl_handle == NULL)
return 1;
lib_glu_handle = dlopen("libGLU.so", RTLD_LAZY | RTLD_GLOBAL);
if (lib_glu_handle == NULL)
return 1;
if (extgl_InitGLX(disp, screen) != 0)
return 1;
return 0;
}
#endif /* X11 */
#ifdef _WIN32

View File

@ -5861,7 +5861,8 @@ extern struct ExtensionTypes extgl_Extensions;
/* initializes everything, call this right after the rc is created. the function returns 0 if successful */
int extgl_Initialize();
#ifdef _X11
int extgl_Open(Display *disp, int screen);
int extgl_Open(void);
int extgl_InitGLX(Display *disp, int screen);
#endif
#ifdef _WIN32

View File

@ -1,46 +1,30 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
#include <jni.h>
/* Header for class org_lwjgl_Window */
#ifndef _Included_org_lwjgl_Window
#define _Included_org_lwjgl_Window
#define _Included_org_lwjgl_Window
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: currentWindow */
/*
* Class: org_lwjgl_Window
* Method: nSetTitle
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_nSetTitle
#endif
/* Inaccessible static: currentWindow */
/*
* Class: org_lwjgl_Window
* Method: nSetTitle
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_nSetTitle
(JNIEnv *, jobject, jstring);
/*
* Class: org_lwjgl_Window
* Method: tick
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_tick
(JNIEnv *, jobject);
/*
* Class: org_lwjgl_Window
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_swapBuffers
(JNIEnv *, jobject);
/*
* Class: org_lwjgl_Window
* Method: nDestroy
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_nDestroy
(JNIEnv *, jobject);
/*
* Class: org_lwjgl_Window
* Method: tick
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_tick
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
#endif
#endif

View File

@ -8,6 +8,14 @@
extern "C" {
#endif
/* Inaccessible static: currentWindow */
/*
* Class: org_lwjgl_opengl_BaseGL
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers
(JNIEnv *, jobject);
/*
* Class: org_lwjgl_opengl_BaseGL
* Method: nCreate

View File

@ -6,6 +6,9 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `pthread' library (-lpthread). */
#undef HAVE_LIBPTHREAD
/* Define to 1 if you have the `X11' library (-lX11). */
#undef HAVE_LIBX11

View File

@ -51,8 +51,8 @@ if test "x$JAVA_HOME" = x; then
else
AC_MSG_RESULT($JAVA_HOME)
JAVA_HOME="$JAVA_HOME"
CPPFLAGS="$CPPFLAGS -D_DEBUG -D_X11 -Wall -I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
CFLAGS="$CFLAGS -D_DEBUG -D_X11 -Wall -I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
CPPFLAGS="$CPPFLAGS -fno-rtti -fno-exceptions -pthread -D_X11 -Wall -I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
CFLAGS="$CFLAGS -pthread -D_X11 -Wall -I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
fi
dnl Checks for libraries.
@ -64,6 +64,8 @@ dnl Replace `main' with a function in -lXext:
AC_CHECK_LIB(Xext, main,, AC_MSG_ERROR(Xext is required))
dnl Replace `main' with a function in -lXxf86vm:
AC_CHECK_LIB(Xxf86vm, main,, AC_MSG_ERROR(Xxf86vm is required))
dnl Replace `main' with a function in -tpthread:
AC_CHECK_LIB(pthread, main,, AC_MSG_ERROR(pthread is required))
dnl Checks for header files.

View File

@ -9,6 +9,7 @@ NATIVE = \
org_lwjgl_input_Controller.cpp \
org_lwjgl_input_Keyboard.cpp \
org_lwjgl_input_Mouse.cpp \
org_lwjgl_opengl_BaseGL.cpp
org_lwjgl_opengl_BaseGL.cpp \
org_lwjgl_Window.cpp

112
src/native/linux/Window.h Normal file
View File

@ -0,0 +1,112 @@
/*
* Copyright (c) 2002 Light Weight Java Game Library Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* $Id$
*
* Include file to access public window features
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#ifndef _LWJGL_WINDOW_H_INCLUDED_
#define _LWJGL_WINDOW_H_INCLUDED_
#include <jni.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
/*
* release input (keyboard, mouse)
*/
extern bool releaseInput(void);
/*
* Various functions to release/acquire keyboard and mouse
*/
extern void handlePointerMotion(XMotionEvent *);
extern void handleButtonPress(XButtonEvent *);
extern void handleButtonRelease(XButtonEvent *);
extern void handleKeyEvent(XKeyEvent *);
extern void releaseKeyboard(void);
extern void releasePointer(void);
extern void acquireKeyboard(void);
extern void acquirePointer(void);
/*
* destroy the window
*/
extern void destroyWindow(void);
/*
* create a new X window with the specified visual
*/
extern void createWindow(JNIEnv *env, Display *disp, int screen, XVisualInfo *vis_info, jstring title, int x, int y, int width, int height, bool fullscreen);
/*
* get the current window width
*/
extern int getWindowWidth(void);
/*
* get the current window height
*/
extern int getWindowHeight(void);
/*
* get the current display
*/
extern Display *getCurrentDisplay(void);
/*
* get the current screen
*/
extern int getCurrentScreen(void);
/*
* get the current window
*/
extern Window getCurrentWindow(void);
/*
* Utility function to throw an Exception
*/
extern void throwException(JNIEnv * env, const char * err);
/*
* Utility function to throw a RuntimeException
*/
extern void throwRuntimeException(JNIEnv * env, const char * err);
#endif /* _LWJGL_WINDOW_H_INCLUDED_ */

View File

@ -51,155 +51,8 @@
#include <jni.h>
#include "org_lwjgl_Display.h"
Display * disp;
int screen;
Window win;
static jfieldID fid_close;
static bool current_fullscreen;
static bool current_minimized;
static bool input_released;
static int win_width;
static int win_height;
static XF86VidModeModeInfo **avail_modes;
static XVisualInfo * vis_info;
static Atom delete_atom;
static jclass saved_clazz;
extern void handlePointerMotion(XMotionEvent *);
extern void handleButtonPress(XButtonEvent *);
extern void handleButtonRelease(XButtonEvent *);
extern void handleKeyEvent(XKeyEvent *);
extern void releaseKeyboard(void);
extern void releasePointer(void);
extern void acquireKeyboard(void);
extern void acquirePointer(void);
struct pixelformat {
int bpp;
int depth;
int alpha;
int stencil;
};
static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) {
int bpe;
switch (bpp) {
case 32:
case 24:
bpe = 8;
break;
case 16:
bpe = 4;
break;
default:
return JNI_FALSE;
}
int attriblist[] = { GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_DEPTH_SIZE, depth,
GLX_RED_SIZE, bpe,
GLX_GREEN_SIZE, bpe,
GLX_BLUE_SIZE, bpe,
GLX_ALPHA_SIZE, alpha,
GLX_STENCIL_SIZE, stencil,
None };
return glXChooseVisual(disp, screen, attriblist);
}
static void dumpVisualInfo(Display *disp, XVisualInfo *vis_info) {
int alpha, depth, stencil, r, g, b;
glXGetConfig(disp, vis_info, GLX_RED_SIZE, &r);
glXGetConfig(disp, vis_info, GLX_GREEN_SIZE, &g);
glXGetConfig(disp, vis_info, GLX_BLUE_SIZE, &b);
glXGetConfig(disp, vis_info, GLX_ALPHA_SIZE, &alpha);
glXGetConfig(disp, vis_info, GLX_DEPTH_SIZE, &depth);
glXGetConfig(disp, vis_info, GLX_STENCIL_SIZE, &stencil);
printf("Pixel format chosen sizes: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d\n", r, g, b, alpha, depth, stencil);
}
static void waitMapped(Display *disp, Window win) {
XEvent event;
do {
XMaskEvent(disp, StructureNotifyMask, &event);
} while ((event.type != MapNotify) || (event.xmap.event != win));
}
static void setRepeatMode(int mode) {
XKeyboardControl repeat_mode;
repeat_mode.auto_repeat_mode = mode;
XChangeKeyboardControl(disp, KBAutoRepeatMode, &repeat_mode);
}
bool releaseInput(void) {
if (current_fullscreen)
return false;
releaseKeyboard();
releasePointer();
input_released = true;
setRepeatMode(AutoRepeatModeDefault);
return true;
}
static void acquireInput(void) {
if (input_released) {
setRepeatMode(AutoRepeatModeOff);
acquireKeyboard();
acquirePointer();
input_released = false;
}
}
void handleMessages(JNIEnv *env) {
XEvent event;
while (XPending(disp) > 0) {
XNextEvent(disp, &event);
switch (event.type) {
case ClientMessage:
if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom))
env->SetStaticBooleanField(saved_clazz, fid_close, JNI_TRUE);
break;
case FocusIn:
acquireInput();
break;
case MapNotify:
current_minimized = false;
break;
case UnmapNotify:
current_minimized = true;
break;
case ButtonPress:
handleButtonPress(&(event.xbutton));
break;
case ButtonRelease:
handleButtonRelease(&(event.xbutton));
break;
case MotionNotify:
handlePointerMotion(&(event.xmotion));
break;
case KeyPress:
case KeyRelease:
handleKeyEvent(&(event.xkey));
break;
}
}
}
static bool loadGL(Display *disp, int screen) {
if (extgl_Open(disp, screen) != 0) {
#ifdef _DEBUG
printf("Could not load gl libs\n");
#endif
return false;
}
return true;
}
static void closeGL(void) {
extgl_Close();
}
static int saved_width;
static int saved_height;
static int getDisplayModes(Display *disp, int screen, int *num_modes, XF86VidModeModeInfo ***avail_modes) {
int event_base, error_base, xvid_ver, xvid_rev;
@ -218,170 +71,101 @@ static int getDisplayModes(Display *disp, int screen, int *num_modes, XF86VidMod
return 1;
}
static bool isMinimized(JNIEnv *env, jclass clazz) {
handleMessages(env);
return current_minimized;
}
int getWindowHeight(void) {
return win_height;
}
int getWindowWidth(void) {
return win_width;
}
XVisualInfo *getVisualInfo(void) {
return vis_info;
}
/*
* Class: org_lwjgl_Display
* Method: isMinimized
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized(JNIEnv *env, jclass clazz) {
return isMinimized(env, clazz) ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, jint alpha_bits, jint depth_bits, jint stencil_bits, jboolean fullscreen, jstring title) {
// Get a global class instance, just to be sure
static jobject globalClassLock = NULL;
if (globalClassLock == NULL) {
globalClassLock = env->NewGlobalRef(clazz);
}
saved_clazz = clazz;
fid_close = env->GetStaticFieldID(clazz, "closeRequested", "Z");
Window root_win;
XSetWindowAttributes attribs;
Colormap cmap;
int attribmask;
static bool setMode(int width, int height, bool lock_mode) {
int num_modes, i;
XF86VidModeModeInfo **avail_modes;
int screen;
Display *disp = XOpenDisplay(NULL);
win_width = width;
win_height = height;
if (fullscreen == JNI_TRUE)
current_fullscreen = true;
else
current_fullscreen = false;
current_minimized = false;
input_released = false;
disp = XOpenDisplay(NULL);
if (disp == NULL) {
#ifdef _DEBUG
printf("Could not open X connection\n");
#endif
return JNI_FALSE;
return false;
}
screen = DefaultScreen(disp);
if (!loadGL(disp, screen)) {
XCloseDisplay(disp);
#ifdef _DEBUG
printf("Could not load GL libs\n");
#endif
return JNI_FALSE;
}
if (!getDisplayModes(disp, screen, &num_modes, &avail_modes)) {
XCloseDisplay(disp);
#ifdef _DEBUG
printf("Could not get display modes\n");
#endif
return JNI_FALSE;
return false;
}
root_win = RootWindow(disp, screen);
vis_info = chooseVisual(disp, screen, bpp, depth_bits, alpha_bits, stencil_bits);
if (vis_info == NULL) {
XCloseDisplay(disp);
XF86VidModeLockModeSwitch(disp, screen, 0);
for ( i = 0; i < num_modes; ++i ) {
#ifdef _DEBUG
printf("Could not choose glx visual\n");
printf("Mode %d: %dx%d\n", i, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay);
#endif
return JNI_FALSE;
}
if (avail_modes[i]->hdisplay == width && avail_modes[i]->vdisplay == height) {
if (!XF86VidModeSwitchToMode(disp, screen, avail_modes[i])) {
#ifdef _DEBUG
dumpVisualInfo(disp, vis_info);
printf("Could not switch mode\n");
#endif
cmap = XCreateColormap(disp, root_win, vis_info->visual, AllocNone);
attribs.colormap = cmap;
attribs.event_mask = FocusChangeMask | VisibilityChangeMask| StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
attribs.background_pixel = 0xFF000000;
attribmask = CWColormap | CWBackPixel | CWEventMask;
if (fullscreen) {
attribmask |= CWOverrideRedirect;
attribs.override_redirect = True;
}
win = XCreateWindow(disp, root_win, 0, 0, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs);
XFreeColormap(disp, cmap);
#ifdef _DEBUG
printf("Created window\n");
#endif
const char * title_str = env->GetStringUTFChars(title, NULL);
XStoreName(disp, win, title_str);
env->ReleaseStringUTFChars(title, title_str);
XSizeHints * size_hints = XAllocSizeHints();
size_hints->flags = PMinSize | PMaxSize;
size_hints->min_width = width;
size_hints->max_width = width;
size_hints->min_height = height;
size_hints->max_height = height;
XSetWMNormalHints(disp, win, size_hints);
XFree(size_hints);
delete_atom = XInternAtom(disp, "WM_DELETE_WINDOW", False);
XSetWMProtocols(disp, win, &delete_atom, 1);
XMapRaised(disp, win);
waitMapped(disp, win);
if (fullscreen) {
for ( i = 0; i < num_modes; ++i ) {
#ifdef _DEBUG
printf("Mode %d: %dx%d\n", i, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay);
#endif
if (avail_modes[i]->hdisplay == width && avail_modes[i]->vdisplay == height) {
if (!XF86VidModeSwitchToMode(disp, screen, avail_modes[i])) {
XFree(vis_info);
XFree(avail_modes);
XDestroyWindow(disp, win);
XCloseDisplay(disp);
#ifdef _DEBUG
printf("Could not switch mode\n");
#endif
return JNI_FALSE;
}
XF86VidModeLockModeSwitch(disp, screen, 1);
break;
}
}
XF86VidModeSetViewPort(disp, screen, 0, 0);
}
XClearWindow(disp, win);
setRepeatMode(AutoRepeatModeOff);
XSync(disp, True);
return JNI_TRUE;
}
JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy(JNIEnv * env, jclass clazz) {
setRepeatMode(AutoRepeatModeDefault);
XDestroyWindow(disp, win);
if (current_fullscreen) {
XF86VidModeLockModeSwitch(disp, screen, 0);
if (!XF86VidModeSwitchToMode(disp, screen, avail_modes[0])) {
#ifdef _DEBUG
printf("Could not switch mode\n");
#endif
// XF86VidModeSetViewPort(disp, screen, 0, 0);
if (lock_mode)
XF86VidModeLockModeSwitch(disp, screen, 1);
XFree(avail_modes);
XCloseDisplay(disp);
return true;
}
}
XFree(avail_modes);
avail_modes = NULL;
XFree(vis_info);
vis_info = NULL;
XCloseDisplay(disp);
disp = NULL;
closeGL();
return false;
}
JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
(JNIEnv * env, jclass clazz)
{
int num_modes;
XF86VidModeModeInfo **avail_modes;
int screen;
Display *disp = XOpenDisplay(NULL);
if (disp == NULL) {
#ifdef _DEBUG
printf("Closed X connection\n");
printf("Could not open X connection\n");
#endif
return;
}
screen = DefaultScreen(disp);
if (!getDisplayModes(disp, screen, &num_modes, &avail_modes)) {
#ifdef _DEBUG
printf("Could not get display modes\n");
#endif
}
saved_width = avail_modes[0]->hdisplay;
saved_height = avail_modes[0]->vdisplay;
int bpp = XDefaultDepth(disp, screen);
#ifdef _DEBUG
printf("Saved width, height %d, %d\n", saved_width, saved_height);
#endif
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/DisplayMode");
jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V");
jobject newMode = env->NewObject(jclass_DisplayMode, ctor, saved_width, saved_height, bpp, 0);
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
env->SetStaticObjectField(clazz, fid_initialMode, newMode);
XFree(avail_modes);
XCloseDisplay(disp);
}
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode(JNIEnv * env, jclass clazz, jobject mode) {
jclass cls_displayMode = env->FindClass("org/lwjgl/DisplayMode");
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
int width = env->GetIntField(mode, fid_width);
int height = env->GetIntField(mode, fid_height);
if (setMode(width, height, true)) {
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
env->SetStaticObjectField(clazz, fid_initialMode, mode);
}
}
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv * env, jclass clazz) {
setMode(saved_width, saved_height, false);
}
/*
@ -393,7 +177,6 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
(JNIEnv * env, jclass clazz)
{
int num_modes, i;
Display *disp = XOpenDisplay(NULL);
int screen;
XF86VidModeModeInfo **avail_modes;
@ -402,7 +185,6 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
#ifdef _DEBUG
printf("Could not open X connection\n");
#endif
XCloseDisplay(disp);
return NULL;
}

View File

@ -0,0 +1,239 @@
/*
* Copyright (c) 2002 Light Weight Java Game Library Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* $Id$
*
* Linux specific window functions.
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <jni.h>
#include <Window.h>
#include "org_lwjgl_Window.h"
static Atom delete_atom;
static Display *current_disp;
static Window current_win;
static int current_screen;
static bool current_fullscreen;
static int current_height;
static int current_width;
static bool input_released;
static void waitMapped(Display *disp, Window win) {
XEvent event;
do {
XMaskEvent(disp, StructureNotifyMask, &event);
} while ((event.type != MapNotify) || (event.xmap.event != win));
}
bool releaseInput(void) {
if (current_fullscreen)
return false;
releaseKeyboard();
releasePointer();
input_released = true;
return true;
}
static void acquireInput(void) {
if (input_released) {
acquireKeyboard();
acquirePointer();
input_released = false;
}
}
static void handleMessages(JNIEnv *env, jobject window_obj) {
XEvent event;
while (XPending(current_disp) > 0) {
XNextEvent(current_disp, &event);
switch (event.type) {
case ClientMessage:
if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom))
env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "closeRequested", "Z"), JNI_TRUE);
break;
case FocusIn:
acquireInput();
break;
case MapNotify:
env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "dirty", "Z"), JNI_TRUE);
env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "minimized", "Z"), JNI_FALSE);
break;
case UnmapNotify:
env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "minimized", "Z"), JNI_TRUE);
case Expose:
env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "dirty", "Z"), JNI_TRUE);
break;
case ButtonPress:
handleButtonPress(&(event.xbutton));
break;
case ButtonRelease:
handleButtonRelease(&(event.xbutton));
break;
case MotionNotify:
handlePointerMotion(&(event.xmotion));
break;
case KeyPress:
case KeyRelease:
handleKeyEvent(&(event.xkey));
break;
}
}
}
static void setWindowTitle(const char *title) {
XStoreName(current_disp, current_win, title);
}
JNIEXPORT void JNICALL Java_org_lwjgl_Window_nSetTitle
(JNIEnv * env, jobject obj, jstring title_obj)
{
const char * title = env->GetStringUTFChars(title_obj, NULL);
setWindowTitle(title);
env->ReleaseStringUTFChars(title_obj, title);
}
void createWindow(JNIEnv* env, Display *disp, int screen, XVisualInfo *vis_info, jstring title, int x, int y, int width, int height, bool fullscreen) {
Window root_win;
Window win;
XSetWindowAttributes attribs;
Colormap cmap;
int attribmask;
current_disp = disp;
current_screen = screen;
input_released = false;
current_fullscreen = fullscreen;
current_width = width;
current_height = height;
root_win = RootWindow(disp, screen);
cmap = XCreateColormap(disp, root_win, vis_info->visual, AllocNone);
attribs.colormap = cmap;
attribs.event_mask = ExposureMask | FocusChangeMask | VisibilityChangeMask| StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
attribs.background_pixel = 0xFF000000;
attribmask = CWColormap | CWBackPixel | CWEventMask;
if (fullscreen) {
attribmask |= CWOverrideRedirect;
attribs.override_redirect = True;
}
win = XCreateWindow(disp, root_win, x, y, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs);
XFreeColormap(disp, cmap);
#ifdef _DEBUG
printf("Created window\n");
#endif
current_win = win;
Java_org_lwjgl_Window_nSetTitle(env, NULL, title);
XSizeHints * size_hints = XAllocSizeHints();
size_hints->flags = PMinSize | PMaxSize;
size_hints->min_width = width;
size_hints->max_width = width;
size_hints->min_height = height;
size_hints->max_height = height;
XSetWMNormalHints(disp, win, size_hints);
XFree(size_hints);
delete_atom = XInternAtom(disp, "WM_DELETE_WINDOW", False);
XSetWMProtocols(disp, win, &delete_atom, 1);
XMapRaised(disp, win);
waitMapped(disp, win);
XClearWindow(disp, win);
XSync(disp, True);
}
void destroyWindow() {
XDestroyWindow(current_disp, current_win);
current_disp = NULL;
}
Display *getCurrentDisplay(void) {
return current_disp;
}
int getCurrentScreen(void) {
return current_screen;
}
Window getCurrentWindow(void) {
return current_win;
}
int getWindowWidth(void) {
return current_width;
}
int getWindowHeight(void) {
return current_height;
}
/*
* Class: org_lwjgl_Window
* Method: tick
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_tick
(JNIEnv *env, jobject obj)
{
handleMessages(env, obj);
}
/*
* Utility function to throw an Exception
*/
void throwException(JNIEnv * env, const char * err)
{
jclass cls = env->FindClass("java/lang/Exception");
env->ThrowNew(cls, err);
env->DeleteLocalRef(cls);
}
/*
* Utility function to throw a RuntimeException
*/
void throwRuntimeException(JNIEnv * env, const char * err)
{
jclass cls = env->FindClass("java/lang/RuntimeException");
env->ThrowNew(cls, err);
env->DeleteLocalRef(cls);
}

View File

@ -44,6 +44,7 @@
#include <X11/Xutil.h>
#include <string.h>
#include <assert.h>
#include <Window.h>
#include "org_lwjgl_input_Keyboard.h"
#define KEYBOARD_BUFFER_SIZE 50
@ -65,12 +66,6 @@ static bool translation_enabled;
static bool created = false;
static bool should_grab = false;
extern Display *disp;
extern Window win;
extern bool releaseInput(void);
extern void handleMessages(JNIEnv *env);
/*
* Class: org_lwjgl_input_Keyboard
* Method: initIDs
@ -82,16 +77,25 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_initIDs
fid_readBuffer = env->GetStaticFieldID(clazz, "readBuffer", "Ljava/nio/ByteBuffer;");
}
static void setRepeatMode(int mode) {
XKeyboardControl repeat_mode;
repeat_mode.auto_repeat_mode = mode;
XChangeKeyboardControl(getCurrentDisplay(), KBAutoRepeatMode, &repeat_mode);
}
static int grabKeyboard(void) {
int result = XGrabKeyboard(disp, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
if (result == GrabSuccess)
int result = XGrabKeyboard(getCurrentDisplay(), getCurrentWindow(), False, GrabModeAsync, GrabModeAsync, CurrentTime);
if (result == GrabSuccess) {
keyboard_grabbed = true;
setRepeatMode(AutoRepeatModeOff);
}
return result;
}
static void ungrabKeyboard(void) {
keyboard_grabbed = false;
XUngrabKeyboard(disp, CurrentTime);
XUngrabKeyboard(getCurrentDisplay(), CurrentTime);
setRepeatMode(AutoRepeatModeDefault);
}
void acquireKeyboard(void) {
@ -257,7 +261,6 @@ void handleKeyEvent(XKeyEvent *event) {
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll
(JNIEnv * env, jclass clazz, jint buf)
{
handleMessages(env);
updateGrab();
memcpy((unsigned char*)buf, key_buf, KEYBOARD_SIZE*sizeof(unsigned char));
}
@ -274,7 +277,6 @@ JNIEXPORT int JNICALL Java_org_lwjgl_input_Keyboard_nRead
int buf_count = 0;
int num_events = 0;
handleMessages(env);
updateGrab();
while (buf_count < KEYBOARD_BUFFER_SIZE * 2 && (key_event = nextEventElement()) != NULL) {
num_events++;

View File

@ -45,6 +45,7 @@
#include <X11/extensions/xf86vmode.h>
#include <assert.h>
#include <string.h>
#include <Window.h>
#include "org_lwjgl_input_Mouse.h"
#define NUM_BUTTONS 3
@ -54,13 +55,6 @@
// scale the mouse wheel according to win32
#define WHEEL_SCALE 120
extern Display *disp;
extern Window win;
extern int screen;
extern int getWindowWidth(void);
extern int getWindowHeight(void);
extern void handleMessages(JNIEnv* env);
static bool pointer_grabbed;
static bool created = false;
static bool should_grab = false;
@ -106,30 +100,30 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_initIDs
static int blankCursor(void) {
unsigned int best_width, best_height;
if (XQueryBestCursor(disp, win, 1, 1, &best_width, &best_height) == 0) {
if (XQueryBestCursor(getCurrentDisplay(), getCurrentWindow(), 1, 1, &best_width, &best_height) == 0) {
#ifdef _DEBUG
printf("Could not query best cursor size\n");
#endif
return 0;
}
Pixmap mask = XCreatePixmap(disp, win, best_width, best_height, 1);
Pixmap mask = XCreatePixmap(getCurrentDisplay(), getCurrentWindow(), best_width, best_height, 1);
XGCValues gc_values;
gc_values.foreground = 0;
GC gc = XCreateGC(disp, mask, GCForeground, &gc_values);
XFillRectangle(disp, mask, gc, 0, 0, best_width, best_height);
XFreeGC(disp, gc);
GC gc = XCreateGC(getCurrentDisplay(), mask, GCForeground, &gc_values);
XFillRectangle(getCurrentDisplay(), mask, gc, 0, 0, best_width, best_height);
XFreeGC(getCurrentDisplay(), gc);
XColor dummy_color;
blank_cursor = XCreatePixmapCursor(disp, mask, mask, &dummy_color, &dummy_color, 0, 0);
XFreePixmap(disp, mask);
blank_cursor = XCreatePixmapCursor(getCurrentDisplay(), mask, mask, &dummy_color, &dummy_color, 0, 0);
XFreePixmap(getCurrentDisplay(), mask);
return 1;
}
static int grabPointer(void) {
int result;
int mask = FocusChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
result = XGrabPointer(disp, win, False, mask, GrabModeAsync, GrabModeAsync, win, blank_cursor, CurrentTime);
XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y);
XF86VidModeSetViewPort(disp, screen, 0, 0); // make sure we have a centered window
result = XGrabPointer(getCurrentDisplay(), getCurrentWindow(), False, mask, GrabModeAsync, GrabModeAsync, getCurrentWindow(), blank_cursor, CurrentTime);
XWarpPointer(getCurrentDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, current_x, current_y);
XF86VidModeSetViewPort(getCurrentDisplay(), getCurrentScreen(), 0, 0); // make sure we have a centered window
if (result == GrabSuccess)
pointer_grabbed = true;
return result;
@ -137,7 +131,7 @@ static int grabPointer(void) {
static void ungrabPointer(void) {
pointer_grabbed = false;
XUngrabPointer(disp, CurrentTime);
XUngrabPointer(getCurrentDisplay(), CurrentTime);
}
void acquirePointer(void) {
@ -200,7 +194,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nDestroy
{
if (pointer_grabbed)
ungrabPointer();
XFreeCursor(disp, blank_cursor);
XFreeCursor(getCurrentDisplay(), blank_cursor);
created = false;
should_grab = false;
}
@ -258,11 +252,11 @@ static void warpPointer(void) {
current_x > getWindowWidth() - POINTER_WARP_BORDER || current_y > getWindowHeight() - POINTER_WARP_BORDER) {
current_x = last_x = getWindowWidth()/2;
current_y = last_y = getWindowHeight()/2;
XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y);
XWarpPointer(getCurrentDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, current_x, current_y);
XEvent event;
// Try to catch the warp pointer event
for (i = 0; i < WARP_RETRY; i++) {
XMaskEvent(disp, PointerMotionMask, &event);
XMaskEvent(getCurrentDisplay(), PointerMotionMask, &event);
if (event.xmotion.x > current_x - POINTER_WARP_BORDER &&
event.xmotion.x < current_x + POINTER_WARP_BORDER &&
event.xmotion.y > current_y - POINTER_WARP_BORDER &&
@ -287,7 +281,6 @@ static void warpPointer(void) {
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll
(JNIEnv * env, jclass clazz)
{
handleMessages(env);
updateGrab();
int moved_x = current_x - last_x;
int moved_y = current_y - last_y;

View File

@ -40,21 +40,64 @@
*/
#include "extgl.h"
#include "Window.h"
#include "org_lwjgl_opengl_BaseGL.h"
static GLXContext context = NULL; // OpenGL rendering context
extern XVisualInfo * getVisualInfo(void);
extern Window win;
extern Display * disp;
extern void handleMessages(JNIEnv* env);
static void makeCurrent(void) {
glXMakeCurrent(disp, win, context);
glXMakeCurrent(getCurrentDisplay(), getCurrentWindow(), context);
}
static void releaseContext(void) {
glXMakeCurrent(disp, None, NULL);
glXMakeCurrent(getCurrentDisplay(), None, NULL);
}
static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) {
int bpe;
switch (bpp) {
case 32:
case 24:
bpe = 8;
break;
case 16:
bpe = 4;
break;
default:
return JNI_FALSE;
}
int attriblist[] = { GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_DEPTH_SIZE, depth,
GLX_RED_SIZE, bpe,
GLX_GREEN_SIZE, bpe,
GLX_BLUE_SIZE, bpe,
GLX_ALPHA_SIZE, alpha,
GLX_STENCIL_SIZE, stencil,
None };
return glXChooseVisual(disp, screen, attriblist);
}
static void dumpVisualInfo(Display *disp, XVisualInfo *vis_info) {
int alpha, depth, stencil, r, g, b;
glXGetConfig(disp, vis_info, GLX_RED_SIZE, &r);
glXGetConfig(disp, vis_info, GLX_GREEN_SIZE, &g);
glXGetConfig(disp, vis_info, GLX_BLUE_SIZE, &b);
glXGetConfig(disp, vis_info, GLX_ALPHA_SIZE, &alpha);
glXGetConfig(disp, vis_info, GLX_DEPTH_SIZE, &depth);
glXGetConfig(disp, vis_info, GLX_STENCIL_SIZE, &stencil);
printf("Pixel format chosen sizes: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d\n", r, g, b, alpha, depth, stencil);
}
static void destroy(void) {
releaseContext();
glXDestroyContext(getCurrentDisplay(), context);
context = NULL;
Display *disp = getCurrentDisplay();
destroyWindow();
XCloseDisplay(disp);
extgl_Close();
}
/*
@ -62,41 +105,63 @@ static void releaseContext(void) {
* Method: nCreate
* Signature: (IIII)Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
(JNIEnv * env, jobject obj)
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
(JNIEnv * env, jobject obj, jstring title, jint x, jint y, jint width, jint height, jint bpp, jint alpha, jint depth, jint stencil, jboolean fullscreen)
{
int screen;
Display *disp;
XVisualInfo *vis_info;
bool fscreen = false;
if (fullscreen == JNI_TRUE)
fscreen = true;
if (extgl_Open() != 0) {
throwException(env, "Could not load gl libs");
return;
}
disp = XOpenDisplay(NULL);
if (disp == NULL) {
#ifdef _DEBUG
printf("No display\n");
#endif
return JNI_FALSE;
XCloseDisplay(disp);
throwException(env, "Could not open X display");
return;
}
if (getVisualInfo() == NULL) {
#ifdef _DEBUG
printf("No visual info\n");
#endif
return JNI_FALSE;
screen = XDefaultScreen(disp);
if (extgl_InitGLX(disp, screen) != 0) {
XCloseDisplay(disp);
extgl_Close();
throwException(env, "Could not init GLX");
return;
}
context = glXCreateContext(disp, getVisualInfo(), NULL, True);
vis_info = chooseVisual(disp, screen, bpp, depth, alpha, stencil);
if (vis_info == NULL) {
XCloseDisplay(disp);
extgl_Close();
throwException(env, "Could not find a matching pixel format");
return;
}
#ifdef _DEBUG
dumpVisualInfo(disp, vis_info);
#endif
context = glXCreateContext(disp, vis_info, NULL, True);
if (context == NULL) {
#ifdef _DEBUG
printf("Could not create context\n");
#endif
return JNI_FALSE;
XFree(vis_info);
XCloseDisplay(disp);
extgl_Close();
throwException(env, "Could not create a GLX context");
return;
}
createWindow(env, disp, screen, vis_info, title, x, y, width, height, fscreen);
XFree(vis_info);
makeCurrent();
if (extgl_Initialize() != 0) {
#ifdef _DEBUG
printf("Could not init gl function pointers\n");
#endif
return JNI_FALSE;
destroy();
throwException(env, "Could not init gl function pointers");
return;
}
#ifdef _DEBUG
const GLubyte * extensions = glGetString(GL_EXTENSIONS);
printf("Supported extensions: %s\n", extensions);
#endif
return JNI_TRUE;
}
/*
@ -104,12 +169,10 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
* Method: nDestroy
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroyGL
(JNIEnv * env, jobject obj)
{
releaseContext();
glXDestroyContext(disp, context);
context = NULL;
destroy();
}
/*
@ -119,8 +182,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jobject obj)
{
handleMessages(env);
glXSwapBuffers(disp, win);
glXSwapBuffers(getCurrentDisplay(), getCurrentWindow());
}
/*

View File

@ -178,15 +178,15 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
case SC_MONITORPOWER:
return 0L;
case SC_MINIMIZE:
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "minimized", "Z"), true);
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "minimized", "Z"), JNI_TRUE);
appActivate(true);
break;
case SC_RESTORE:
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "minimized", "Z"), false);
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "minimized", "Z"), JNI_FALSE);
appActivate(false);
break;
case SC_CLOSE:
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "closeRequested", "Z"), true);
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "closeRequested", "Z"), JNI_TRUE);
//don't continue processing this command since this
//would shutdown the window, which the application might not want to
return 0L;
@ -198,11 +198,11 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
switch(LOWORD(wParam)) {
case WA_ACTIVE:
case WA_CLICKACTIVE:
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "minimized", "Z"), false);
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "minimized", "Z"), JNI_FALSE);
isMinimized = false;
break;
case WA_INACTIVE:
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "minimized", "Z"), true);
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "minimized", "Z"), JNI_TRUE);
isMinimized = true;
break;
}
@ -211,12 +211,12 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
break;
case WM_QUIT:
{
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "closeRequested", "Z"), true);
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "closeRequested", "Z"), JNI_TRUE);
return 0L;
}
case WM_PAINT:
{
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "dirty", "Z"), true);
environment->SetBooleanField(window, environment->GetFieldID(environment->GetObjectClass(window), "dirty", "Z"), JNI_TRUE);
}
}
@ -353,40 +353,11 @@ bool createWindow(const char * title, int x, int y, int width, int height, bool
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_nSetTitle
(JNIEnv * env, jobject obj)
(JNIEnv * env, jobject obj, jstring title_obj)
{
const char * title = env->GetStringUTFChars((jstring) obj, NULL);
const char * title = env->GetStringUTFChars(title_obj, NULL);
SetWindowText(hwnd, title);
env->ReleaseStringUTFChars((jstring) obj, title);
}
/*
* Class: org_lwjgl_Window
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_swapBuffers
(JNIEnv * env, jobject obj)
{
SwapBuffers(hdc);
}
/*
* Class: org_lwjgl_Window
* Method: nDestroy
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Window_nDestroy
(JNIEnv * env, jobject obj)
{
// Cache env and obj
environment = env;
window = obj;
closeWindow();
environment = NULL;
window = NULL;
env->ReleaseStringUTFChars(title_obj, title);
}
/*
@ -426,4 +397,4 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Window_tick
(JNIEnv * env, jobject obj)
{
handleMessages(env, obj);
}
}

View File

@ -204,6 +204,18 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroyGL
wglDeleteContext(hglrc);
hglrc = NULL;
}
closeWindow();
extgl_Close();
}
/*
* Class: org_lwjgl_opengl_BaseGL
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers
(JNIEnv *, jobject)
{
SwapBuffers(wglGetCurrentDC());
}