From a56b3c21942737208a4f54f869b239b1d293cb00 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 7 Oct 2018 00:33:05 +0200 Subject: [PATCH 1/3] CMake: suppress OpenGL deprecation warnings on macOS Mojave A single warning at configuration time is enough. --- src/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c86cc0e7..a8d8635f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,6 +73,10 @@ if(${PLATFORM} MATCHES "Desktop") find_library(OPENGL_LIBRARY OpenGL) set(LIBS_PRIVATE ${OPENGL_LIBRARY}) link_libraries("${LIBS_PRIVATE}") + if (NOT CMAKE_SYSTEM STRLESS "Darwin-18.0.0") + add_definitions(-DGL_SILENCE_DEPRECATION) + MESSAGE(AUTHOR_WARNING "OpenGL is deprecated starting with macOS 10.14 (Mojave)!") + endif() elseif(WIN32) add_definitions(-D_CRT_SECURE_NO_WARNINGS) else() From 6572d5ff8c3299d3915f2b3155ef2275baa971fd Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 7 Oct 2018 00:34:50 +0200 Subject: [PATCH 2/3] raylib.h: include if available Previously, if was #included prior to another header that defined bool, the compilation would fail. This is e.g. the case for and which both fall back to the if C99 is available. The following commit includes in src/core.c, which causes the same problem. Avoid this by checking for C99 bool like we already do for C++'s. --- src/raylib.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index 17c4234e..20a3ca26 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -354,11 +354,11 @@ //---------------------------------------------------------------------------------- // Structures Definition //---------------------------------------------------------------------------------- -#ifndef __cplusplus // Boolean type - #ifndef bool - typedef enum { false, true } bool; - #endif +#if defined(__STDC__) && __STDC_VERSION__ >= 199901L + #include +#elif !defined(__cplusplus) && !defined(bool) + typedef enum { false, true } bool; #endif // Vector2 type From 1fe6d9fc06156257d5210cfa71ecb839fb190722 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 7 Oct 2018 00:47:57 +0200 Subject: [PATCH 3/3] core: workaround window not being rendered till moved on macOS Mojave Apple ought to fix their OpenGL implementation, but with OpenGL now deprecated this might not happen. This has been reported upstream in GLFW in glfw/glfw#1334. The workaround comes from kovidgoyal/kitty@b82e74f99 This also fixes the HiDPI (Retina) scaling issues reported in #497, so the workaround is enabled anywhere __APPLE__ is defined. --- src/core.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/core.c b/src/core.c index 203da4d9..558cc854 100644 --- a/src/core.c +++ b/src/core.c @@ -134,12 +134,6 @@ #define CHDIR chdir #endif -#if defined(__linux__) || defined(PLATFORM_WEB) - #include // Required for: timespec, nanosleep(), select() - POSIX -#elif defined(__APPLE__) - #include // Required for: usleep() -#endif - #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) #if defined(PLATFORM_WEB) #define GLFW_INCLUDE_ES2 @@ -155,6 +149,15 @@ #endif #endif +#if defined(__linux__) || defined(PLATFORM_WEB) + #include // Required for: timespec, nanosleep(), select() - POSIX +#elif defined(__APPLE__) + #include // Required for: usleep() + #include // Required for: objc_msgsend(), sel_registerName() + #define GLFW_EXPOSE_NATIVE_NSGL + #include // Required for: glfwGetNSGLContext() +#endif + #if defined(PLATFORM_ANDROID) //#include // Android sensors functions (accelerometer, gyroscope, light...) #include // Defines AWINDOW_FLAG_FULLSCREEN and others @@ -233,6 +236,11 @@ static bool windowReady = false; // Check if window has been init static bool windowMinimized = false; // Check if window has been minimized static const char *windowTitle = NULL; // Window text title... +#if defined(__APPLE__) +static int windowNeedsUpdating = 2; // Times the Cocoa window needs to be updated initially +#endif + + #if defined(PLATFORM_ANDROID) static struct android_app *androidApp; // Android activity static struct android_poll_source *source; // Android events polling source @@ -2870,6 +2878,15 @@ static void SwapBuffers(void) { #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) glfwSwapBuffers(window); +#if __APPLE__ + // workaround for missing/erroneous initial rendering on macOS + if (windowNeedsUpdating) { + // Desugared version of Objective C: [glfwGetNSGLContext(window) update] + ((id (*)(id, SEL))objc_msgSend)(glfwGetNSGLContext(window), + sel_registerName("update")); + windowNeedsUpdating--; + } +#endif #endif #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(PLATFORM_UWP)