From d70d3ac4b68528916c9a0696afe7f55e0bcda376 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sun, 18 Jun 2006 21:42:51 -0400 Subject: [PATCH] Changed Fixed some apple stuff glGenTextures is still generating a bus error because we don't have a gl context yet. ~g2k --- .cdtproject | 1 + .project | 24 +++--- Makefile.macosx | 3 - include/main.h | 5 +- include/mygl.h | 8 +- include/tga.h | 2 +- include/window.h | 25 +++++- src/Makefile.macosx | 23 +++--- src/macosx.cpp | 8 +- src/mygl.cpp | 7 +- src/myglTexture.cpp | 14 ++-- src/window.cpp | 190 +++++++++++++++++++++++++++++++++++++++++++- 12 files changed, 259 insertions(+), 51 deletions(-) diff --git a/.cdtproject b/.cdtproject index 4a5fef5..9f52969 100644 --- a/.cdtproject +++ b/.cdtproject @@ -49,6 +49,7 @@ + diff --git a/.project b/.project index e958169..2c78234 100644 --- a/.project +++ b/.project @@ -11,40 +11,44 @@ org.eclipse.cdt.make.core.build.arguments - + -f Makefile.macosx org.eclipse.cdt.core.errorOutputParser org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.VCErrorParser; - - org.eclipse.cdt.make.core.enableAutoBuild - false - org.eclipse.cdt.make.core.environment - org.eclipse.cdt.make.core.enableFullBuild - true + org.eclipse.cdt.make.core.enableAutoBuild + false org.eclipse.cdt.make.core.build.target.inc all + + org.eclipse.cdt.make.core.enableFullBuild + true + org.eclipse.cdt.make.core.enabledIncrementalBuild true - org.eclipse.cdt.make.core.build.target.clean - clean + org.eclipse.cdt.make.core.build.location + org.eclipse.cdt.make.core.build.command make + + org.eclipse.cdt.make.core.build.target.clean + clean + org.eclipse.cdt.make.core.enableCleanBuild true @@ -59,7 +63,7 @@ org.eclipse.cdt.make.core.useDefaultBuildCmd - true + false org.eclipse.cdt.make.core.build.target.auto diff --git a/Makefile.macosx b/Makefile.macosx index 299a194..044cbc7 100644 --- a/Makefile.macosx +++ b/Makefile.macosx @@ -2,9 +2,6 @@ EXECUTABLES = OpenArena/OA LIBRARIES = BUILDROOT = /usr/local PREFIX = -INCLUDE_DIRS = /System/Library/Frameworks/OpenGL.framework/Headers -LIBRARY_DIRS = /System/Library/Frameworks/OpenGL.framework/Libraries - .Phony: all clean install all: diff --git a/include/main.h b/include/main.h index 0c396b0..71f224b 100644 --- a/include/main.h +++ b/include/main.h @@ -14,8 +14,8 @@ #include // Header file for Glu32 library #endif #ifdef __APPLE__ -#include // Header file for OpenGL32 library -#include // Header file for Glu32 library +#include // Header file for OpenGL32 library +#include // Header file for Glu32 library #endif #include @@ -28,6 +28,7 @@ #include "window.h" #include "vector.h" #pragma warning(disable: 4786) + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Variables diff --git a/include/mygl.h b/include/mygl.h index d523c14..4b8cac7 100644 --- a/include/mygl.h +++ b/include/mygl.h @@ -11,8 +11,8 @@ #include #endif #ifdef __APPLE__ -#include -#include +#include +#include #endif //#include //Hopefully nothing needs this remove if it works in windows #include @@ -34,7 +34,7 @@ extern OpenArena::Window g_Screen; //int InitGL(GLvoid); namespace OpenArena { - bool LoadGLTexture(string , GLuint&, GLuint = GL_LINEAR, GLuint = GL_LINEAR); - void FreeGLTexture(GLuint&); + bool LoadGLTexture(string , GLuint, GLuint = GL_LINEAR, GLuint = GL_LINEAR); + void FreeGLTexture(GLuint); }; #endif diff --git a/include/tga.h b/include/tga.h index 7a645fe..083bb1e 100644 --- a/include/tga.h +++ b/include/tga.h @@ -10,7 +10,7 @@ #include #endif #ifdef __APPLE__ -#include +#include #endif #include #include diff --git a/include/window.h b/include/window.h index f31ead7..32439f8 100644 --- a/include/window.h +++ b/include/window.h @@ -10,8 +10,9 @@ #endif #ifdef __APPLE__ -#include -#include +#include +#include +#include #include #include #include @@ -55,7 +56,21 @@ namespace OpenArena Vec2i GetMousePosition(); void SetMousePosition(Vec2i pos); -// #ifdef __linux + #ifdef __linux + Display* GetDisplay(); + + private: + Cursor CreateWindowedCursor(); + Cursor CreateFullscreenCursor(); + int screen; + ::Window window; + GLXContext hRC; + XSetWindowAttributes attributes; + bool doubleBuffered; + XF86VidModeModeInfo vidMode; + int x, y; + Display* display; + #endif #ifdef __APPLE__ Display* GetDisplay(); @@ -90,5 +105,9 @@ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None}; static int attrListDbl[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None}; #endif +#ifdef __APPLE__ +static int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None}; +static int attrListDbl[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None}; +#endif #endif diff --git a/src/Makefile.macosx b/src/Makefile.macosx index f82fdea..38c7b46 100644 --- a/src/Makefile.macosx +++ b/src/Makefile.macosx @@ -3,29 +3,30 @@ CPP = g++ -g INCLUDES = LD = g++ INCLUDEPATH = ../include -INCLUDE_DIRS = -I/System/Library/Frameworks/OpenGL.framework/Headers -LIBRARY_DIRS = -L/System/Library/Frameworks/OpenGL.framework/Libraries -L/usr/X11R6/lib +X11INCLUDEDIR = /usr/X11R6/include +X11LIBDIR = /usr/X11R6/lib +INCLUDE_DIRS = -I$(X11INCLUDEDIR) +LIBRARY_DIRS = -L$(X11LIBDIR) OBJECTS = screen.o bmp.o camera.o ctrls.o level.o mygl.o myglFont.o myglTexture.o physics.o player.o strmanip.o tga.o vector.o window.o keys.o main.o -LIBS = -L/usr/X11R6/lib -lGL -lGLU -lXxf86vm $(INCLUDE_DIRS) +LIBS = $(LIBRARY_DIRS) -lGL -lGLU -lXxf86vm -lX11 LIBRARIES = SO_LIBS = SO_LIBRARIES = oa_game.so oa_audio.so oa_net.so oa_video.so oa_input.so -FRAMEWORK_DIR = /System/Library/Frameworks/ -CPPFLAGS = +CPPFLAGS = $(INCLUDE_DIRS) LDFLAGS = $(LIBS) .Phony: all clean install -all: ../OpenArena/OA +all: ../OpenArena/OpenArena clean: rm -f *.o - rm -f ../OpenArena/OA + if [ -f ../OpenArena/OpenArena ]; then rm ../OpenArena/OpenArena; fi install: #Executables -../OpenArena/OA: $(OBJECTS) - $(LD) $(LDFLAGS) $(INCLUDE_DIRS) -o ../OpenArena/OA $(OBJECTS) +../OpenArena/OpenArena: $(OBJECTS) + $(LD) $(LDFLAGS) $(INCLUDE_DIRS) -o ../OpenArena/OpenArena $(OBJECTS) #Dynamic Libraries oa_game.so: @@ -84,5 +85,5 @@ window.o: window.cpp $(INCLUDEPATH)/window.h keys.o: keys.cpp $(INCLUDEPATH)/keys.h $(CPP) -c $(INCLUDE_DIRS) -o keys.o keys.cpp -main.o: linux.cpp $(INCLUDEPATH)/main.h - $(CPP) -c $(INCLUDE_DIRS) -o main.o linux.cpp +main.o: macosx.cpp $(INCLUDEPATH)/main.h + $(CPP) -c $(INCLUDE_DIRS) -o main.o macosx.cpp diff --git a/src/macosx.cpp b/src/macosx.cpp index 4149f35..ebea24a 100644 --- a/src/macosx.cpp +++ b/src/macosx.cpp @@ -35,9 +35,9 @@ using namespace std; //void InitControls(); -//unsigned char TranslateKey(int keyCode); -//unsigned char TranslateButton(int keyCode); -//void HandleConsoleKeyPress(OpenArena::Keys key); +unsigned char TranslateKey(int keyCode); +unsigned char TranslateButton(int keyCode); +void HandleConsoleKeyPress(OpenArena::Keys key); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Function Definitions @@ -224,7 +224,7 @@ int main(int argc, char** argv) } else { - SetCursorPos(g_Screen.width/2, g_Screen.height/2);//Shit this may be windows specific +// SetMousePosition(g_Screen.width/2, g_Screen.height/2);//Shit this may be windows specific } //Maybe some of these if not almost all should be moved into Level diff --git a/src/mygl.cpp b/src/mygl.cpp index 0905aa5..0b24842 100644 --- a/src/mygl.cpp +++ b/src/mygl.cpp @@ -1,13 +1,12 @@ - #include "../include/mygl.h" namespace OpenArena { - void FreeGLTexture(GLuint& texture) + void FreeGLTexture(GLuint texture) { - glDeleteTextures(1, &texture); + glDeleteTextures(1, texture); } - bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min) + bool LoadGLTexture(string fn, GLuint texture, GLuint mag, GLuint min) { if(Right(tolower(fn), 4) == ".bmp") { diff --git a/src/myglTexture.cpp b/src/myglTexture.cpp index 4338e42..b670e49 100644 --- a/src/myglTexture.cpp +++ b/src/myglTexture.cpp @@ -43,7 +43,7 @@ namespace OpenArena } else { - id=0xFFFFFFFF; + id = 0xFFFFFFFF; return false; } } @@ -81,31 +81,31 @@ namespace OpenArena bool Texture::operator<(const Texture& rtOp) { - return id=(const Texture& rtOp) { - return id>=rtOp.id; + return id>= rtOp.id; } bool Texture::operator>(const Texture& rtOp) { - return id>rtOp.id; + return id> rtOp.id; } }; diff --git a/src/window.cpp b/src/window.cpp index 9903024..e108b3a 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -9,6 +9,15 @@ void OpenArena::Window::SwapBuffers() } } #endif +#ifdef __APPLE__ +void OpenArena::Window::SwapBuffers() +{ + if(doubleBuffered) + { + glXSwapBuffers(display, window); + } +} +#endif #ifdef WIN32 void OpenArena::Window::SwapBuffers() { @@ -37,6 +46,27 @@ void OpenArena::Window::Close() XCloseDisplay(display); } #endif +#ifdef __APPLE__ +void OpenArena::Window::Close() +{ + if(hRC) + { + if(!glXMakeCurrent(display, None, NULL)) + { + printf("Could not release drawing context.\n"); + } + glXDestroyContext(display, hRC); + hRC = NULL; + } + + if(_fullscreen) + { + XF86VidModeSwitchToMode(display, screen, &vidMode); + XF86VidModeSetViewPort(display, screen, 0, 0); + } + XCloseDisplay(display); +} +#endif #ifdef WIN32 void OpenArena::Window::Close() { @@ -111,6 +141,110 @@ bool OpenArena::Window::Open() } } + vi = glXChooseVisual(display, screen, attrListDbl); + if(vi == NULL) + vi = glXChooseVisual(display, screen, attrListSgl); + doubleBuffered = false; + printf("Only Singlebuffered Visual!\n"); + } + else + { + doubleBuffered = true; + printf("Got Doublebuffered Visual!\n"); + } + + glXQueryVersion(display, &glxMajorVersion, & glxMinorVersion); + printf("glX-Version %d.%d\n", glxMajorVersion, glxMinorVersion); + + hRC = glXCreateContext(display, vi, 0, GL_TRUE); + cmap = XCreateColormap(display, RootWindow(display, vi->screen), vi->visual, AllocNone); + attributes.colormap = cmap; + attributes.border_pixel = 0; + + attributes.event_mask = ExposureMask | + KeyPressMask | KeyReleaseMask | + ButtonPressMask | ButtonReleaseMask | +// PointerMotionMask | ButtonMotionMask | + StructureNotifyMask; + + if(_fullscreen) + { + XF86VidModeSwitchToMode(display, screen, modes[bestMode]); + XF86VidModeSetViewPort(display, screen, 0, 0); + XFree(modes); + + attributes.override_redirect = true; + window = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, _width, _height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attributes); + XWarpPointer(display, None, window, 0, 0, 0, 0, 0, 0); + XMapRaised(display, window); + XGrabKeyboard(display, window, true, GrabModeAsync, GrabModeAsync, CurrentTime); + XGrabPointer(display, window, true, ButtonPressMask, GrabModeAsync, GrabModeAsync, window, None, CurrentTime); + XDefineCursor(display, window, CreateFullscreenCursor()); + } + else + { + window = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, _width, _height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &attributes); + wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", true); + XSetWMProtocols(display, window, &wmDelete, 1); + XSetStandardProperties(display, window, GetName(), GetName(), None, NULL, 0, NULL); + XMapRaised(display, window); + XDefineCursor(display, window, CreateWindowedCursor()); + } + + glXMakeCurrent(display, window, hRC); + unsigned int twidth, theight, depth; + XGetGeometry(display, window, &winDummy, &x, &y, &twidth, &theight, &borderDummy, &depth); + _colorDepth = (char)depth; + _height = (short)twidth; + _width = (short)theight; + printf("Resolution %dx%d\n", twidth, theight); + printf("Depth %d\n", depth); + if(glXIsDirect(display, hRC)) + { + printf("Congrats, you have Direct Rendering!\n"); + } + else + { + printf("Sorry, no Direct Rendering possible!\n"); + } + _initializer->Initialize(); + return true; +} +#endif +#ifdef __APPLE__ +bool OpenArena::Window::Open() +{ + XVisualInfo* vi; + Colormap cmap; + int bestMode = 0; + int vidModeMajorVersion; + int vidModeMinorVersion; + int glxMajorVersion; + int glxMinorVersion; + int modeNum; + XF86VidModeModeInfo** modes; + Atom wmDelete; + ::Window winDummy; + unsigned int borderDummy; + + display = XOpenDisplay(0); + screen = DefaultScreen(display); + XF86VidModeQueryVersion(display, &vidModeMajorVersion, &vidModeMinorVersion); + printf("XF86VidModeExtension-Version %d.%d\n", vidModeMajorVersion, vidModeMinorVersion); + + XF86VidModeGetAllModeLines(display, screen, &modeNum, &modes); + vidMode = *modes[0]; + + int i; + for(i=0; ihdisplay == _width) && (modes[i]->vdisplay == _height)) + { + bestMode = i; + } + } + vi = glXChooseVisual(display, screen, attrListDbl); if(vi == NULL) { @@ -178,7 +312,7 @@ bool OpenArena::Window::Open() { printf("Sorry, no Direct Rendering possible!\n"); } - OnInit(); + _initializer->Initialize(); return true; } #endif @@ -301,7 +435,7 @@ bool OpenArena::Window::Open() SetFocus(window); OnResize(_width, _height); - if (!OnInit()) + if (!_initializer->Initialize()) { Close(); MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION); @@ -385,6 +519,13 @@ Display* OpenArena::Window::GetDisplay() } #endif +#ifdef __APPLE__ +Display* OpenArena::Window::GetDisplay() +{ + return display; +} +#endif + #ifdef __linux Vec2i OpenArena::Window::GetMousePosition() { @@ -405,6 +546,26 @@ Vec2i OpenArena::Window::GetMousePosition() } } #endif +#ifdef __APPLE__ +OpenArena::Vec2i OpenArena::Window::GetMousePosition() +{ + ::Window rootWindow; + ::Window childWindow; + int rootX; + int rootY; + int mouseX; + int mouseY; + unsigned int mask; + if(!XQueryPointer(display, window, &rootWindow, &childWindow, &rootX, &rootY, &mouseX, &mouseY, &mask)) + { + return Vec2i(-1,-1); + } + else + { + return Vec2i(mouseX, mouseY); + } +} +#endif #ifdef WIN32 OpenArena::Vec2i OpenArena::Window::GetMousePosition() { @@ -421,6 +582,13 @@ void OpenArena::Window::SetMousePosition(Vec2i pos) XWarpPointer(display, None, window, 0, 0, 0, 0, middle.x, middle.y); } #endif +#ifdef __APPLE__ +void OpenArena::Window::SetMousePosition(Vec2i pos) +{ + Vec2i middle = Vec2i(_width, _height)/2; + XWarpPointer(display, None, window, 0, 0, 0, 0, middle.x, middle.y); +} +#endif #ifdef WIN32 void OpenArena::Window::SetMousePosition(Vec2i pos) { @@ -446,4 +614,22 @@ Cursor OpenArena::Window::CreateFullscreenCursor() return cur; } #endif +#ifdef __APPLE__ +Cursor OpenArena::Window::CreateWindowedCursor() +{ + return CreateFullscreenCursor(); +} + +Cursor OpenArena::Window::CreateFullscreenCursor() +{ + Pixmap pixmap = XCreatePixmap(display, window, 1, 1, 1); + XColor color; + color.pixel = 0; + color.red = 0; + color.flags = DoRed; + Cursor cur = XCreatePixmapCursor(display, pixmap, pixmap, &color, &color, 0, 0); + XFreePixmap(display, pixmap); + return cur; +} +#endif