diff --git a/examples/core/core_2d_camera.c b/examples/core/core_2d_camera.c index 44d3c6961..07766e0fb 100644 --- a/examples/core/core_2d_camera.c +++ b/examples/core/core_2d_camera.c @@ -14,6 +14,7 @@ ********************************************************************************************/ #include "raylib.h" +#include #define MAX_BUILDINGS 100 @@ -44,7 +45,11 @@ int main(void) spacing += (int)buildings[i].width; - buildColors[i] = (Color){ GetRandomValue(200, 240), GetRandomValue(200, 240), GetRandomValue(200, 250), 255 }; + buildColors[i] = (Color){ + (unsigned char)GetRandomValue(200, 240), + (unsigned char)GetRandomValue(200, 240), + (unsigned char)GetRandomValue(200, 250), + 255}; } Camera2D camera = { 0 }; @@ -77,7 +82,8 @@ int main(void) else if (camera.rotation < -40) camera.rotation = -40; // Camera zoom controls - camera.zoom += ((float)GetMouseWheelMove()*0.05f); + // Uses log scaling to provide consistent zoom speed + camera.zoom = expf(logf(camera.zoom) + ((float)GetMouseWheelMove()*0.1f)); if (camera.zoom > 3.0f) camera.zoom = 3.0f; else if (camera.zoom < 0.1f) camera.zoom = 0.1f; diff --git a/examples/core/core_2d_camera_mouse_zoom.c b/examples/core/core_2d_camera_mouse_zoom.c index cfdaf15aa..31aa7bc6b 100644 --- a/examples/core/core_2d_camera_mouse_zoom.c +++ b/examples/core/core_2d_camera_mouse_zoom.c @@ -73,9 +73,9 @@ int main () camera.target = mouseWorldPos; // Zoom increment - float scaleFactor = 1.0f + (0.25f*fabsf(wheel)); - if (wheel < 0) scaleFactor = 1.0f/scaleFactor; - camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f); + // Uses log scaling to provide consistent zoom speed + float scale = 0.2f*wheel; + camera.zoom = Clamp(expf(logf(camera.zoom)+scale), 0.125f, 64.0f); } } else @@ -96,10 +96,10 @@ int main () if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) { // Zoom increment + // Uses log scaling to provide consistent zoom speed float deltaX = GetMouseDelta().x; - float scaleFactor = 1.0f + (0.01f*fabsf(deltaX)); - if (deltaX < 0) scaleFactor = 1.0f/scaleFactor; - camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f); + float scale = 0.005f*deltaX; + camera.zoom = Clamp(expf(logf(camera.zoom)+scale), 0.125f, 64.0f); } } //---------------------------------------------------------------------------------- @@ -143,4 +143,4 @@ int main () CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; -} \ No newline at end of file +} diff --git a/src/config.h b/src/config.h index f7b015305..ca54fa8cd 100644 --- a/src/config.h +++ b/src/config.h @@ -136,8 +136,8 @@ #define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported -#define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance -#define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance +#define RL_CULL_DISTANCE_NEAR 0.001 // Default projection matrix near cull distance +#define RL_CULL_DISTANCE_FAR 10000.0 // Default projection matrix far cull distance // Default shader vertex attribute locations #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION 0 diff --git a/src/external/jar_xm.h b/src/external/jar_xm.h index b5e80e48a..174c1704c 100644 --- a/src/external/jar_xm.h +++ b/src/external/jar_xm.h @@ -232,6 +232,13 @@ uint64_t jar_xm_get_remaining_samples(jar_xm_context_t* ctx); #include #include +#ifdef DEBUG + // Undefine DEBUG to avoid external redefinition warnings/conflicts + // This is probably a common definition for + // many external build systems' debug configurations + #undef DEBUG +#endif + #if JAR_XM_DEBUG //JAR_XM_DEBUG defined as 0 #include #define DEBUG(fmt, ...) do { \ diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c index 5445b1029..eac7f3256 100644 --- a/src/platforms/rcore_android.c +++ b/src/platforms/rcore_android.c @@ -859,7 +859,7 @@ static int InitGraphicsDevice(void) EGL_GREEN_SIZE, 8, // GREEN color bit depth (alternative: 6) EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5) //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI) - EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!) + EGL_DEPTH_SIZE, 24, // Depth buffer size (Required to use Depth testing!) //EGL_STENCIL_SIZE, 8, // Stencil buffer size EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index dbe8d6f55..19ee78bf4 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1741,7 +1741,7 @@ static void ErrorCallback(int error, const char *description) } // GLFW3 WindowSize Callback, runs when window is resizedLastFrame -// NOTE: Window resizing not allowed by default +// NOTE: Window resizing not enabled by default, use SetConfigFlags() static void WindowSizeCallback(GLFWwindow *window, int width, int height) { // Reset viewport and projection matrix for new size @@ -1753,12 +1753,22 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height) if (IsWindowFullscreen()) return; - // Set current screen size + // if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale + if (IsWindowState(FLAG_WINDOW_HIGHDPI)) + { + width = (int)(width/GetWindowScaleDPI().x); + height = (int)(height/GetWindowScaleDPI().y); + } + + // Set render size + CORE.Window.render.width = width; + CORE.Window.render.height = height; + // Set current screen size CORE.Window.screen.width = width; CORE.Window.screen.height = height; - // NOTE: Postprocessing texture is not scaled to new size + // WARNING: If using a render texture, it is not scaled to new size } static void WindowPosCallback(GLFWwindow* window, int x, int y) { diff --git a/src/platforms/rcore_desktop_rgfw.c b/src/platforms/rcore_desktop_rgfw.c index fe521587f..aafe28a66 100644 --- a/src/platforms/rcore_desktop_rgfw.c +++ b/src/platforms/rcore_desktop_rgfw.c @@ -76,14 +76,14 @@ void CloseWindow(void); #if defined(_WIN32) || defined(_WIN64) #define WIN32_LEAN_AND_MEAN - #define Rectangle rectangle_win32 + #define Rectangle rectangle_win32 #define CloseWindow CloseWindow_win32 #define ShowCursor __imp_ShowCursor - #define _APISETSTRING_ - - #undef MAX_PATH + #define _APISETSTRING_ + + #undef MAX_PATH - __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar); + __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar); #endif #if defined(__APPLE__) @@ -103,8 +103,8 @@ void CloseWindow(void); #undef CloseWindow #undef Rectangle - #undef MAX_PATH - #define MAX_PATH 1025 + #undef MAX_PATH + #define MAX_PATH 1025 #endif #if defined(__APPLE__) @@ -896,23 +896,23 @@ const char *GetKeyName(int key) static KeyboardKey ConvertScancodeToKey(u32 keycode); int RGFW_gpConvTable[18] = { - [RGFW_gamepadY] = GAMEPAD_BUTTON_RIGHT_FACE_UP, - [RGFW_gamepadB] = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, - [RGFW_gamepadA] = GAMEPAD_BUTTON_RIGHT_FACE_DOWN, - [RGFW_gamepadX] = GAMEPAD_BUTTON_RIGHT_FACE_LEFT, - [RGFW_gamepadL1] = GAMEPAD_BUTTON_LEFT_TRIGGER_1, - [RGFW_gamepadR1] = GAMEPAD_BUTTON_RIGHT_TRIGGER_1, - [RGFW_gamepadL2] = GAMEPAD_BUTTON_LEFT_TRIGGER_2, - [RGFW_gamepadR2] = GAMEPAD_BUTTON_RIGHT_TRIGGER_2, - [RGFW_gamepadSelect] = GAMEPAD_BUTTON_MIDDLE_LEFT, - [RGFW_gamepadHome] = GAMEPAD_BUTTON_MIDDLE, - [RGFW_gamepadStart] = GAMEPAD_BUTTON_MIDDLE_RIGHT, - [RGFW_gamepadUp] = GAMEPAD_BUTTON_LEFT_FACE_UP, - [RGFW_gamepadRight] = GAMEPAD_BUTTON_LEFT_FACE_RIGHT, - [RGFW_gamepadDown] = GAMEPAD_BUTTON_LEFT_FACE_DOWN, - [RGFW_gamepadLeft] = GAMEPAD_BUTTON_LEFT_FACE_LEFT, - [RGFW_gamepadL3] = GAMEPAD_BUTTON_LEFT_THUMB, - [RGFW_gamepadR3] = GAMEPAD_BUTTON_RIGHT_THUMB, + [RGFW_gamepadY] = GAMEPAD_BUTTON_RIGHT_FACE_UP, + [RGFW_gamepadB] = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, + [RGFW_gamepadA] = GAMEPAD_BUTTON_RIGHT_FACE_DOWN, + [RGFW_gamepadX] = GAMEPAD_BUTTON_RIGHT_FACE_LEFT, + [RGFW_gamepadL1] = GAMEPAD_BUTTON_LEFT_TRIGGER_1, + [RGFW_gamepadR1] = GAMEPAD_BUTTON_RIGHT_TRIGGER_1, + [RGFW_gamepadL2] = GAMEPAD_BUTTON_LEFT_TRIGGER_2, + [RGFW_gamepadR2] = GAMEPAD_BUTTON_RIGHT_TRIGGER_2, + [RGFW_gamepadSelect] = GAMEPAD_BUTTON_MIDDLE_LEFT, + [RGFW_gamepadHome] = GAMEPAD_BUTTON_MIDDLE, + [RGFW_gamepadStart] = GAMEPAD_BUTTON_MIDDLE_RIGHT, + [RGFW_gamepadUp] = GAMEPAD_BUTTON_LEFT_FACE_UP, + [RGFW_gamepadRight] = GAMEPAD_BUTTON_LEFT_FACE_RIGHT, + [RGFW_gamepadDown] = GAMEPAD_BUTTON_LEFT_FACE_DOWN, + [RGFW_gamepadLeft] = GAMEPAD_BUTTON_LEFT_FACE_LEFT, + [RGFW_gamepadL3] = GAMEPAD_BUTTON_LEFT_THUMB, + [RGFW_gamepadR3] = GAMEPAD_BUTTON_RIGHT_THUMB, }; // Register all input events @@ -923,7 +923,7 @@ void PollInputEvents(void) // because ProcessGestureEvent() is just called on an event, not every frame UpdateGestures(); #endif - + // Reset keys/chars pressed registered CORE.Input.Keyboard.keyPressedQueueCount = 0; CORE.Input.Keyboard.charPressedQueueCount = 0; @@ -994,7 +994,7 @@ void PollInputEvents(void) RGFW_event *event = &platform.window->event; // All input events can be processed after polling - switch (event->type) + switch (event->type) { case RGFW_mouseEnter: CORE.Input.Mouse.cursorOnScreen = true; break; case RGFW_mouseLeave: CORE.Input.Mouse.cursorOnScreen = false; break; @@ -1015,7 +1015,7 @@ void PollInputEvents(void) CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event->droppedFiles[i]); - + CORE.Window.dropFileCount++; } else if (CORE.Window.dropFileCount < 1024) @@ -1033,8 +1033,19 @@ void PollInputEvents(void) case RGFW_windowResized: { SetupViewport(platform.window->r.w, platform.window->r.h); - CORE.Window.screen.width = platform.window->r.w; - CORE.Window.screen.height = platform.window->r.h; + + // if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale + if (IsWindowState(FLAG_WINDOW_HIGHDPI)) + { + CORE.Window.screen.width = (int)(platform.window->r.w / GetWindowScaleDPI().x); + CORE.Window.screen.height = (int)(platform.window->r.h / GetWindowScaleDPI().y); + } + else + { + CORE.Window.screen.width = platform.window->r.w; + CORE.Window.screen.height = platform.window->r.h; + } + CORE.Window.currentFbo.width = platform.window->r.w; CORE.Window.currentFbo.height = platform.window->r.h; CORE.Window.resizedLastFrame = true; @@ -1168,7 +1179,7 @@ void PollInputEvents(void) } break; case RGFW_gamepadButtonPressed: { - int button = RGFW_gpConvTable[event->button]; + int button = RGFW_gpConvTable[event->button]; if (button >= 0) { @@ -1178,7 +1189,7 @@ void PollInputEvents(void) } break; case RGFW_gamepadButtonReleased: { - int button = RGFW_gpConvTable[event->button]; + int button = RGFW_gpConvTable[event->button]; CORE.Input.Gamepad.currentButtonState[event->gamepad][button] = 0; if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0; @@ -1186,34 +1197,34 @@ void PollInputEvents(void) case RGFW_gamepadAxisMove: { int axis = -1; - float value = 0; + float value = 0; - switch(event->whichAxis) + switch(event->whichAxis) { - case 0: - { - CORE.Input.Gamepad.axisState[event->gamepad][GAMEPAD_AXIS_LEFT_X] = event->axis[0].x / 100.0f; - CORE.Input.Gamepad.axisState[event->gamepad][GAMEPAD_AXIS_LEFT_Y] = event->axis[0].y / 100.0f; - } break; - case 1: - { - CORE.Input.Gamepad.axisState[event->gamepad][GAMEPAD_AXIS_RIGHT_X] = event->axis[1].x / 100.0f; - CORE.Input.Gamepad.axisState[event->gamepad][GAMEPAD_AXIS_RIGHT_Y] = event->axis[1].y / 100.0f; - } break; - case 2: axis = GAMEPAD_AXIS_LEFT_TRIGGER; - case 3: + case 0: + { + CORE.Input.Gamepad.axisState[event->gamepad][GAMEPAD_AXIS_LEFT_X] = event->axis[0].x / 100.0f; + CORE.Input.Gamepad.axisState[event->gamepad][GAMEPAD_AXIS_LEFT_Y] = event->axis[0].y / 100.0f; + } break; + case 1: + { + CORE.Input.Gamepad.axisState[event->gamepad][GAMEPAD_AXIS_RIGHT_X] = event->axis[1].x / 100.0f; + CORE.Input.Gamepad.axisState[event->gamepad][GAMEPAD_AXIS_RIGHT_Y] = event->axis[1].y / 100.0f; + } break; + case 2: axis = GAMEPAD_AXIS_LEFT_TRIGGER; + case 3: { if (axis == -1) axis = GAMEPAD_AXIS_RIGHT_TRIGGER; - int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2; - int pressed = (value > 0.1f); - CORE.Input.Gamepad.currentButtonState[event->gamepad][button] = pressed; - - if (pressed) CORE.Input.Gamepad.lastButtonPressed = button; - else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0; - } - default: break; - } + int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2; + int pressed = (value > 0.1f); + CORE.Input.Gamepad.currentButtonState[event->gamepad][button] = pressed; + + if (pressed) CORE.Input.Gamepad.lastButtonPressed = button; + else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0; + } + default: break; + } } break; default: break; } @@ -1311,14 +1322,14 @@ int InitPlatform(void) CORE.Window.display.width = screenSize.w; CORE.Window.display.height = screenSize.h; #else - CORE.Window.display.width = CORE.Window.screen.width; + CORE.Window.display.width = CORE.Window.screen.width; CORE.Window.display.height = CORE.Window.screen.height; #endif - // TODO: Is this needed by raylib now? + // TODO: Is this needed by raylib now? // If so, rcore_desktop_sdl should be updated too - //SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height); - - if (CORE.Window.flags & FLAG_VSYNC_HINT) RGFW_window_swapInterval(platform.window, 1); + //SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height); + + if (CORE.Window.flags & FLAG_VSYNC_HINT) RGFW_window_swapInterval(platform.window, 1); RGFW_window_makeCurrent(platform.window); // Check surface and context activation @@ -1399,5 +1410,5 @@ static KeyboardKey ConvertScancodeToKey(u32 keycode) { if (keycode > sizeof(keyMappingRGFW)/sizeof(unsigned short)) return 0; - return keyMappingRGFW[keycode]; + return keyMappingRGFW[keycode]; } diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 379091bbf..97145b9dd 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -1451,8 +1451,17 @@ void PollInputEvents(void) const int width = event.window.data1; const int height = event.window.data2; SetupViewport(width, height); - CORE.Window.screen.width = width; - CORE.Window.screen.height = height; + // if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale + if (IsWindowState(FLAG_WINDOW_HIGHDPI)) + { + CORE.Window.screen.width = (int)(width / GetWindowScaleDPI().x); + CORE.Window.screen.height = (int)(height / GetWindowScaleDPI().y); + } + else + { + CORE.Window.screen.width = width; + CORE.Window.screen.height = height; + } CORE.Window.currentFbo.width = width; CORE.Window.currentFbo.height = height; CORE.Window.resizedLastFrame = true; diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index b0a56d6ee..baa51a8d8 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -735,20 +735,24 @@ int InitPlatform(void) #if defined(DEFAULT_GRAPHIC_DEVICE_DRM) platform.fd = open(DEFAULT_GRAPHIC_DEVICE_DRM, O_RDWR); + if (platform.fd != -1) TRACELOG(LOG_INFO, "DISPLAY: Default graphic device DRM opened successfully"); #else - TRACELOG(LOG_INFO, "DISPLAY: No graphic card set, trying platform-gpu-card"); + TRACELOG(LOG_WARNING, "DISPLAY: No graphic card set, trying platform-gpu-card"); platform.fd = open("/dev/dri/by-path/platform-gpu-card", O_RDWR); // VideoCore VI (Raspberry Pi 4) + if (platform.fd != -1) TRACELOG(LOG_INFO, "DISPLAY: platform-gpu-card opened successfully"); if ((platform.fd == -1) || (drmModeGetResources(platform.fd) == NULL)) { - TRACELOG(LOG_INFO, "DISPLAY: Failed to open platform-gpu-card, trying card1"); + TRACELOG(LOG_WARNING, "DISPLAY: Failed to open platform-gpu-card, trying card1"); platform.fd = open("/dev/dri/card1", O_RDWR); // Other Embedded + if (platform.fd != -1) TRACELOG(LOG_INFO, "DISPLAY: card1 opened successfully"); } if ((platform.fd == -1) || (drmModeGetResources(platform.fd) == NULL)) { - TRACELOG(LOG_INFO, "DISPLAY: Failed to open graphic card1, trying card0"); + TRACELOG(LOG_WARNING, "DISPLAY: Failed to open graphic card1, trying card0"); platform.fd = open("/dev/dri/card0", O_RDWR); // VideoCore IV (Raspberry Pi 1-3) + if (platform.fd != -1) TRACELOG(LOG_INFO, "DISPLAY: card0 opened successfully"); } #endif @@ -906,7 +910,7 @@ int InitPlatform(void) EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5) EGL_ALPHA_SIZE, 8, // ALPHA bit depth (required for transparent framebuffer) //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI) - EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!) + EGL_DEPTH_SIZE, 24, // Depth buffer size (Required to use Depth testing!) //EGL_STENCIL_SIZE, 8, // Stencil buffer size EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs) @@ -1399,7 +1403,7 @@ static void ConfigureEvdevDevice(char *device) int fd = open(device, O_RDONLY | O_NONBLOCK); if (fd < 0) { - TRACELOG(LOG_WARNING, "DRM: Failed to open input device: %s", device); + TRACELOG(LOG_WARNING, "SYSTEM: Failed to open input device: %s", device); return; } diff --git a/src/rcore.c b/src/rcore.c index 6739e5f05..864c54b0f 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1119,7 +1119,7 @@ void BeginTextureMode(RenderTexture2D target) //rlScalef(0.0f, -1.0f, 0.0f); // Flip Y-drawing (?) // Setup current width/height for proper aspect ratio - // calculation when using BeginMode3D() + // calculation when using BeginTextureMode() CORE.Window.currentFbo.width = target.texture.width; CORE.Window.currentFbo.height = target.texture.height; CORE.Window.usingFbo = true; @@ -3688,12 +3688,16 @@ static void ScanDirectoryFiles(const char *basePath, FilePathList *files, const (strcmp(dp->d_name, "..") != 0)) { #if defined(_WIN32) - sprintf(path, "%s\\%s", basePath, dp->d_name); + int pathLength = snprintf(path, MAX_FILEPATH_LENGTH - 1, "%s\\%s", basePath, dp->d_name); #else - sprintf(path, "%s/%s", basePath, dp->d_name); + int pathLength = snprintf(path, MAX_FILEPATH_LENGTH - 1, "%s/%s", basePath, dp->d_name); #endif - if (filter != NULL) + if ((pathLength < 0) || (pathLength >= MAX_FILEPATH_LENGTH)) + { + TRACELOG(LOG_WARNING, "FILEIO: Path longer than %d characters (%s...)", MAX_FILEPATH_LENGTH, basePath); + } + else if (filter != NULL) { if (IsPathFile(path)) { @@ -3742,12 +3746,16 @@ static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *fi { // Construct new path from our base path #if defined(_WIN32) - sprintf(path, "%s\\%s", basePath, dp->d_name); + int pathLength = snprintf(path, MAX_FILEPATH_LENGTH - 1, "%s\\%s", basePath, dp->d_name); #else - sprintf(path, "%s/%s", basePath, dp->d_name); + int pathLength = snprintf(path, MAX_FILEPATH_LENGTH - 1, "%s/%s", basePath, dp->d_name); #endif - if (IsPathFile(path)) + if ((pathLength < 0) || (pathLength >= MAX_FILEPATH_LENGTH)) + { + TRACELOG(LOG_WARNING, "FILEIO: Path longer than %d characters (%s...)", MAX_FILEPATH_LENGTH, basePath); + } + else if (IsPathFile(path)) { if (filter != NULL) { diff --git a/src/rlgl.h b/src/rlgl.h index e5394a6fe..d55ae82f2 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -56,8 +56,8 @@ * * #define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack * #define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported -* #define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance -* #define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance +* #define RL_CULL_DISTANCE_NEAR 0.001 // Default projection matrix near cull distance +* #define RL_CULL_DISTANCE_FAR 10000.0 // Default projection matrix far cull distance * * When loading a shader, the following vertex attributes and uniform * location names are tried to be set automatically: @@ -234,10 +234,10 @@ // Projection matrix culling #ifndef RL_CULL_DISTANCE_NEAR - #define RL_CULL_DISTANCE_NEAR 0.01 // Default near cull distance + #define RL_CULL_DISTANCE_NEAR 0.001 // Default near cull distance #endif #ifndef RL_CULL_DISTANCE_FAR - #define RL_CULL_DISTANCE_FAR 1000.0 // Default far cull distance + #define RL_CULL_DISTANCE_FAR 10000.0 // Default far cull distance #endif // Texture parameters (equivalent to OpenGL defines) @@ -1459,9 +1459,6 @@ void rlBegin(int mode) // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode != mode) { - // Get current binded texture to preserve it between draw modes change (QUADS <--> TRIANGLES) - int currentTexture = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId; - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0) { // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, @@ -1484,16 +1481,13 @@ void rlBegin(int mode) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = mode; RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0; - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = currentTexture; // Preserve active texture + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.defaultTextureId; } } // Finish vertex providing void rlEnd(void) { - // Reset texture to default - rlSetTexture(RLGL.State.defaultTextureId); - // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values, // as well as depth buffer bit-depth (16bit or 24bit or 32bit) // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits) diff --git a/src/rshapes.c b/src/rshapes.c index 9327a5543..c739f4162 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -285,6 +285,7 @@ void DrawCircleV(Vector2 center, float radius, Color color) // Draw a piece of a circle void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color) { + if (startAngle == endAngle) return; if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero // Function expects (endAngle > startAngle) @@ -376,6 +377,7 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA // Draw a piece of a circle outlines void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color) { + if (startAngle == endAngle) return; if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero issue // Function expects (endAngle > startAngle) @@ -2237,7 +2239,7 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 // NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCount) { - bool inside = false; + bool collision = false; if (pointCount > 2) { @@ -2246,12 +2248,12 @@ bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCoun if ((points[i].y > point.y) != (points[j].y > point.y) && (point.x < (points[j].x - points[i].x)*(point.y - points[i].y)/(points[j].y - points[i].y) + points[i].x)) { - inside = !inside; + collision = !collision; } } } - return inside; + return collision; } // Check collision between two rectangles