Updated to use RenderingContext

This commit is contained in:
Gregory Pierce 2002-09-08 06:19:21 +00:00
parent 0078885178
commit ef84e6de85
1 changed files with 35 additions and 89 deletions

View File

@ -32,13 +32,12 @@
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include <AGL/agl.h> #include <AGL/agl.h>
#include <OpenGL/gl.h> #include <OpenGL/gl.h>
#include <JavaVM/jni.h>
#include "RenderingContext.h"
#include "org_lwjgl_Display.h" #include "org_lwjgl_Display.h"
RenderingContext * renderingContext;
AGLContext ctx;
Rect rect;
WindotPtr win;
/* /*
@ -63,36 +62,37 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
#ifdef _DEBUG #ifdef _DEBUG
printf("Creating display: size %dx%d %dhz %dbpp...\n", width, height, freq, bpp); printf("Creating display: size %dx%d %dhz %dbpp...\n", width, height, freq, bpp);
#endif #endif
renderingContext = new RenderingContext();
InitCursor(); InitCursor();
Rect rect;
SetRect( &rect, 0, 0, width, height ); SetRect( &rect, 0, 0, width, height );
win = NewCWindow( NULL, &rect, "Lightweight Java Gaming Library", true, kWindowShadowDialogProc, (WindowPtr) -1L, true, 0L );
SetPortWindowPort( win ); WindowPtr windowPtr = NewCWindow( NULL, &rect, "Lightweight Java Gaming Library", true, kWindowShadowDialogProc, (WindowPtr) -1L, true, 0L );
if ( win==null ) SetPortWindowPort( windowPtr );
if ( windowPtr == NULL )
{ {
printf("Failed to create a window\n"); printf("Failed to create a window\n");
return 1; return 1;
} }
ShowWindow( win ); ShowWindow( windowPtr );
/*
/* Setup the OpenGL context */ pAGLContext = setupAGL( attrib, (AGLDrawable) windowPtr);
GLint attrib[] = { AGL_RGBA, AGL_NONE };
ctx = setupAGL( attrib, (AGLDrawable) win);
if(ctx == NULL) if(ctx == NULL)
{ {
return JNI_FALSE; return 1;
} }
*/
jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I"); jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I");
env->SetStaticIntField(clazz, fid_handle, (jint) win); env->SetStaticIntField(clazz, fid_handle, (jint) windowPtr );
return JNI_TRUE; return 0;
} }
/* /*
@ -105,11 +105,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy
{ {
// cleanup the AGL context // cleanup the AGL context
// //
cleanupAGL( ctx ); renderingContext->destroy();
// cleanup the window
//
DisposeWindow( win );
#ifdef _DEBUG #ifdef _DEBUG
printf("Destroyed display\n"); printf("Destroyed display\n");
@ -117,55 +114,4 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy
} }
/*
** OpenGL Setup
*/
static AGLContext setupAGL( GLint* attrib, AGLDrawable win)
{
AGLPixelFormat fmt;
AGLContext ctx;
GLboolean ok;
/* Choose an rgb pixel format */
fmt = aglChoosePixelFormat(NULL, 0, attrib);
if(fmt == NULL)
{
return NULL;
}
/* Create an AGL context */
ctx = aglCreateContext(fmt, NULL);
if(ctx == NULL)
{
return NULL;
}
/* Attach the window to the context */
ok = aglSetDrawable(ctx, GetWindowPort(win) );
if(!ok)
{
return NULL;
}
/* Make the context the current context */
ok = aglSetCurrentContext(ctx);
if(!ok)
{
return NULL;
}
/* Pixel format is no longer needed */
aglDestroyPixelFormat(fmt);
return ctx;
}
/*
** OpenGL Cleanup
*/
static void cleanupAGL(AGLContext ctx)
{
aglSetCurrentContext(NULL);
aglSetDrawable(ctx, NULL);
aglDestroyContext(ctx);
}