From: Gregory P. <gre...@us...> - 2002-09-03 05:53:08
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/macosx In directory usw-pr-cvs1:/tmp/cvs-serv30536 Modified Files: org_lwjgl_Display.cpp Log Message: Updated with GL setup functions 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.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- org_lwjgl_Display.cpp 3 Sep 2002 04:57:24 -0000 1.1 +++ org_lwjgl_Display.cpp 3 Sep 2002 05:53:05 -0000 1.2 @@ -29,13 +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 "org_lwjgl_Display.h" -// Initialise static variables -bool oneShotInitialised = false; - AGLContext ctx; Rect rect; @@ -79,6 +78,15 @@ } ShowWindow( win ); + + /* Setup the OpenGL context */ + GLint attrib[] = { AGL_RGBA, AGL_NONE }; + + ctx = setupAGL( attrib, (AGLDrawable) win); + if(ctx == NULL) + { + return JNI_FALSE; + } jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I"); @@ -107,4 +115,57 @@ printf("Destroyed display\n"); #endif } -@ + + +/* +** 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); +} |