From 8150cb82f5ace000dfdea65a2bda31f7a8e8fdd8 Mon Sep 17 00:00:00 2001 From: adler3d Date: Thu, 1 Jun 2017 15:47:19 +0400 Subject: [PATCH 1/5] Update main.cpp --- src/platform/nix/main.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/platform/nix/main.cpp b/src/platform/nix/main.cpp index 1d686f4..c145465 100644 --- a/src/platform/nix/main.cpp +++ b/src/platform/nix/main.cpp @@ -99,7 +99,25 @@ InputKey mouseToInputKey(int btn) { return ikNone; } -void WndProc(const XEvent &e) { +void toggle_fullscreen(Display* dpy, Window win) { + const size_t _NET_WM_STATE_TOGGLE=2; + + XEvent xev; + Atom wm_state = XInternAtom(dpy, "_NET_WM_STATE", False); + Atom scr_full = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = win; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = _NET_WM_STATE_TOGGLE; + xev.xclient.data.l[1] = scr_full; + + XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureNotifyMask, &xev); +} + +void WndProc(const XEvent &e,Display*dpy,Window wnd) { switch (e.type) { case ConfigureNotify : Core::width = e.xconfigure.width; @@ -108,7 +126,7 @@ void WndProc(const XEvent &e) { case KeyPress : case KeyRelease : if (e.type == KeyPress && (e.xkey.state & Mod1Mask) && e.xkey.keycode == 36) { - // TODO: windowed <-> fullscreen switch + toggle_fullscreen(dpy,wnd); break; } Input::setDown(keyToInputKey(e.xkey.keycode), e.type == KeyPress); @@ -183,7 +201,7 @@ int main() { XNextEvent(dpy, &event); if (event.type == ClientMessage && *event.xclient.data.l == WM_DELETE_WINDOW) break; - WndProc(event); + WndProc(event,dpy,wnd); } else { int time = getTime(); if (time <= lastTime) From d11c62aa5ed290fae93cf287866b0a122a613063 Mon Sep 17 00:00:00 2001 From: adler3d Date: Thu, 1 Jun 2017 15:50:33 +0400 Subject: [PATCH 2/5] Update build.sh --- src/platform/nix/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platform/nix/build.sh b/src/platform/nix/build.sh index 9ebf532..000092d 100755 --- a/src/platform/nix/build.sh +++ b/src/platform/nix/build.sh @@ -1,2 +1,3 @@ +set -e clang++ -std=c++11 -Os -s -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections -DNDEBUG main.cpp ../../libs/stb_vorbis/stb_vorbis.c -I../../ -o../../../bin/OpenLara -lX11 -lGL -lm -lpthread -lpulse-simple -lpulse strip ../../../bin/OpenLara --strip-all --remove-section=.comment --remove-section=.note From f408f179d257feb6795401db4fa0c1fcc357db81 Mon Sep 17 00:00:00 2001 From: Gemma Peter Date: Fri, 2 Jun 2017 01:21:10 +0100 Subject: [PATCH 3/5] debugBreak function for Linux --- src/utils.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils.h b/src/utils.h index b8241df..3d9312e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -7,7 +7,12 @@ #include #ifdef _DEBUG - #define debugBreak() _asm { int 3 } + #ifdef LINUX + #define debugBreak() raise(SIGTRAP); + #else + #define debugBreak() _asm { int 3 } + #endif + #define ASSERT(expr) if (expr) {} else { LOG("ASSERT %s in %s:%d\n", #expr, __FILE__, __LINE__); debugBreak(); } #ifndef ANDROID From 8e994211d2450e9638233ad7d3e67692c263e2b4 Mon Sep 17 00:00:00 2001 From: Gemma Peter Date: Fri, 2 Jun 2017 01:45:09 +0100 Subject: [PATCH 4/5] Prevent type errors when compiling with GCC --- src/debug.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/debug.h b/src/debug.h index 1e19566..58a3c7f 100644 --- a/src/debug.h +++ b/src/debug.h @@ -557,10 +557,10 @@ namespace Debug { uint32 data; uint32 dataSize; } header = { - FOURCC("RIFF"), sizeof(Header) - 8 + dataSize, + FOURCC("RIFF"), (uint32) sizeof(Header) - 8 + dataSize, FOURCC("WAVE"), FOURCC("fmt "), 16, { 1, 1, 44100, 44100 * 16 / 8, 0, 16 }, - FOURCC("data"), dataSize + FOURCC("data"), (uint32) dataSize }; fwrite(&header, sizeof(header), 1, f); From e76f38b1e4f749848e54ed693e1a3a0512790e01 Mon Sep 17 00:00:00 2001 From: Gemma Peter Date: Fri, 2 Jun 2017 01:57:41 +0100 Subject: [PATCH 5/5] Debug text font setup for Linux --- src/debug.h | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/debug.h b/src/debug.h index 58a3c7f..ebce4f0 100644 --- a/src/debug.h +++ b/src/debug.h @@ -11,15 +11,36 @@ namespace Debug { static GLuint font; void init() { - font = glGenLists(256); - HDC hdc = GetDC(0); - HFONT hfont = CreateFontA(-MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72), 0, - 0, 0, FW_BOLD, 0, 0, 0, - ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, - ANTIALIASED_QUALITY, DEFAULT_PITCH, "Courier New"); - SelectObject(hdc, hfont); - wglUseFontBitmaps(hdc, 0, 256, font); - DeleteObject(hfont); + #ifdef WIN32 + font = glGenLists(256); + HDC hdc = GetDC(0); + HFONT hfont = CreateFontA(-MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72), 0, + 0, 0, FW_BOLD, 0, 0, 0, + ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, + ANTIALIASED_QUALITY, DEFAULT_PITCH, "Courier New"); + SelectObject(hdc, hfont); + wglUseFontBitmaps(hdc, 0, 256, font); + DeleteObject(hfont); + #elif LINUX + XFontStruct *fontInfo; + Font id; + unsigned int first, last; + fontInfo = XLoadQueryFont(glXGetCurrentDisplay(), "-adobe-times-medium-r-normal--17-120-100-100-p-88-iso8859-1"); + + if (fontInfo == NULL) { + LOG("no font found\n"); + } + + id = fontInfo->fid; + first = fontInfo->min_char_or_byte2; + last = fontInfo->max_char_or_byte2; + + font = glGenLists(last + 1); + if (font == 0) { + LOG("out of display lists\n"); + } + glXUseXFont(id, first, last - first + 1, font + first); + #endif } void free() {