no message

This commit is contained in:
Gregory Pierce 2003-01-01 03:58:44 +00:00
parent beebfb4484
commit e20873b847
7 changed files with 251 additions and 136 deletions

View file

@ -34,7 +34,7 @@
#include <jni.h>
#include "extal.h"
#ifndef _WIN32
#ifdef _X11
#include <dlfcn.h>
#endif
@ -154,7 +154,8 @@ int LoadALExtensions();
void* GetFunctionPointer(const char* function) {
#ifdef _WIN32
return GetProcAddress(handleOAL, function);
#else
#endif
#ifdef _X11
return dlsym(handleOAL, function);
#endif
}
@ -165,7 +166,8 @@ void* GetFunctionPointer(const char* function) {
void LoadOpenAL() {
#ifdef _WIN32
handleOAL = LoadLibrary("OpenAL32.dll");
#else
#endif
#ifdef _X11
handleOAL = dlopen("libopenal.so", RTLD_LAZY);
#endif
}
@ -176,7 +178,8 @@ void LoadOpenAL() {
void UnLoadOpenAL() {
#ifdef _WIN32
FreeLibrary(handleOAL);
#else
#endif
#ifdef _X11
dlclose(handleOAL);
#endif
}

View file

@ -1,10 +1,42 @@
/*
* 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@gregorypierce.com>
* @version $Revision$
*/
#include "RenderingContext.h"
@ -13,6 +45,141 @@ 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()
{
}

View file

@ -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@gregorypierce.com>
* @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 @@ public:
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

View file

@ -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 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
#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 jboolean JNICALL Java_org_lwjgl_Display_nCreate
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
}

View file

@ -117,7 +117,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead
(JNIEnv * env, jclass clazz, jint keys)
{
return 0;
}
/*

View file

@ -112,4 +112,5 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer
(JNIEnv * env, jclass clazz) {
return 0;
}

View file

@ -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 @@ extern RenderingContext * renderingContext;
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 jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
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_nDestroy
*/
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_swapBuffers(JNIEnv * env, jo
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_nMakeCurrent
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nReleaseContext
(JNIEnv *, jobject)
{
// release the context
//
aglSetCurrentContext( NULL );
renderingContext->releaseContext();
}