Changed: Cleaned up the linux portion of the code
Changed: Finished updating the linux portion of the code with the previous changes to OpenArena::Window ~g2k
This commit is contained in:
@@ -3,7 +3,7 @@ CPP = g++ -g
|
||||
INCLUDES =
|
||||
LD = g++
|
||||
INCLUDEPATH = ../include
|
||||
OBJECTS = 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
|
||||
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
|
||||
LIBRARIES =
|
||||
SO_LIBS =
|
||||
@@ -34,6 +34,9 @@ oa_video.so:
|
||||
|
||||
oa_input.so:
|
||||
|
||||
screen.o: screen.cpp $(INCLUDEPATH)/screen.h
|
||||
$(CPP) -c -o screen.o screen.cpp
|
||||
|
||||
bmp.o: bmp.cpp $(INCLUDEPATH)/bmp.h $(INCLUDEPATH)/mygl.h $(INCLUDEPATH)/datatypes.h $(INCLUDEPATH)/texture.h
|
||||
$(CPP) -c -o bmp.o bmp.cpp
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ namespace OpenArena
|
||||
Vec2i middle;
|
||||
double angleZ;
|
||||
|
||||
middle.x = window.width/2;
|
||||
middle.y = window.height/2;
|
||||
middle.x = window.GetWidth()/2;
|
||||
middle.y = window.GetHeight()/2;
|
||||
pos = window.GetMousePosition();
|
||||
if(pos != middle)
|
||||
{
|
||||
|
||||
@@ -120,7 +120,7 @@ int main(int argc, char** argv)
|
||||
|
||||
InitControls();
|
||||
|
||||
level.glFont.SetScreenDimensions(level.screen.width*2, level.screen.height*2);
|
||||
level.glFont.SetScreenDimensions(level.screen.GetWidth()*2, level.screen.GetHeight()*2);
|
||||
|
||||
if(level.nextLevel == "")
|
||||
{
|
||||
@@ -132,15 +132,15 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
//Hack for now
|
||||
if(level.screen.bpp == 32)
|
||||
if(level.screen.GetColorDepth() == 32)
|
||||
{
|
||||
level.screen.bpp = 24;
|
||||
level.screen.SetColorDepth(24);
|
||||
}
|
||||
|
||||
g_Screen.SetOnInit(InitGL);
|
||||
g_Screen.SetOnResize(ResizeGLScene);
|
||||
|
||||
if(!g_Screen.Open(OPENARENA_VERSION, level.screen.width, level.screen.height, level.screen.bpp, level.screen.fullscreen))
|
||||
if(!g_Screen.Open(OPENARENA_VERSION, level.screen.GetWidth(), level.screen.GetHeight(), level.screen.GetColorDepth(), level.screen.GetFullscreen()))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -161,10 +161,10 @@ int main(int argc, char** argv)
|
||||
DrawGLScene();
|
||||
break;
|
||||
case ConfigureNotify:
|
||||
if((event.xconfigure.width != g_Screen.width) || (event.xconfigure.height != g_Screen.height))
|
||||
if((event.xconfigure.width != g_Screen.GetWidth()) || (event.xconfigure.height != g_Screen.GetHeight()))
|
||||
{
|
||||
g_Screen.width = event.xconfigure.width;
|
||||
g_Screen.height = event.xconfigure.height;
|
||||
g_Screen.SetWidth(event.xconfigure.width);
|
||||
g_Screen.SetHeight(event.xconfigure.height);
|
||||
ResizeGLScene(event.xconfigure.width, event.xconfigure.height);
|
||||
}
|
||||
break;
|
||||
@@ -210,7 +210,7 @@ int main(int argc, char** argv)
|
||||
else if(keys[OpenArena::KEY_F1])
|
||||
{
|
||||
g_Screen.Close();
|
||||
g_Screen.fullscreen = !g_Screen.fullscreen;
|
||||
g_Screen.ToggleFullscreen();
|
||||
g_Screen.Open();
|
||||
}
|
||||
else
|
||||
@@ -517,8 +517,8 @@ int main(int argc, char** argv)
|
||||
{
|
||||
keys[OpenArena::KEY_F1] = false;
|
||||
g_Screen.Close();
|
||||
g_Screen.fullscreen = !g_Screen.fullscreen;
|
||||
if(!g_Screen.Open(OPENARENA_VERSION, level.screen.width, level.screen.height, level.screen.bpp, level.screen.fullscreen))
|
||||
g_Screen.ToggleFullscreen();
|
||||
if(!g_Screen.Open(OPENARENA_VERSION, level.screen.GetWidth(), level.screen.GetHeight(), level.screen.GetColorDepth(), level.screen.GetFullscreen()))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -76,4 +76,4 @@ namespace OpenArena
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
287
src/window.cpp
287
src/window.cpp
@@ -1,20 +1,45 @@
|
||||
#include "../include/window.h"
|
||||
|
||||
#ifdef __linux
|
||||
void OpenArena::Window::SwapBuffers()
|
||||
{
|
||||
#ifdef __linux
|
||||
if(doubleBuffered)
|
||||
{
|
||||
glXSwapBuffers(display, window);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
void OpenArena::Window::SwapBuffers()
|
||||
{
|
||||
::SwapBuffers(deviceContext);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux
|
||||
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()
|
||||
{
|
||||
if (_fullscreen)
|
||||
{
|
||||
ChangeDisplaySettings(NULL, 0);
|
||||
@@ -49,31 +74,115 @@ void OpenArena::Window::Close()
|
||||
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
|
||||
instance=NULL;
|
||||
}
|
||||
#endif
|
||||
#ifdef __linux
|
||||
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
|
||||
}//End OpenArena::Window::Close()
|
||||
#endif
|
||||
|
||||
#ifdef __linux
|
||||
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; i<modeNum; i++)
|
||||
{
|
||||
//Add a check for colordepth here
|
||||
if((modes[i]->hdisplay == _width) && (modes[i]->vdisplay == _height))
|
||||
{
|
||||
bestMode = i;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
OnInit();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
bool OpenArena::Window::Open()
|
||||
{
|
||||
#ifdef WIN32
|
||||
unsigned int PixelFormat;
|
||||
WNDCLASS wc;
|
||||
DWORD dwExStyle;
|
||||
@@ -198,109 +307,8 @@ bool OpenArena::Window::Open()
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
#ifdef __linux
|
||||
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; i<modeNum; i++)
|
||||
{
|
||||
//Add a check for colordepth here
|
||||
if((modes[i]->hdisplay == width) && (modes[i]->vdisplay == height))
|
||||
{
|
||||
bestMode = i;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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, name.c_str(), name.c_str(), None, NULL, 0, NULL);
|
||||
XMapRaised(display, window);
|
||||
}
|
||||
|
||||
glXMakeCurrent(display, window, hRC);
|
||||
unsigned int twidth, theight, depth;
|
||||
XGetGeometry(display, window, &winDummy, &x, &y, &twidth, &theight, &borderDummy, &depth);
|
||||
bpp = (char)depth;
|
||||
height = (short)twidth;
|
||||
width = (short)theight;
|
||||
printf("Resolution %dx%d\n", twidth, theight);
|
||||
printf("Depth %d\n", bpp);
|
||||
if(glXIsDirect(display, hRC))
|
||||
{
|
||||
printf("Congrats, you have Direct Rendering!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Sorry, no Direct Rendering possible!\n");
|
||||
}
|
||||
OnInit();
|
||||
return true;
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
bool OpenArena::Window::Open(string title, int width, int height, int bits, bool fullscreenflag)
|
||||
{
|
||||
@@ -345,11 +353,11 @@ int OpenArena::DefaultInit()
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void OpenArena::DefaultResize(GLsizei width, GLsizei height)
|
||||
{
|
||||
//TODO see if this really needs to be os specific
|
||||
#ifdef WIN32
|
||||
if (height==0)
|
||||
height=1;
|
||||
@@ -364,6 +372,7 @@ void OpenArena::DefaultResize(GLsizei width, GLsizei height)
|
||||
glLoadIdentity();
|
||||
#endif
|
||||
#ifdef __linux
|
||||
//TODO Implement this
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -379,11 +388,9 @@ Display* OpenArena::Window::GetDisplay()
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __linux
|
||||
Vec2i OpenArena::Window::GetMousePosition()
|
||||
{
|
||||
#ifdef __linux
|
||||
|
||||
::Window rootWindow;
|
||||
::Window childWindow;
|
||||
int rootX;
|
||||
@@ -399,21 +406,27 @@ Vec2i OpenArena::Window::GetMousePosition()
|
||||
{
|
||||
return Vec2i(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
POINT pos;
|
||||
Vec2i OpenArena::Window::GetMousePosition()
|
||||
{
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
return Vec2i(pos.x, pos.y);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux
|
||||
void OpenArena::Window::SetMousePosition(Vec2i pos)
|
||||
{
|
||||
#ifdef __linux
|
||||
Vec2i middle = Vec2i(width, height)/2;
|
||||
Vec2i middle = Vec2i(_width, _height)/2;
|
||||
XWarpPointer(display, None, window, 0, 0, 0, 0, middle.x, middle.y);
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
SetCursorPos(pos.x, pos.y);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
void OpenArena::Window::SetMousePosition(Vec2i pos)
|
||||
{
|
||||
SetCursorPos(pos.x, pos.y);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user