Update of /cvsroot/java-game-lib/LWJGL/src/native/macosx In directory sc8-pr-cvs1:/tmp/cvs-serv2955/src/native/macosx Modified Files: org_lwjgl_opengl_BaseGL.cpp org_lwjgl_input_Mouse.cpp org_lwjgl_input_Keyboard.cpp org_lwjgl_Display.cpp RenderingContext.h RenderingContext.cpp Log Message: no message Index: org_lwjgl_opengl_BaseGL.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_opengl_BaseGL.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_opengl_BaseGL.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- org_lwjgl_opengl_BaseGL.cpp 30 Dec 2002 22:06:28 -0000 1.3 +++ org_lwjgl_opengl_BaseGL.cpp 1 Jan 2003 03:58:03 -0000 1.4 @@ -39,12 +39,11 @@ * @version $Revision$ */ -#define _OSX -#include "extgl.h" -#include "org_lwjgl_opengl_BaseGL.h" #include "RenderingContext.h" +#include "org_lwjgl_opengl_BaseGL.h" + + -extern RenderingContext * renderingContext; /* * Class: org_lwjgl_opengl_BaseGL @@ -54,64 +53,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate (JNIEnv * env, jobject obj, jint colorBits, jint alphaBits, jint depthBits, jint stencilBits) { - AGLPixelFormat fmt; - GLboolean ok; - GLint attrib[] = { AGL_RGBA, AGL_NONE }; - - if ( extgl_Open() != 0 ) - { - printf("extgl_Open failed"); - return JNI_FALSE; - } - - /* Choose an rgb pixel format */ - fmt = aglChoosePixelFormat(NULL, 0, attrib); - if(fmt == NULL) - { - return JNI_FALSE; - } - - /* Create an AGL context */ - renderingContext->aglContext = aglCreateContext(fmt, NULL); - if( renderingContext->aglContext == NULL) - { - return JNI_FALSE; - } - - /* Attach the window to the context */ - ok = aglSetDrawable(renderingContext->aglContext, GetWindowPort(renderingContext->windowPtr) ); - if(!ok) - { - return JNI_FALSE; - } - - /* Make the context the current context */ - ok = aglSetCurrentContext(renderingContext->aglContext); - if(!ok) - { - return JNI_FALSE; - } - - if ( extgl_Initialize() != 0 ) - { - printf("Failed to initialize GL [extgl_Initialize()]\n"); - return JNI_FALSE; - } - - /* Pixel format is no longer needed */ - aglDestroyPixelFormat(fmt); - -#ifdef _DEBUG - char * p = (char * ) glGetString( GL_EXTENSIONS ); - if ( NULL == p ) - { - printf("NO extensions available"); - } - else - { - printf("Available extensions:\n%s\n", p); - } -#endif /* DEBUG */ + renderingContext->createGL( colorBits, alphaBits, depthBits, stencilBits ); return JNI_TRUE; } @@ -124,17 +66,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy (JNIEnv * env, jobject obj) { - // clear out the current rendering context - // - aglSetCurrentContext( NULL ); - - // destroy the context - // - aglDestroyContext( renderingContext->aglContext ); - - // close the gl extension context - // - extgl_Close(); + renderingContext->destroyGL(); } /* @@ -144,9 +76,7 @@ */ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jobject obj) { - // swap the rendering buffer - // - aglSwapBuffers( renderingContext->aglContext ); + renderingContext->swap(); } /* @@ -157,9 +87,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nMakeCurrent (JNIEnv * env, jobject obj) { - // make the current context the one we have stored - // - aglSetCurrentContext( renderingContext->aglContext ); + renderingContext->makeContextCurrent(); } /* @@ -170,7 +98,5 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nReleaseContext (JNIEnv *, jobject) { - // release the context - // - aglSetCurrentContext( NULL ); + renderingContext->releaseContext(); } Index: org_lwjgl_input_Mouse.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Mouse.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Mouse.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- org_lwjgl_input_Mouse.cpp 30 Dec 2002 07:09:35 -0000 1.2 +++ org_lwjgl_input_Mouse.cpp 1 Jan 2003 03:58:03 -0000 1.3 @@ -112,4 +112,5 @@ */ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer (JNIEnv * env, jclass clazz) { + return 0; } Index: org_lwjgl_input_Keyboard.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Keyboard.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Keyboard.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- org_lwjgl_input_Keyboard.cpp 30 Dec 2002 07:09:35 -0000 1.3 +++ org_lwjgl_input_Keyboard.cpp 1 Jan 2003 03:58:03 -0000 1.4 @@ -117,7 +117,7 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead (JNIEnv * env, jclass clazz, jint keys) { - + return 0; } /* Index: org_lwjgl_Display.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Display.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Display.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- org_lwjgl_Display.cpp 30 Dec 2002 22:06:28 -0000 1.6 +++ org_lwjgl_Display.cpp 1 Jan 2003 03:58:03 -0000 1.7 @@ -29,16 +29,12 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <Carbon/Carbon.h> -#include <AGL/agl.h> -#include <OpenGL/gl.h> -#include <JavaVM/jni.h> + #include "org_lwjgl_Display.h" +#include <JavaVM/jni.h> #include "RenderingContext.h" - -RenderingContext * renderingContext; - +RenderingContext * renderingContext; /* * Class: org_lwjgl_Display @@ -64,29 +60,8 @@ #endif renderingContext = new RenderingContext(); - - InitCursor(); - SetRect( &renderingContext->rect, 0, 0, width, height ); - renderingContext->windowPtr = NewCWindow( NULL, &renderingContext->rect, "LWJGL", true, kWindowShadowDialogProc, (WindowPtr) -1L, true, 0L ); - - /* - CreateNewWindow( kDocumentWindowClass, - kWindowStandardDocumentAttributes | - kWindowStandardHandlerAttribute, - &rect, - &windowPtr ); - */ - - SetPortWindowPort( renderingContext->windowPtr ); - - if ( renderingContext->windowPtr == NULL ) - { - printf("Failed to create a window\n"); - return JNI_TRUE; - } - - ShowWindow( renderingContext->windowPtr ); + renderingContext->createDisplay( width, height, bpp, freq ); jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I"); @@ -103,19 +78,15 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy (JNIEnv * env, jclass clazz) { - // cleanup the AGL context - // - aglSetCurrentContext(NULL); - aglSetDrawable(renderingContext->aglContext, NULL); - aglDestroyContext(renderingContext->aglContext); - - // cleanup the window - // - DisposeWindow( renderingContext->windowPtr ); +#ifdef _DEBUG + printf("Destroying display\n"); +#endif + + renderingContext->destroyDisplay(); #ifdef _DEBUG - printf("Destroyed display\n"); + printf("Destroyed display\n"); #endif } Index: RenderingContext.h CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/RenderingContext.h =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/RenderingContext.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- RenderingContext.h 30 Dec 2002 07:09:35 -0000 1.2 +++ RenderingContext.h 1 Jan 2003 03:58:03 -0000 1.3 @@ -1,16 +1,50 @@ /* - * RenderingContext.h - * lwjglOSX +* Copyright (c) 2002 Light Weight Java Game Library Project + * All rights reserved. * - * Created by Gregory Pierce on Sat Dec 28 2002. - * Copyright (c) 2002 __MyCompanyName__. 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. */ -#pragma once +/** +* $Id$ + * + * OSX rendering context management. + * + * @author Gregory Pierce <me...@gr...> + * @version $Revision$ + */ + +#ifndef _RENDERING_CONTEXT_H +#define _RENDERING_CONTEXT_H + +#include "extgl.h" #include <Carbon/Carbon.h> #include <AGL/agl.h> -#include <OpenGL/gl.h> class RenderingContext { @@ -22,5 +56,18 @@ RenderingContext(); ~RenderingContext(); + + bool createDisplay( int width, int height, int bpp, int freq ); + void destroyDisplay(); + + bool createGL( int colorBits, int alphaBits, int depthBits, int stencilBits ); + void destroyGL(); + + void swap(); + void makeContextCurrent(); + void releaseContext(); }; +extern RenderingContext * renderingContext; + +#endif Index: RenderingContext.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/RenderingContext.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/RenderingContext.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- RenderingContext.cpp 30 Dec 2002 07:09:35 -0000 1.2 +++ RenderingContext.cpp 1 Jan 2003 03:58:03 -0000 1.3 @@ -1,16 +1,183 @@ /* - * RenderingContext.cpp - * lwjglOSX +* Copyright (c) 2002 Light Weight Java Game Library Project + * All rights reserved. * - * Created by Gregory Pierce on Sat Dec 28 2002. - * Copyright (c) 2002 __MyCompanyName__. 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$ * + * OSX rendering context management. + * + * @author Gregory Pierce <me...@gr...> + * @version $Revision$ */ #include "RenderingContext.h" RenderingContext::RenderingContext() { +} + +bool RenderingContext::createDisplay( int width, int height, int bpp, int freq ) +{ + InitCursor(); + + SetRect( &rect, 0, 0, width, height ); + windowPtr = NewCWindow( NULL, &rect, "LWJGL", true, kWindowShadowDialogProc, (WindowPtr) -1L, true, 0L ); + + SetPortWindowPort( windowPtr ); + + if ( windowPtr == NULL ) + { + printf("Failed to create a window\n"); + return false; + } + + ShowWindow( windowPtr ); + + return true; +} + +void RenderingContext::destroyDisplay() +{ + // cleanup the AGL context + // + aglSetCurrentContext(NULL); + aglSetDrawable(aglContext, NULL); + aglDestroyContext(aglContext); + + // cleanup the window + // + DisposeWindow( windowPtr ); +} + +bool RenderingContext::createGL( int colorBits, int alphaBits, int depthBits, int stencilBits ) +{ + AGLPixelFormat fmt; + GLboolean ok; + GLint attrib[] = { AGL_RGBA, AGL_NONE }; + + + if ( extgl_Open() != 0 ) + { + printf("extgl_Open failed"); + return false; + } + + /* Choose an rgb pixel format */ + fmt = aglChoosePixelFormat(NULL, 0, attrib); + if(fmt == NULL) + { + return false; + } + + /* Create an AGL context */ + aglContext = aglCreateContext(fmt, NULL); + if( aglContext == NULL) + { + return false; + } + + /* Attach the window to the context */ + ok = aglSetDrawable(aglContext, GetWindowPort(windowPtr) ); + if(!ok) + { + return false; + } + + /* Make the context the current context */ + ok = aglSetCurrentContext(aglContext); + if(!ok) + { + return false; + } + + if ( extgl_Initialize() != 0 ) + { + printf("Failed to initialize GL [extgl_Initialize()]\n"); + return false; + } + + /* Pixel format is no longer needed */ + aglDestroyPixelFormat(fmt); + +#ifdef _DEBUG + char * p = (char * ) glGetString( GL_EXTENSIONS ); + if ( NULL == p ) + { + printf("NO extensions available"); + } + else + { + printf("Available extensions:\n%s\n", p); + } +#endif /* DEBUG */ + + return true; + +} + +void RenderingContext::destroyGL() +{ + // clear out the current rendering context + // + aglSetCurrentContext( NULL ); + + // destroy the context + // + aglDestroyContext( aglContext ); + + // close the gl extension context + // + extgl_Close(); +} + +void RenderingContext::swap() +{ + // swap the rendering buffer + // + aglSwapBuffers( aglContext ); +} + +void RenderingContext::makeContextCurrent() +{ + // make the current context the one we have stored + // + aglSetCurrentContext( aglContext ); +} + +void RenderingContext::releaseContext() +{ + // release the context + // + aglSetCurrentContext( NULL ); } RenderingContext::~RenderingContext() |