From 47358fe5ce50a7dfae2db6cd3c3d86ad93eec152 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 24 Dec 2018 17:09:46 +0100 Subject: Tweaks to support OpenGL ES 2.0 desktop --- src/core.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 79404abe..1b975214 100644 --- a/src/core.c +++ b/src/core.c @@ -2247,11 +2247,11 @@ static bool InitGraphicsDevice(int width, int height) //glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers // Check some Window creation flags - if (configFlags & FLAG_WINDOW_RESIZABLE) glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Resizable window - else glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Avoid window being resizable + if (configFlags & FLAG_WINDOW_RESIZABLE) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // Resizable window + else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // Avoid window being resizable - if (configFlags & FLAG_WINDOW_UNDECORATED) glfwWindowHint(GLFW_DECORATED, GL_FALSE); // Border and buttons on Window - else glfwWindowHint(GLFW_DECORATED, GL_TRUE); // Decorated window + if (configFlags & FLAG_WINDOW_UNDECORATED) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // Border and buttons on Window + else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); // Decorated window // FLAG_WINDOW_TRANSPARENT not supported on HTML5 and not included in any released GLFW version yet #if defined(GLFW_TRANSPARENT_FRAMEBUFFER) if (configFlags & FLAG_WINDOW_TRANSPARENT) glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); // Transparent framebuffer @@ -2267,21 +2267,28 @@ static bool InitGraphicsDevice(int width, int height) // Check selection OpenGL version if (rlGetVersion() == OPENGL_21) { - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); // Choose OpenGL major version (just hint) - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); // Choose OpenGL minor version (just hint) + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); // Choose OpenGL major version (just hint) + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); // Choose OpenGL minor version (just hint) } else if (rlGetVersion() == OPENGL_33) { - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Choose OpenGL major version (just hint) - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Choose OpenGL minor version (just hint) + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Choose OpenGL major version (just hint) + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Choose OpenGL minor version (just hint) glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Profiles Hint: Only 3.3 and above! // Values: GLFW_OPENGL_CORE_PROFILE, GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_COMPAT_PROFILE #if defined(__APPLE__) - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // OSX Requires fordward compatibility + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); // OSX Requires fordward compatibility #else - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); // Fordward Compatibility Hint: Only 3.3 and above! + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_FALSE); // Fordward Compatibility Hint: Only 3.3 and above! #endif - //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); // Request OpenGL DEBUG context + //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); // Request OpenGL DEBUG context + } + else if (rlGetVersion() == OPENGL_ES_20) // Request OpenGL ES 2.0 context + { + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); + glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API); // Alternative: GLFW_EGL_CONTEXT_API (ANGLE) } if (fullscreen) @@ -3145,7 +3152,7 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i { if (key == exitKey && action == GLFW_PRESS) { - glfwSetWindowShouldClose(window, GL_TRUE); + glfwSetWindowShouldClose(window, GLFW_TRUE); // NOTE: Before closing window, while loop must be left! } -- cgit v1.2.3 From 01338b0a14f053d281970a32595bc531e8c70885 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 26 Dec 2018 13:26:34 +0100 Subject: WARNING: BREAKING CHANGE Added a bunch of useful text management functions. Consequently, some already available functions like `FormatText()` and `SubText()` has been renamed for consistency. Created temporal fallbacks for old names. raylib version bumped to 2.3. --- src/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 1b975214..6c2713e1 100644 --- a/src/core.c +++ b/src/core.c @@ -3176,17 +3176,17 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i // NOTE: delay represents the time between frames in the gif, if we capture a gif frame every // 10 game frames and each frame trakes 16.6ms (60fps), delay between gif frames should be ~16.6*10. - GifBegin(FormatText("screenrec%03i.gif", screenshotCounter), screenWidth, screenHeight, (int)(GetFrameTime()*10.0f), 8, false); + GifBegin(TextFormat("screenrec%03i.gif", screenshotCounter), screenWidth, screenHeight, (int)(GetFrameTime()*10.0f), 8, false); screenshotCounter++; - TraceLog(LOG_INFO, "Begin animated GIF recording: %s", FormatText("screenrec%03i.gif", screenshotCounter)); + TraceLog(LOG_INFO, "Begin animated GIF recording: %s", TextFormat("screenrec%03i.gif", screenshotCounter)); } } else #endif // SUPPORT_GIF_RECORDING #if defined(SUPPORT_SCREEN_CAPTURE) { - TakeScreenshot(FormatText("screenshot%03i.png", screenshotCounter)); + TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter)); screenshotCounter++; } #endif // SUPPORT_SCREEN_CAPTURE @@ -4454,7 +4454,7 @@ static void LogoAnimation(void) DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha)); - DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha)); + DrawText(TextSubtext("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha)); } EndDrawing(); -- cgit v1.2.3 From 893329886451706033d8af4901cf7c251903a136 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Wed, 2 Jan 2019 10:14:55 +0000 Subject: Added SetMouseOffset - Changed mouseScale to Vector2. - Added SetMouseOffset to change XY of mouseScale. --- src/core.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 6c2713e1..c4f410e4 100644 --- a/src/core.c +++ b/src/core.c @@ -333,7 +333,7 @@ static int defaultKeyboardMode; // Used to store default keyboar // Mouse states static Vector2 mousePosition; // Mouse position on screen -static float mouseScale = 1.0f; // Mouse default scale +static Vector2 mouseScale = { 1.0f }; // Mouse default scale static bool cursorHidden = false; // Track if cursor is hidden static bool cursorOnScreen = false; // Tracks if cursor is inside client area static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -2075,7 +2075,7 @@ int GetMouseX(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)(mousePosition.x*mouseScale); + return (int)(mousePosition.x*mouseScale.x); #endif } @@ -2085,7 +2085,7 @@ int GetMouseY(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)(mousePosition.y*mouseScale); + return (int)(mousePosition.y*mouseScale.y); #endif } @@ -2095,7 +2095,7 @@ Vector2 GetMousePosition(void) #if defined(PLATFORM_ANDROID) return GetTouchPosition(0); #else - return (Vector2){ mousePosition.x*mouseScale, mousePosition.y*mouseScale }; + return (Vector2){ mousePosition.x*mouseScale.x, mousePosition.y*mouseScale.y }; #endif } @@ -2114,7 +2114,16 @@ void SetMousePosition(Vector2 position) void SetMouseScale(float scale) { #if !defined(PLATFORM_ANDROID) - mouseScale = scale; + mouseScale = (Vector2){ scale }; +#endif +} + +// Set mouse scaling +// NOTE: Useful when rendering to different size targets +void SetMouseOffset(Vector2 offset) +{ +#if !defined(PLATFORM_ANDROID) + mouseScale = offset; #endif } @@ -4225,10 +4234,10 @@ static void *EventThread(void *arg) // Screen confinement if (mousePosition.x < 0) mousePosition.x = 0; - if (mousePosition.x > screenWidth/mouseScale) mousePosition.x = screenWidth/mouseScale; + if (mousePosition.x > screenWidth/mouseScale.x) mousePosition.x = screenWidth/mouseScale.x; if (mousePosition.y < 0) mousePosition.y = 0; - if (mousePosition.y > screenHeight/mouseScale) mousePosition.y = screenHeight/mouseScale; + if (mousePosition.y > screenHeight/mouseScale) mousePosition.y = screenHeight/mouseScale.y; // Gesture update if (GestureNeedsUpdate) -- cgit v1.2.3 From a707574f33467f81e8e300e09db23269bf2c1b98 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Wed, 2 Jan 2019 10:46:19 +0000 Subject: Default mouseScale fixed - Didn't set X and Y values correctly. --- src/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index c4f410e4..6c886024 100644 --- a/src/core.c +++ b/src/core.c @@ -333,7 +333,7 @@ static int defaultKeyboardMode; // Used to store default keyboar // Mouse states static Vector2 mousePosition; // Mouse position on screen -static Vector2 mouseScale = { 1.0f }; // Mouse default scale +static Vector2 mouseScale = { 1.0f, 1.0f }; // Mouse default scale static bool cursorHidden = false; // Track if cursor is hidden static bool cursorOnScreen = false; // Tracks if cursor is inside client area static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -2114,7 +2114,7 @@ void SetMousePosition(Vector2 position) void SetMouseScale(float scale) { #if !defined(PLATFORM_ANDROID) - mouseScale = (Vector2){ scale }; + mouseScale = (Vector2){ scale, scale }; #endif } -- cgit v1.2.3 From f9c43dc379165927e847981ec9e14eb5d3b14534 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Wed, 2 Jan 2019 19:09:34 +0000 Subject: Mouse functions changed - SetMouseScale changed to take in a Vector2. - Added mouseOffset global which is used in mouse read functions. --- src/core.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 6c886024..c013a288 100644 --- a/src/core.c +++ b/src/core.c @@ -334,6 +334,7 @@ static int defaultKeyboardMode; // Used to store default keyboar // Mouse states static Vector2 mousePosition; // Mouse position on screen static Vector2 mouseScale = { 1.0f, 1.0f }; // Mouse default scale +static Vector2 mouseOffset = { 0.0f, 0.0f }; // Mouse default scale static bool cursorHidden = false; // Track if cursor is hidden static bool cursorOnScreen = false; // Tracks if cursor is inside client area static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -2075,7 +2076,7 @@ int GetMouseX(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)(mousePosition.x*mouseScale.x); + return (int)((mousePosition.x+mouseOffset.x)*mouseScale.x); #endif } @@ -2085,7 +2086,7 @@ int GetMouseY(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)(mousePosition.y*mouseScale.y); + return (int)((mousePosition.y+mouseOffset.y)*mouseScale.y); #endif } @@ -2095,7 +2096,7 @@ Vector2 GetMousePosition(void) #if defined(PLATFORM_ANDROID) return GetTouchPosition(0); #else - return (Vector2){ mousePosition.x*mouseScale.x, mousePosition.y*mouseScale.y }; + return (Vector2){ (mousePosition.x+mouseOffset.x)*mouseScale.x, (mousePosition.y+mouseOffset.y)*mouseScale.y }; #endif } @@ -2111,14 +2112,14 @@ void SetMousePosition(Vector2 position) // Set mouse scaling // NOTE: Useful when rendering to different size targets -void SetMouseScale(float scale) +void SetMouseScale(Vector2 scale) { #if !defined(PLATFORM_ANDROID) - mouseScale = (Vector2){ scale, scale }; + mouseScale = scale; #endif } -// Set mouse scaling +// Set mouse offset // NOTE: Useful when rendering to different size targets void SetMouseOffset(Vector2 offset) { @@ -4237,7 +4238,7 @@ static void *EventThread(void *arg) if (mousePosition.x > screenWidth/mouseScale.x) mousePosition.x = screenWidth/mouseScale.x; if (mousePosition.y < 0) mousePosition.y = 0; - if (mousePosition.y > screenHeight/mouseScale) mousePosition.y = screenHeight/mouseScale.y; + if (mousePosition.y > screenHeight/mouseScale.y) mousePosition.y = screenHeight/mouseScale.y; // Gesture update if (GestureNeedsUpdate) -- cgit v1.2.3 From d427f17210170b4ae0f185208db504264056d3c1 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 3 Jan 2019 13:53:20 +0100 Subject: REVIEWED some functions parameters Decided to allow user to provide values directly instead of requiring a Vector2 struct, probably more confortable to use. - SetMousePosition() - SetMouseOffset() - SetMouseScale() --- src/core.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index c013a288..f2edc1b6 100644 --- a/src/core.c +++ b/src/core.c @@ -332,9 +332,9 @@ static int defaultKeyboardMode; // Used to store default keyboar #endif // Mouse states -static Vector2 mousePosition; // Mouse position on screen -static Vector2 mouseScale = { 1.0f, 1.0f }; // Mouse default scale -static Vector2 mouseOffset = { 0.0f, 0.0f }; // Mouse default scale +static Vector2 mousePosition = { 0.0f, 0.0f }; // Mouse position on screen +static Vector2 mouseScale = { 1.0f, 1.0f }; // Mouse scaling +static Vector2 mouseOffset = { 0.0f, 0.0f }; // Mouse offset static bool cursorHidden = false; // Track if cursor is hidden static bool cursorOnScreen = false; // Tracks if cursor is inside client area static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -2076,7 +2076,7 @@ int GetMouseX(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)((mousePosition.x+mouseOffset.x)*mouseScale.x); + return (int)((mousePosition.x + mouseOffset.x)*mouseScale.x); #endif } @@ -2086,7 +2086,7 @@ int GetMouseY(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)((mousePosition.y+mouseOffset.y)*mouseScale.y); + return (int)((mousePosition.y + mouseOffset.y)*mouseScale.y); #endif } @@ -2096,36 +2096,32 @@ Vector2 GetMousePosition(void) #if defined(PLATFORM_ANDROID) return GetTouchPosition(0); #else - return (Vector2){ (mousePosition.x+mouseOffset.x)*mouseScale.x, (mousePosition.y+mouseOffset.y)*mouseScale.y }; + return (Vector2){ (mousePosition.x + mouseOffset.x)*mouseScale.x, (mousePosition.y + mouseOffset.y)*mouseScale.y }; #endif } // Set mouse position XY -void SetMousePosition(Vector2 position) +void SetMousePosition(int x, int y) { - mousePosition = position; + mousePosition = (Vector2){ (float)x, (float)y }; #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) // NOTE: emscripten not implemented - glfwSetCursorPos(window, position.x, position.y); + glfwSetCursorPos(window, mousePosition.x, mousePosition.y); #endif } -// Set mouse scaling +// Set mouse offset // NOTE: Useful when rendering to different size targets -void SetMouseScale(Vector2 scale) +void SetMouseOffset(int offsetX, int offsetY) { -#if !defined(PLATFORM_ANDROID) - mouseScale = scale; -#endif + mouseOffset = (Vector2){ (float)offsetX, (float)offsetY }; } -// Set mouse offset +// Set mouse scaling // NOTE: Useful when rendering to different size targets -void SetMouseOffset(Vector2 offset) +void SetMouseScale(float scaleX, float scaleY) { -#if !defined(PLATFORM_ANDROID) - mouseScale = offset; -#endif + mouseScale = (Vector2){ scaleX, scaleY }; } // Returns mouse wheel movement Y -- cgit v1.2.3 From 644eddda11acefe38329cd8fea5b25c1a63ef778 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 3 Jan 2019 13:55:59 +0100 Subject: REMOVED: ShowLogo() Same functionality could be achieved using FLAGS... but also considering removing raylib logo animation... --- src/core.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index f2edc1b6..2d607c3a 100644 --- a/src/core.c +++ b/src/core.c @@ -1461,12 +1461,6 @@ Color Fade(Color color, float alpha) return (Color){color.r, color.g, color.b, (unsigned char)(255.0f*alpha)}; } -// Activate raylib logo at startup (can be done with flags) -void ShowLogo(void) -{ - showLogo = true; -} - // Setup window configuration flags (view FLAGS) void SetConfigFlags(unsigned char flags) { -- cgit v1.2.3 From 0bacc978c39a234da4a2b73ce3cb5b43e072a103 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 4 Jan 2019 15:48:25 +0100 Subject: Corrected issue on web --- src/core.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 2d607c3a..8844b1d3 100644 --- a/src/core.c +++ b/src/core.c @@ -2381,7 +2381,9 @@ static bool InitGraphicsDevice(int width, int height) // Try to disable GPU V-Sync by default, set framerate using SetTargetFPS() // NOTE: V-Sync can be enabled by graphic driver configuration +#if !defined(PLATFORM_WEB) glfwSwapInterval(0); +#endif #if defined(PLATFORM_DESKTOP) // Load OpenGL 3.3 extensions -- cgit v1.2.3 From a41cc08f9b30531a41921100d5a0d257053bd056 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 5 Jan 2019 18:03:09 +0100 Subject: Support screenshots and GIF capturing on Android and Web --- src/core.c | 76 ++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 24 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 8844b1d3..a7ea150b 100644 --- a/src/core.c +++ b/src/core.c @@ -311,7 +311,7 @@ extern EGLNativeWindowType uwpWindow; // Native EGL window handler for static struct android_app *androidApp; // Android activity static struct android_poll_source *source; // Android events polling source static int ident, events; // Android ALooper_pollAll() variables -static const char *internalDataPath; // Android internal data path to write data (/data/data//files) +static const char *internalDataPath = NULL; // Android internal data path to write data (/data/data//files) static bool appEnabled = true; // Used to detec if app is active static bool contextRebindRequired = false; // Used to know context rebind required @@ -1473,17 +1473,32 @@ void SetConfigFlags(unsigned char flags) // NOTE TraceLog() function is located in [utils.h] // Takes a screenshot of current screen (saved a .png) +// NOTE: This function could work in any platform but some platforms: PLATFORM_ANDROID and PLATFORM_WEB +// have their own internal file-systems, to dowload image to user file-system some additional mechanism is required void TakeScreenshot(const char *fileName) { -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) unsigned char *imgData = rlReadScreenPixels(renderWidth, renderHeight); - Image image = { imgData, renderWidth, renderHeight, 1, UNCOMPRESSED_R8G8B8A8 }; - ExportImage(image, fileName); + + char path[512] = { 0 }; +#if defined(PLATFORM_ANDROID) + strcpy(path, internalDataPath); + strcat(path, "/"); + strcat(path, fileName); +#else + strcpy(path, fileName); +#endif + + ExportImage(image, path); free(imgData); - - TraceLog(LOG_INFO, "Screenshot taken: %s", fileName); + +#if defined(PLATFORM_WEB) + // Download file from MEMFS (emscripten memory filesystem) + // SaveFileFromMEMFSToDisk() function is defined in raylib/templates/web_shel/shell.html + emscripten_run_script(TextFormat("SaveFileFromMEMFSToDisk('%s','%s')", GetFileName(path), GetFileName(path))); #endif + + TraceLog(LOG_INFO, "Screenshot taken: %s", path); } // Check if the file exists @@ -1492,11 +1507,10 @@ bool FileExists(const char *fileName) bool result = false; #if defined(_WIN32) - if (_access(fileName, 0) != -1) + if (_access(fileName, 0) != -1) result = true; #else - if (access(fileName, F_OK) != -1) + if (access(fileName, F_OK) != -1) result = true; #endif - result = true; return result; } @@ -1509,7 +1523,7 @@ bool IsFileExtension(const char *fileName, const char *ext) if ((fileExt = strrchr(fileName, '.')) != NULL) { - #if defined(_WIN32) +#if defined(_WIN32) result = true; int extLen = strlen(ext); @@ -1525,9 +1539,9 @@ bool IsFileExtension(const char *fileName, const char *ext) } } else result = false; - #else +#else if (strcmp(fileExt, ext) == 0) result = true; - #endif +#endif } return result; @@ -1729,7 +1743,7 @@ void StorageSaveValue(int position, int value) { FILE *storageFile = NULL; - char path[128]; + char path[512] = { 0 }; #if defined(PLATFORM_ANDROID) strcpy(path, internalDataPath); strcat(path, "/"); @@ -1769,7 +1783,7 @@ int StorageLoadValue(int position) { int value = 0; - char path[128]; + char path[512] = { 0 }; #if defined(PLATFORM_ANDROID) strcpy(path, internalDataPath); strcat(path, "/"); @@ -1814,7 +1828,9 @@ void OpenURL(const char *url) if (strchr(url, '\'') != NULL) { TraceLog(LOG_WARNING, "Provided URL does not seem to be valid."); - } else { + } + else + { char *cmd = calloc(strlen(url) + 10, sizeof(char)); #if defined(_WIN32) @@ -3158,16 +3174,21 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i // NOTE: Before closing window, while loop must be left! } -#if defined(PLATFORM_DESKTOP) else if (key == GLFW_KEY_F12 && action == GLFW_PRESS) { - #if defined(SUPPORT_GIF_RECORDING) +#if defined(SUPPORT_GIF_RECORDING) if (mods == GLFW_MOD_CONTROL) { if (gifRecording) { GifEnd(); gifRecording = false; + + #if defined(PLATFORM_WEB) + // Download file from MEMFS (emscripten memory filesystem) + // SaveFileFromMEMFSToDisk() function is defined in raylib/templates/web_shel/shell.html + emscripten_run_script(TextFormat("SaveFileFromMEMFSToDisk('%s','%s')", TextFormat("screenrec%03i.gif", screenshotCounter - 1), TextFormat("screenrec%03i.gif", screenshotCounter - 1))); + #endif TraceLog(LOG_INFO, "End animated GIF recording"); } @@ -3175,25 +3196,32 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i { gifRecording = true; gifFramesCounter = 0; + + char path[512] = { 0 }; + #if defined(PLATFORM_ANDROID) + strcpy(path, internalDataPath); + strcat(path, TextFormat("/screenrec%03i.gif", screenshotCounter)); + #else + strcpy(path, TextFormat("/screenrec%03i.gif", screenshotCounter)); + #endif // NOTE: delay represents the time between frames in the gif, if we capture a gif frame every // 10 game frames and each frame trakes 16.6ms (60fps), delay between gif frames should be ~16.6*10. - GifBegin(TextFormat("screenrec%03i.gif", screenshotCounter), screenWidth, screenHeight, (int)(GetFrameTime()*10.0f), 8, false); + GifBegin(path, screenWidth, screenHeight, (int)(GetFrameTime()*10.0f), 8, false); screenshotCounter++; TraceLog(LOG_INFO, "Begin animated GIF recording: %s", TextFormat("screenrec%03i.gif", screenshotCounter)); } } else - #endif // SUPPORT_GIF_RECORDING - #if defined(SUPPORT_SCREEN_CAPTURE) +#endif // SUPPORT_GIF_RECORDING +#if defined(SUPPORT_SCREEN_CAPTURE) { TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter)); screenshotCounter++; } - #endif // SUPPORT_SCREEN_CAPTURE +#endif // SUPPORT_SCREEN_CAPTURE } -#endif // PLATFORM_DESKTOP else { currentKeyState[key] = action; @@ -3375,11 +3403,11 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd) // Init hi-res timer InitTimer(); - #if defined(SUPPORT_DEFAULT_FONT) + #if defined(SUPPORT_DEFAULT_FONT) // Load default font // NOTE: External function (defined in module: text) LoadDefaultFont(); - #endif + #endif // TODO: GPU assets reload in case of lost focus (lost context) // NOTE: This problem has been solved just unbinding and rebinding context from display -- cgit v1.2.3 From 8bc4050377221e85e0e270b01fc14ba669d90cb7 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sat, 27 Oct 2018 11:11:54 +0200 Subject: Revert "core: workaround window not being rendered till moved on macOS Mojave" This reverts commit 1fe6d9fc06156257d5210cfa71ecb839fb190722. Because upstream GLFW now contains a fix. --- src/core.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index a7ea150b..1c703e5b 100644 --- a/src/core.c +++ b/src/core.c @@ -175,11 +175,9 @@ #include // Required for: glfwGetX11Window() #elif defined(__APPLE__) #include // Required for: usleep() - #include // Required for: objc_msgsend(), sel_registerName() //#define GLFW_EXPOSE_NATIVE_COCOA // WARNING: Fails due to type redefinition - #define GLFW_EXPOSE_NATIVE_NSGL - #include // Required for: glfwGetCocoaWindow(), glfwGetNSGLContext() + #include // Required for: glfwGetCocoaWindow() #endif #endif @@ -277,10 +275,6 @@ 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 - static unsigned int displayWidth, displayHeight;// Display width and height (monitor, device-screen, LCD, ...) static int screenWidth, screenHeight; // Screen width and height (used render area) static int renderWidth, renderHeight; // Framebuffer width and height (render area, including black bars if required) @@ -3135,16 +3129,6 @@ 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) -- cgit v1.2.3