diff --git a/src/debug.h b/src/debug.h index b05da50..4a53801 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() { @@ -557,10 +578,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); 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 diff --git a/src/platform/nix/main.cpp b/src/platform/nix/main.cpp index 9675f7a..1f723b6 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) diff --git a/src/utils.h b/src/utils.h index faf123e..d55b9a7 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