diff --git a/BINDINGS.md b/BINDINGS.md index 9c5f4c620..76e72601c 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -1,6 +1,8 @@ ## raylib bindings -Some people ported raylib to other languages in form of bindings or wrappers to the library, here is a list with the ones I'm aware of: +Some people ported raylib to other languages in form of bindings or wrappers to the library. + +Here it is a list with the ones I'm aware of: | name | language | repo | |:------------------:|:--------------:|----------------------------------------------------------------------| @@ -10,22 +12,24 @@ Some people ported raylib to other languages in form of bindings or wrappers to | RaylibFS | F# | https://github.com/dallinbeutler/RaylibFS | | raylib_d | D | https://github.com/0xFireball/raylib_d | | raylib-d | D | https://github.com/onroundit/raylib-d | +| bindbc-raylib | D | https://github.com/o3o/bindbc-raylib | | raylib-go | Go | https://github.com/gen2brain/raylib-go | | raylib-goplus | Go | https://github.com/Lachee/raylib-goplus | -| raylib-rs | Rust | https://github.com/deltaphc/raylib-rs | +| raylib-rs | [Rust](https://www.rust-lang.org/) | https://github.com/deltaphc/raylib-rs | | raylib-lua | Lua | https://github.com/raysan5/raylib-lua | | raylib-lua-ffi | Lua | https://github.com/raysan5/raylib/issues/693 | | raylib-lua-sol | Lua | https://github.com/RobLoach/raylib-lua-sol | | raylib-lua (raylua)| Lua | https://github.com/TSnake41/raylib-lua | | raylib-luamore | Lua | https://github.com/HDPLocust/raylib-luamore | -| raylib-nelua | Nelua | https://github.com/Andre-LA/raylib-nelua-mirror | +| raylib-nelua | [Nelua](https://nelua.io/) | https://github.com/Andre-LA/raylib-nelua-mirror | | raylib-Nim | Nim | https://gitlab.com/define-private-public/raylib-Nim | | raylib-nim | Nim | https://github.com/Skrylar/raylib-nim | | raylib-Forever | Nim | https://github.com/Guevara-chan/Raylib-Forever | -| raylib-haskell | Haskell | https://github.com/DevJac/raylib-haskell | +| raylib-haskell | [Haskell](https://www.haskell.org/) | https://github.com/DevJac/raylib-haskell | | raylib-cr | Crystal | https://github.com/AregevDev/raylib-cr | | cray | Crystal | https://gitlab.com/Zatherz/cray | | cray | Crystal | https://github.com/tapgg/cray | +| raylib.cr | Crystal | https://github.com/sam0x17/raylib.cr | | raylib-pascal | Pascal | https://github.com/drezgames/raylib-pascal | | raylib-pas | Pascal | https://github.com/tazdij/raylib-pas | | Graphics-Raylib | Perl | https://github.com/athreef/Graphics-Raylib | @@ -36,42 +40,43 @@ Some people ported raylib to other languages in form of bindings or wrappers to | raylib-python-cffi | Python | https://github.com/electronstudio/raylib-python-cffi | | jaylib | Java | https://github.com/electronstudio/jaylib/ | | raylib-java | Java | https://github.com/XoanaIO/raylib-java | -| node-raylib | Node.js | https://github.com/RobLoach/node-raylib | -| QuickJS-raylib | [QuickJS](https://bellard.org/quickjs/) | https://github.com/sntg-p/QuickJS-raylib | +| clj-raylib | [Clojure](https://clojure.org/) | https://github.com/lsevero/clj-raylib | +| node-raylib | [Node.js](https://nodejs.org/en/) | https://github.com/RobLoach/node-raylib | +| QuickJS-raylib | [QuickJS](https://bellard.org/quickjs/) | https://github.com/sntg-p/QuickJS-raylib | | raylib-js | JavaScript | https://github.com/RobLoach/raylib-js | -| raylib-chaiscript | ChaiScript | https://github.com/RobLoach/raylib-chaiscript | -| raylib-squirrel | Squirrel | https://github.com/RobLoach/raylib-squirrel | -| racket-raylib-2d | Racket | https://github.com/arvyy/racket-raylib-2d | +| raylib-chaiscript | [ChaiScript](http://chaiscript.com/) | https://github.com/RobLoach/raylib-chaiscript | +| raylib-squirrel | [Squirrel](http://www.squirrel-lang.org/) | https://github.com/RobLoach/raylib-squirrel | +| racket-raylib-2d | [Racket](https://racket-lang.org/) | https://github.com/arvyy/racket-raylib-2d | | raylib-php | PHP | https://github.com/joseph-montanez/raylib-php | | raylib-php-ffi | PHP | https://github.com/oraoto/raylib-php-ffi | | raylib-phpcpp | PHP | https://github.com/oraoto/raylib-phpcpp | -| raylib-factor | Factor | https://github.com/Silverbeard00/raylib-factor | +| raylib-factor | [Factor](https://factorcode.org/) | https://github.com/Silverbeard00/raylib-factor | | raylib-haxe | [Haxe](https://haxe.org/) | https://github.com/ibilon/raylib-haxe | | ringraylib | [Ring](http://ring-lang.sourceforge.net/) | https://github.com/ringpackages/ringraylib | | cl-raylib | Common Lisp | https://github.com/longlene/cl-raylib | | raylib-scm | Chicken Scheme | https://github.com/yashrk/raylib-scm | | raylib-chibi | Chibi-Scheme | https://github.com/VincentToups/raylib-chibi | -| Euraylib | Euphoria | https://github.com/gAndy50/Euraylib | +| Euraylib | [Euphoria](https://openeuphoria.org/) | https://github.com/gAndy50/Euraylib | | raylib-wren | [Wren](http://wren.io/) | https://github.com/TSnake41/raylib-wren | -| raylib-odin | [Odin](https://odin-lang.org/) | https://github.com/kevinw/raylib-odin | -| raylib-zig | [Zig](https://ziglang.org/) | https://github.com/G3bE/raylib-zig | -| ray.zig | [Zig](https://ziglang.org/) | https://github.com/BitPuffin/zig-raylib-experiments | -| raylib-Ada | Ada | https://github.com/mimo/raylib-Ada | +| raylib-odin | [Odin](https://odin-lang.org/) | https://github.com/kevinw/raylib-odin | +| raylib-zig | [Zig](https://ziglang.org/) | https://github.com/G3bE/raylib-zig | +| ray.zig | [Zig](https://ziglang.org/) | https://github.com/BitPuffin/zig-raylib-experiments | +| raylib-Ada | [Ada](https://www.adacore.com/about-ada) | https://github.com/mimo/raylib-Ada | | jaylib | [Janet](https://janet-lang.org/) | https://github.com/janet-lang/jaylib | -| raykit | Kit | https://github.com/Gamerfiend/raykit | -| vraylib | [V](https://vlang.io/) | https://github.com/MajorHard/vraylib | -| ray.mod | BlitzMax | https://github.com/bmx-ng/ray.mod | +| raykit | [Kit](https://www.kitlang.org/) | https://github.com/Gamerfiend/raykit | +| vraylib | [V](https://vlang.io/) | https://github.com/MajorHard/vraylib | +| ray.mod | [BlitzMax](https://blitzmax.org/) | https://github.com/bmx-ng/ray.mod | | raylib-mosaic | Mosaic | https://github.com/pluckyporcupine/raylib-mosaic | | raylib-xdpw | XD Pascal | https://github.com/vtereshkov/raylib-xdpw | | raylib-carp | Carp | https://github.com/pluckyporcupine/raylib-carp | | raylib-fb | FreeBasic | https://github.com/IchMagBier/raylib-fb | +| raylib-purebasic | [PureBasic](https://www.purebasic.com/) | https://github.com/D-a-n-i-l-o/raylib-purebasic | | raylib-ats2 | ATS2 | https://github.com/mephistopheles-8/raylib-ats2 | | raylib-beef | [Beef](https://www.beeflang.org/) | https://github.com/M0n7y5/raylib-beef | | raylib.cbl | COBOL | *[code examples](https://github.com/Martinfx/Cobol/tree/master/OpenCobol/Games/raylib)* | -Missing some language? Check the [bindings not yet in this list](https://gist.github.com/raysan5/5764cc5b885183f523fce47f098f3d9b#bindings-not-yet-in-the-official-list) or create a new binding! :) +Missing some language? Feel free to create a new binding! :) Usually, raylib bindings follow the convention: `raylib-{language}` -Let me know if you're writing a new binding for raylib, I will list it here and I usually -provide the icon/logo for that new language binding. +Let me know if you're writing a new binding for raylib, I will list it here! diff --git a/projects/VS2017/raylib/raylib.vcxproj b/projects/VS2017/raylib/raylib.vcxproj index 4fe9b6840..a608d8e15 100644 --- a/projects/VS2017/raylib/raylib.vcxproj +++ b/projects/VS2017/raylib/raylib.vcxproj @@ -161,7 +161,7 @@ Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP + _CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP CompileAsC $(SolutionDir)..\..\src\external\glfw\include @@ -178,7 +178,7 @@ Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP + _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP CompileAsC $(SolutionDir)..\..\src\external\glfw\include @@ -195,7 +195,7 @@ Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP;BUILD_LIBTYPE_SHARED + _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP;BUILD_LIBTYPE_SHARED CompileAsC $(SolutionDir)..\..\src\external\glfw\include MultiThreadedDebug @@ -214,7 +214,7 @@ Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP;BUILD_LIBTYPE_SHARED + _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP;BUILD_LIBTYPE_SHARED CompileAsC $(SolutionDir)..\..\src\external\glfw\include MultiThreadedDebug @@ -235,7 +235,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP + _CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP $(SolutionDir)..\..\src\external\glfw\include CompileAsC @@ -253,7 +253,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP + _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP $(SolutionDir)..\..\src\external\glfw\include CompileAsC @@ -271,7 +271,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP;BUILD_LIBTYPE_SHARED + _CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP;BUILD_LIBTYPE_SHARED $(SolutionDir)..\..\src\external\glfw\include CompileAsC MultiThreaded @@ -291,7 +291,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP;BUILD_LIBTYPE_SHARED + _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP;BUILD_LIBTYPE_SHARED $(SolutionDir)..\..\src\external\glfw\include CompileAsC MultiThreaded diff --git a/src/camera.h b/src/camera.h index 31db38f0c..3b0feb432 100644 --- a/src/camera.h +++ b/src/camera.h @@ -170,7 +170,7 @@ void SetCameraMoveControls(int frontKey, int backKey, #define CAMERA_FIRST_PERSON_MIN_CLAMP 89.0f #define CAMERA_FIRST_PERSON_MAX_CLAMP -89.0f -#define CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER 5.0f +#define CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER 8.0f #define CAMERA_FIRST_PERSON_STEP_DIVIDER 30.0f #define CAMERA_FIRST_PERSON_WAVING_DIVIDER 200.0f @@ -197,17 +197,18 @@ typedef enum { MOVE_DOWN } CameraMove; -// Camera global state context data +// Camera global state context data [56 bytes] typedef struct { - int mode; // Current camera mode + unsigned int mode; // Current camera mode float targetDistance; // Camera distance from position to target - float playerEyesPosition; // Default player eyes position from ground (in meters) + float playerEyesPosition; // Player eyes position from ground (in meters) Vector2 angle; // Camera angle in plane XZ - int moveControl[6]; - int smoothZoomControl; // raylib: KEY_LEFT_CONTROL - int altControl; // raylib: KEY_LEFT_ALT - int panControl; // raylib: MOUSE_MIDDLE_BUTTON + // Camera movement control keys + int moveControl[6]; // Move controls (CAMERA_FIRST_PERSON) + int smoothZoomControl; // Smooth zoom control key + int altControl; // Alternative control key + int panControl; // Pan view control key } CameraData; //---------------------------------------------------------------------------------- @@ -219,9 +220,9 @@ static CameraData CAMERA = { // Global CAMERA state context .playerEyesPosition = 1.85f, .angle = { 0 }, .moveControl = { 'W', 'S', 'D', 'A', 'E', 'Q' }, - .smoothZoomControl = 341, - .altControl = 342, - .panControl = 2 + .smoothZoomControl = 341, // raylib: KEY_LEFT_CONTROL + .altControl = 342, // raylib: KEY_LEFT_ALT + .panControl = 2 // raylib: MOUSE_MIDDLE_BUTTON }; //---------------------------------------------------------------------------------- @@ -253,13 +254,13 @@ void SetCameraMode(Camera camera, int mode) float dy = v2.y - v1.y; float dz = v2.z - v1.z; - CAMERA.targetDistance = sqrtf(dx*dx + dy*dy + dz*dz); + CAMERA.targetDistance = sqrtf(dx*dx + dy*dy + dz*dz); // Distance to target // Camera angle calculation - CAMERA.angle.x = atan2f(dx, dz); // Camera angle in plane XZ (0 aligned with Z, move positive CCW) - CAMERA.angle.y = atan2f(dy, sqrtf(dx*dx + dz*dz)); // Camera angle in plane XY (0 aligned with X, move positive CW) + CAMERA.angle.x = atan2f(dx, dz); // Camera angle in plane XZ (0 aligned with Z, move positive CCW) + CAMERA.angle.y = atan2f(dy, sqrtf(dx*dx + dz*dz)); // Camera angle in plane XY (0 aligned with X, move positive CW) - CAMERA.playerEyesPosition = camera.position.y; + CAMERA.playerEyesPosition = camera.position.y; // Init player eyes position to camera Y position // Lock cursor for first person and third person cameras if ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON)) DisableCursor(); @@ -287,6 +288,7 @@ void UpdateCamera(Camera *camera) int mouseWheelMove = GetMouseWheelMove(); // Keys input detection + // TODO: Input detection is raylib-dependant, it could be moved outside the module bool panKey = IsMouseButtonDown(CAMERA.panControl); bool altKey = IsKeyDown(CAMERA.altControl); bool szoomKey = IsKeyDown(CAMERA.smoothZoomControl); @@ -297,8 +299,6 @@ void UpdateCamera(Camera *camera) IsKeyDown(CAMERA.moveControl[MOVE_UP]), IsKeyDown(CAMERA.moveControl[MOVE_DOWN]) }; - // TODO: Touch input detection (probably gestures system required) - if (CAMERA.mode != CAMERA_CUSTOM) { mousePositionDelta.x = mousePosition.x - previousMousePosition.x; @@ -321,7 +321,6 @@ void UpdateCamera(Camera *camera) } // Camera looking down - // TODO: Review, weird comparison of CAMERA.targetDistance == 120.0f? else if ((camera->position.y > camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0)) { camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; @@ -342,7 +341,6 @@ void UpdateCamera(Camera *camera) if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP; } // Camera looking up - // TODO: Review, weird comparisson of CAMERA.targetDistance == 120.0f? else if ((camera->position.y < camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0)) { camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; @@ -489,8 +487,10 @@ void UpdateCamera(Camera *camera) // TODO: It seems camera->position is not correctly updated or some rounding issue makes the camera move straight to camera->target... camera->position.x = sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x; + if (CAMERA.angle.y <= 0.0f) camera->position.y = sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y; else camera->position.y = -sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y; + camera->position.z = cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z; } break; diff --git a/src/core.c b/src/core.c index b01f15138..b0c38450b 100644 --- a/src/core.c +++ b/src/core.c @@ -1690,7 +1690,7 @@ int GetFPS(void) if ((GetTime() - last) > FPS_STEP) { - last = GetTime(); + last = (float)GetTime(); index = (index + 1)%FPS_CAPTURE_FRAMES_COUNT; average -= history[index]; history[index] = fpsFrame/FPS_CAPTURE_FRAMES_COUNT; @@ -1752,10 +1752,10 @@ Color ColorFromNormalized(Vector4 normalized) { Color result; - result.r = normalized.x*255.0f; - result.g = normalized.y*255.0f; - result.b = normalized.z*255.0f; - result.a = normalized.w*255.0f; + result.r = (unsigned char)(normalized.x*255.0f); + result.g = (unsigned char)(normalized.y*255.0f); + result.b = (unsigned char)(normalized.z*255.0f); + result.a = (unsigned char)(normalized.w*255.0f); return result; } @@ -1821,28 +1821,28 @@ Color ColorFromHSV(Vector3 hsv) float h = hsv.x, s = hsv.y, v = hsv.z; // Red channel - float k = fmod((5.0f + h/60.0f), 6); + float k = fmodf((5.0f + h/60.0f), 6); float t = 4.0f - k; k = (t < k)? t : k; k = (k < 1)? k : 1; k = (k > 0)? k : 0; - color.r = (v - v*s*k)*255; + color.r = (unsigned char)((v - v*s*k)*255.0f); // Green channel - k = fmod((3.0f + h/60.0f), 6); + k = fmodf((3.0f + h/60.0f), 6); t = 4.0f - k; k = (t < k)? t : k; k = (k < 1)? k : 1; k = (k > 0)? k : 0; - color.g = (v - v*s*k)*255; + color.g = (unsigned char)((v - v*s*k)*255.0f); // Blue channel - k = fmod((1.0f + h/60.0f), 6); + k = fmodf((1.0f + h/60.0f), 6); t = 4.0f - k; k = (t < k)? t : k; k = (k < 1)? k : 1; k = (k > 0)? k : 0; - color.b = (v - v*s*k)*255; + color.b = (unsigned char)((v - v*s*k)*255.0f); return color; } @@ -2023,7 +2023,7 @@ const char *GetFileNameWithoutExt(const char *filePath) if (filePath != NULL) strcpy(fileName, GetFileName(filePath)); // Get filename with extension - int len = strlen(fileName); + int len = (int)strlen(fileName); for (int i = 0; (i < len) && (i < MAX_FILENAMEWITHOUTEXT_LENGTH); i++) { @@ -2080,7 +2080,7 @@ const char *GetPrevDirectoryPath(const char *dirPath) { static char prevDirPath[MAX_FILEPATH_LENGTH]; memset(prevDirPath, 0, MAX_FILEPATH_LENGTH); - int pathLen = strlen(dirPath); + int pathLen = (int)strlen(dirPath); if (pathLen <= 3) strcpy(prevDirPath, dirPath); @@ -2886,9 +2886,9 @@ static bool InitGraphicsDevice(int width, int height) // Get closest video mode to desired CORE.Window.screen.width/CORE.Window.screen.height for (int i = 0; i < count; i++) { - if (modes[i].width >= CORE.Window.screen.width) + if ((unsigned int)modes[i].width >= CORE.Window.screen.width) { - if (modes[i].height >= CORE.Window.screen.height) + if ((unsigned int)modes[i].height >= CORE.Window.screen.height) { CORE.Window.display.width = modes[i].width; CORE.Window.display.height = modes[i].height; @@ -5055,10 +5055,7 @@ static void *EventThread(void *arg) #endif } } - else - { - usleep(5000); // Sleep for 5ms to avoid hogging CPU time - } + else Wait(5); // Sleep for 5ms to avoid hogging CPU time } close(worker->fd); @@ -5146,10 +5143,7 @@ static void *GamepadThread(void *arg) } } } - else - { - usleep(1000); //Sleep for 1ms to avoid hogging CPU time - } + else Wait(1); // Sleep for 1 ms to avoid hogging CPU time } } diff --git a/src/gestures.h b/src/gestures.h index 392ae6607..bb0e43373 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -154,7 +154,6 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang #include // Required for: sqrtf(), atan2f() #endif - #if defined(__APPLE__) // macOS also defines __MACH__ #include // Required for: clock_get_time() #include // Required for: mach_timespec_t @@ -163,20 +162,20 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- -#define FORCE_TO_SWIPE 0.0005f // Measured in normalized screen units/time -#define MINIMUM_DRAG 0.015f // Measured in normalized screen units (0.0f to 1.0f) -#define MINIMUM_PINCH 0.005f // Measured in normalized screen units (0.0f to 1.0f) -#define TAP_TIMEOUT 300 // Time in milliseconds -#define PINCH_TIMEOUT 300 // Time in milliseconds -#define DOUBLETAP_RANGE 0.03f // Measured in normalized screen units (0.0f to 1.0f) +#define FORCE_TO_SWIPE 0.0005f // Swipe force, measured in normalized screen units/time +#define MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f) +#define MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f) +#define TAP_TIMEOUT 300 // Tap minimum time, measured in milliseconds +#define PINCH_TIMEOUT 300 // Pinch minimum time, measured in milliseconds +#define DOUBLETAP_RANGE 0.03f // DoubleTap range, measured in normalized screen units (0.0f to 1.0f) //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- -// Gestures module state context +// Gestures module state context [136 bytes] typedef struct { - int current; // Current detected gesture + unsigned int current; // Current detected gesture unsigned int enabledFlags; // Enabled gestures flags struct { int firstId; // Touch id for first touch point @@ -216,8 +215,8 @@ typedef struct { //---------------------------------------------------------------------------------- static GesturesData GESTURES = { .Touch.firstId = -1, - .current = GESTURE_NONE, - .enabledFlags = 0b0000001111111111 // All gestures enabled by default + .current = GESTURE_NONE, // No current gesture detected + .enabledFlags = 0b0000001111111111 // All gestures supported by default }; //---------------------------------------------------------------------------------- diff --git a/src/models.c b/src/models.c index 7e174caee..00d3b5165 100644 --- a/src/models.c +++ b/src/models.c @@ -142,8 +142,8 @@ void DrawPoint3D(Vector3 position, Color color) rlTranslatef(position.x, position.y, position.z); rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex3f(0.0,0.0,0.0); - rlVertex3f(0.0,0.0,0.1); + rlVertex3f(0.0f, 0.0f, 0.0f); + rlVertex3f(0.0f, 0.0f, 0.1f); rlEnd(); rlPopMatrix(); } @@ -169,6 +169,48 @@ void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rota rlPopMatrix(); } +// Draw a color-filled triangle (vertex in counter-clockwise order!) +void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color) +{ + if (rlCheckBufferLimit(3)) rlglDraw(); + + rlBegin(RL_TRIANGLES); + rlColor4ub(color.r, color.g, color.b, color.a); + rlVertex3f(v1.x, v1.y, v1.z); + rlVertex3f(v2.x, v2.y, v2.z); + rlVertex3f(v3.x, v3.y, v3.z); + rlEnd(); +} + +// Draw a triangle strip defined by points +void DrawTriangleStrip3D(Vector3 *points, int pointsCount, Color color) +{ + if (pointsCount >= 3) + { + if (rlCheckBufferLimit(3*(pointsCount - 2))) rlglDraw(); + + rlBegin(RL_TRIANGLES); + rlColor4ub(color.r, color.g, color.b, color.a); + + for (int i = 2; i < pointsCount; i++) + { + if ((i%2) == 0) + { + rlVertex3f(points[i].x, points[i].y, points[i].z); + rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z); + rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z); + } + else + { + rlVertex3f(points[i].x, points[i].y, points[i].z); + rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z); + rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z); + } + } + rlEnd(); + } +} + // Draw cube // NOTE: Cube position is the center position void DrawCube(Vector3 position, float width, float height, float length, Color color) @@ -863,7 +905,7 @@ Material *LoadMaterials(const char *fileName, int *materialCount) #endif // Set materials shader to default (DIFFUSE, SPECULAR, NORMAL) - for (int i = 0; i < count; i++) materials[i].shader = GetShaderDefault(); + for (unsigned int i = 0; i < count; i++) materials[i].shader = GetShaderDefault(); *materialCount = count; return materials; @@ -998,7 +1040,7 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount) fseek(iqmFile, iqm.ofs_frames, SEEK_SET); fread(framedata, iqm.num_frames*iqm.num_framechannels*sizeof(unsigned short), 1, iqmFile); - for (int a = 0; a < iqm.num_anims; a++) + for (unsigned int a = 0; a < iqm.num_anims; a++) { animations[a].frameCount = anim[a].num_frames; animations[a].boneCount = iqm.num_poses; @@ -1006,19 +1048,19 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount) animations[a].framePoses = RL_MALLOC(anim[a].num_frames*sizeof(Transform *)); //animations[a].framerate = anim.framerate; // TODO: Use framerate? - for (int j = 0; j < iqm.num_poses; j++) + for (unsigned int j = 0; j < iqm.num_poses; j++) { strcpy(animations[a].bones[j].name, "ANIMJOINTNAME"); animations[a].bones[j].parent = poses[j].parent; } - for (int j = 0; j < anim[a].num_frames; j++) animations[a].framePoses[j] = RL_MALLOC(iqm.num_poses*sizeof(Transform)); + for (unsigned int j = 0; j < anim[a].num_frames; j++) animations[a].framePoses[j] = RL_MALLOC(iqm.num_poses*sizeof(Transform)); int dcounter = anim[a].first_frame*iqm.num_framechannels; - for (int frame = 0; frame < anim[a].num_frames; frame++) + for (unsigned int frame = 0; frame < anim[a].num_frames; frame++) { - for (int i = 0; i < iqm.num_poses; i++) + for (unsigned int i = 0; i < iqm.num_poses; i++) { animations[a].framePoses[frame][i].translation.x = poses[i].channeloffset[0]; @@ -1105,7 +1147,7 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount) } // Build frameposes - for (int frame = 0; frame < anim[a].num_frames; frame++) + for (unsigned int frame = 0; frame < anim[a].num_frames; frame++) { for (int i = 0; i < animations[a].boneCount; i++) { @@ -2458,10 +2500,10 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota Color color = model.materials[model.meshMaterial[i]].maps[MAP_DIFFUSE].color; Color colorTint = WHITE; - colorTint.r = (((float)color.r/255.0)*((float)tint.r/255.0))*255; - colorTint.g = (((float)color.g/255.0)*((float)tint.g/255.0))*255; - colorTint.b = (((float)color.b/255.0)*((float)tint.b/255.0))*255; - colorTint.a = (((float)color.a/255.0)*((float)tint.a/255.0))*255; + colorTint.r = (unsigned char)((((float)color.r/255.0)*((float)tint.r/255.0))*255.0f); + colorTint.g = (unsigned char)((((float)color.g/255.0)*((float)tint.g/255.0))*255.0f); + colorTint.b = (unsigned char)((((float)color.b/255.0)*((float)tint.b/255.0))*255.0f); + colorTint.a = (unsigned char)((((float)color.a/255.0)*((float)tint.a/255.0))*255.0f); model.materials[model.meshMaterial[i]].maps[MAP_DIFFUSE].color = colorTint; rlDrawMesh(model.meshes[i], model.materials[model.meshMaterial[i]], model.transform); @@ -2845,7 +2887,7 @@ static Model LoadOBJ(const char *fileName) if (fileData != NULL) { - int dataSize = strlen(fileData); + unsigned int dataSize = (unsigned int)strlen(fileData); char currentDir[1024] = { 0 }; strcpy(currentDir, GetWorkingDirectory()); chdir(GetDirectoryPath(fileName)); @@ -2897,7 +2939,7 @@ static Model LoadOBJ(const char *fileName) int vtCount = 0; int vnCount = 0; - for (int f = 0; f < attrib.num_faces; f++) + for (unsigned int f = 0; f < attrib.num_faces; f++) { // Get indices for the face tinyobj_vertex_index_t idx0 = attrib.faces[3*f + 0]; @@ -2934,7 +2976,7 @@ static Model LoadOBJ(const char *fileName) } // Init model materials - for (int m = 0; m < materialCount; m++) + for (unsigned int m = 0; m < materialCount; m++) { // Init material to default // NOTE: Uses default shader, only MAP_DIFFUSE supported @@ -2970,18 +3012,18 @@ static Model LoadOBJ(const char *fileName) model.materials[m].maps[MAP_DIFFUSE].texture = GetTextureDefault(); // Get default texture, in case no texture is defined if (materials[m].diffuse_texname != NULL) model.materials[m].maps[MAP_DIFFUSE].texture = LoadTexture(materials[m].diffuse_texname); //char *diffuse_texname; // map_Kd - model.materials[m].maps[MAP_DIFFUSE].color = (Color){ (float)(materials[m].diffuse[0]*255.0f), (float)(materials[m].diffuse[1]*255.0f), (float)(materials[m].diffuse[2]*255.0f), 255 }; //float diffuse[3]; + model.materials[m].maps[MAP_DIFFUSE].color = (Color){ (unsigned char)(materials[m].diffuse[0]*255.0f), (unsigned char)(materials[m].diffuse[1]*255.0f), (unsigned char)(materials[m].diffuse[2]*255.0f), 255 }; //float diffuse[3]; model.materials[m].maps[MAP_DIFFUSE].value = 0.0f; if (materials[m].specular_texname != NULL) model.materials[m].maps[MAP_SPECULAR].texture = LoadTexture(materials[m].specular_texname); //char *specular_texname; // map_Ks - model.materials[m].maps[MAP_SPECULAR].color = (Color){ (float)(materials[m].specular[0]*255.0f), (float)(materials[m].specular[1]*255.0f), (float)(materials[m].specular[2]*255.0f), 255 }; //float specular[3]; + model.materials[m].maps[MAP_SPECULAR].color = (Color){ (unsigned char)(materials[m].specular[0]*255.0f), (unsigned char)(materials[m].specular[1]*255.0f), (unsigned char)(materials[m].specular[2]*255.0f), 255 }; //float specular[3]; model.materials[m].maps[MAP_SPECULAR].value = 0.0f; if (materials[m].bump_texname != NULL) model.materials[m].maps[MAP_NORMAL].texture = LoadTexture(materials[m].bump_texname); //char *bump_texname; // map_bump, bump model.materials[m].maps[MAP_NORMAL].color = WHITE; model.materials[m].maps[MAP_NORMAL].value = materials[m].shininess; - model.materials[m].maps[MAP_EMISSION].color = (Color){ (float)(materials[m].emission[0]*255.0f), (float)(materials[m].emission[1]*255.0f), (float)(materials[m].emission[2]*255.0f), 255 }; //float emission[3]; + model.materials[m].maps[MAP_EMISSION].color = (Color){ (unsigned char)(materials[m].emission[0]*255.0f), (unsigned char)(materials[m].emission[1]*255.0f), (unsigned char)(materials[m].emission[2]*255.0f), 255 }; //float emission[3]; if (materials[m].displacement_texname != NULL) model.materials[m].maps[MAP_HEIGHT].texture = LoadTexture(materials[m].displacement_texname); //char *displacement_texname; // disp } @@ -3175,7 +3217,7 @@ static Model LoadIQM(const char *fileName) { int tcounter = 0; - for (int i = imesh[m].first_triangle; i < (imesh[m].first_triangle + imesh[m].num_triangles); i++) + for (unsigned int i = imesh[m].first_triangle; i < (imesh[m].first_triangle + imesh[m].num_triangles); i++) { // IQM triangles are stored counter clockwise, but raylib sets opengl to clockwise drawing, so we swap them around model.meshes[m].indices[tcounter + 2] = tri[i].vertex[0] - imesh[m].first_vertex; @@ -3190,7 +3232,7 @@ static Model LoadIQM(const char *fileName) fseek(iqmFile, iqm.ofs_vertexarrays, SEEK_SET); fread(va, iqm.num_vertexarrays*sizeof(IQMVertexArray), 1, iqmFile); - for (int i = 0; i < iqm.num_vertexarrays; i++) + for (unsigned int i = 0; i < iqm.num_vertexarrays; i++) { switch (va[i].type) { @@ -3200,10 +3242,10 @@ static Model LoadIQM(const char *fileName) fseek(iqmFile, va[i].offset, SEEK_SET); fread(vertex, iqm.num_vertexes*3*sizeof(float), 1, iqmFile); - for (int m = 0; m < iqm.num_meshes; m++) + for (unsigned int m = 0; m < iqm.num_meshes; m++) { int vCounter = 0; - for (int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++) + for (unsigned int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++) { model.meshes[m].vertices[vCounter] = vertex[i]; model.meshes[m].animVertices[vCounter] = vertex[i]; @@ -3217,10 +3259,10 @@ static Model LoadIQM(const char *fileName) fseek(iqmFile, va[i].offset, SEEK_SET); fread(normal, iqm.num_vertexes*3*sizeof(float), 1, iqmFile); - for (int m = 0; m < iqm.num_meshes; m++) + for (unsigned int m = 0; m < iqm.num_meshes; m++) { int vCounter = 0; - for (int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++) + for (unsigned int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++) { model.meshes[m].normals[vCounter] = normal[i]; model.meshes[m].animNormals[vCounter] = normal[i]; @@ -3234,10 +3276,10 @@ static Model LoadIQM(const char *fileName) fseek(iqmFile, va[i].offset, SEEK_SET); fread(text, iqm.num_vertexes*2*sizeof(float), 1, iqmFile); - for (int m = 0; m < iqm.num_meshes; m++) + for (unsigned int m = 0; m < iqm.num_meshes; m++) { int vCounter = 0; - for (int i = imesh[m].first_vertex*2; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*2; i++) + for (unsigned int i = imesh[m].first_vertex*2; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*2; i++) { model.meshes[m].texcoords[vCounter] = text[i]; vCounter++; @@ -3250,10 +3292,10 @@ static Model LoadIQM(const char *fileName) fseek(iqmFile, va[i].offset, SEEK_SET); fread(blendi, iqm.num_vertexes*4*sizeof(char), 1, iqmFile); - for (int m = 0; m < iqm.num_meshes; m++) + for (unsigned int m = 0; m < iqm.num_meshes; m++) { int boneCounter = 0; - for (int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++) + for (unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++) { model.meshes[m].boneIds[boneCounter] = blendi[i]; boneCounter++; @@ -3266,10 +3308,10 @@ static Model LoadIQM(const char *fileName) fseek(iqmFile, va[i].offset, SEEK_SET); fread(blendw, iqm.num_vertexes*4*sizeof(unsigned char), 1, iqmFile); - for (int m = 0; m < iqm.num_meshes; m++) + for (unsigned int m = 0; m < iqm.num_meshes; m++) { int boneCounter = 0; - for (int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++) + for (unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++) { model.meshes[m].boneWeights[boneCounter] = blendw[i]/255.0f; boneCounter++; @@ -3288,7 +3330,7 @@ static Model LoadIQM(const char *fileName) model.bones = RL_MALLOC(iqm.num_joints*sizeof(BoneInfo)); model.bindPose = RL_MALLOC(iqm.num_joints*sizeof(Transform)); - for (int i = 0; i < iqm.num_joints; i++) + for (unsigned int i = 0; i < iqm.num_joints; i++) { // Bones model.bones[i].parent = ijoint[i].parent; @@ -3460,17 +3502,17 @@ static Image LoadImageFromCgltfImage(cgltf_image *image, const char *texPath, Co else if (image->buffer_view) { unsigned char *data = RL_MALLOC(image->buffer_view->size); - int n = image->buffer_view->offset; - int stride = image->buffer_view->stride ? image->buffer_view->stride : 1; + int n = (int)image->buffer_view->offset; + int stride = (int)image->buffer_view->stride ? (int)image->buffer_view->stride : 1; - for (int i = 0; i < image->buffer_view->size; i++) + for (unsigned int i = 0; i < image->buffer_view->size; i++) { data[i] = ((unsigned char *)image->buffer_view->buffer->data)[n]; n += stride; } int width, height; - unsigned char *raw = stbi_load_from_memory(data, image->buffer_view->size, &width, &height, NULL, 4); + unsigned char *raw = stbi_load_from_memory(data, (int)image->buffer_view->size, &width, &height, NULL, 4); free(data); rimage.data = raw; @@ -3511,12 +3553,12 @@ static Model LoadGLTF(const char *fileName) #define LOAD_ACCESSOR(type, nbcomp, acc, dst) \ { \ int n = 0; \ - type* buf = (type*)acc->buffer_view->buffer->data+acc->buffer_view->offset/sizeof(type)+acc->offset/sizeof(type); \ - for (int k = 0; k < acc->count; k++) {\ + type* buf = (type*)acc->buffer_view->buffer->data + acc->buffer_view->offset/sizeof(type) + acc->offset/sizeof(type); \ + for (unsigned int k = 0; k < acc->count; k++) {\ for (int l = 0; l < nbcomp; l++) {\ - dst[nbcomp*k+l] = buf[n+l];\ + dst[nbcomp*k + l] = buf[n + l];\ }\ - n += acc->stride/sizeof(type);\ + n += (int)(acc->stride/sizeof(type));\ }\ } @@ -3544,12 +3586,12 @@ static Model LoadGLTF(const char *fileName) int primitivesCount = 0; - for (int i = 0; i < data->meshes_count; i++) primitivesCount += (int)data->meshes[i].primitives_count; + for (unsigned int i = 0; i < data->meshes_count; i++) primitivesCount += (int)data->meshes[i].primitives_count; // Process glTF data and map to model model.meshCount = primitivesCount; model.meshes = RL_CALLOC(model.meshCount, sizeof(Mesh)); - model.materialCount = data->materials_count + 1; + model.materialCount = (int)data->materials_count + 1; model.materials = RL_MALLOC(model.materialCount*sizeof(Material)); model.meshMaterial = RL_MALLOC(model.meshCount*sizeof(int)); @@ -3625,16 +3667,16 @@ static Model LoadGLTF(const char *fileName) int primitiveIndex = 0; - for (int i = 0; i < data->meshes_count; i++) + for (unsigned int i = 0; i < data->meshes_count; i++) { - for (int p = 0; p < data->meshes[i].primitives_count; p++) + for (unsigned int p = 0; p < data->meshes[i].primitives_count; p++) { - for (int j = 0; j < data->meshes[i].primitives[p].attributes_count; j++) + for (unsigned int j = 0; j < data->meshes[i].primitives[p].attributes_count; j++) { if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_position) { cgltf_accessor *acc = data->meshes[i].primitives[p].attributes[j].data; - model.meshes[primitiveIndex].vertexCount = acc->count; + model.meshes[primitiveIndex].vertexCount = (int)acc->count; model.meshes[primitiveIndex].vertices = RL_MALLOC(sizeof(float)*model.meshes[primitiveIndex].vertexCount*3); LOAD_ACCESSOR(float, 3, acc, model.meshes[primitiveIndex].vertices) @@ -3669,7 +3711,7 @@ static Model LoadGLTF(const char *fileName) { if (acc->component_type == cgltf_component_type_r_16u) { - model.meshes[primitiveIndex].triangleCount = acc->count/3; + model.meshes[primitiveIndex].triangleCount = (int)acc->count/3; model.meshes[primitiveIndex].indices = RL_MALLOC(sizeof(unsigned short)*model.meshes[primitiveIndex].triangleCount*3); LOAD_ACCESSOR(unsigned short, 1, acc, model.meshes[primitiveIndex].indices) } @@ -3688,7 +3730,7 @@ static Model LoadGLTF(const char *fileName) if (data->meshes[i].primitives[p].material) { // Compute the offset - model.meshMaterial[primitiveIndex] = data->meshes[i].primitives[p].material - data->materials; + model.meshMaterial[primitiveIndex] = (int)(data->meshes[i].primitives[p].material - data->materials); } else { diff --git a/src/raudio.c b/src/raudio.c index 5224d516f..dddb08e63 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -2024,7 +2024,7 @@ static int SaveWAV(Wave wave, const char *fileName) fwrite(&waveFormat, sizeof(WaveFormat), 1, wavFile); fwrite(&waveData, sizeof(WaveData), 1, wavFile); - success = fwrite(wave.data, dataSize, 1, wavFile); + success = (int)fwrite(wave.data, dataSize, 1, wavFile); fclose(wavFile); } diff --git a/src/raylib.h b/src/raylib.h index 050875059..7ddf183a8 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1268,6 +1268,8 @@ RLAPI const char *CodepointToUtf8(int codepoint, int *byteLength); // Encode RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space RLAPI void DrawPoint3D(Vector3 position, Color color); // Draw a point in 3D space, actually a small line RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space +RLAPI void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color); // Draw a color-filled triangle (vertex in counter-clockwise order!) +RLAPI void DrawTriangleStrip3D(Vector3 *points, int pointsCount, Color color); // Draw a triangle strip defined by points RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires @@ -1282,7 +1284,6 @@ RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color); RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo -//DrawTorus(), DrawTeapot() could be useful? //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) diff --git a/src/rlgl.h b/src/rlgl.h index c2473ee90..acf2270d2 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1577,10 +1577,10 @@ void rlglInit(int width, int height) glGetIntegerv(GL_NUM_EXTENSIONS, &numExt); // Allocate numExt strings pointers - const char **extList = RL_MALLOC(sizeof(const char *)*numExt); + char **extList = RL_MALLOC(sizeof(char *)*numExt); // Get extensions strings - for (int i = 0; i < numExt; i++) extList[i] = (const char *)glGetStringi(GL_EXTENSIONS, i); + for (int i = 0; i < numExt; i++) extList[i] = (char *)glGetStringi(GL_EXTENSIONS, i); #elif defined(GRAPHICS_API_OPENGL_ES2) // Allocate 512 strings pointers (2 KB) diff --git a/src/shapes.c b/src/shapes.c index 6b0a7f217..66e0f55ce 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -223,13 +223,13 @@ void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle { // Calculate the maximum angle between segments based on the error rate (usually 0.5f) float th = acosf(2*powf(1 - SMOOTH_CIRCLE_ERROR_RATE/radius, 2) - 1); - segments = (endAngle - startAngle)*ceilf(2*PI/th)/360; + segments = (int)((endAngle - startAngle)*ceilf(2*PI/th)/360); if (segments <= 0) segments = 4; } float stepLength = (float)(endAngle - startAngle)/(float)segments; - float angle = startAngle; + float angle = (float)startAngle; #if defined(SUPPORT_QUADS_DRAW_MODE) if (rlCheckBufferLimit(4*segments/2)) rlglDraw(); @@ -312,13 +312,13 @@ void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int end { // Calculate the maximum angle between segments based on the error rate (usually 0.5f) float th = acosf(2*powf(1 - SMOOTH_CIRCLE_ERROR_RATE/radius, 2) - 1); - segments = (endAngle - startAngle)*ceilf(2*PI/th)/360; + segments = (int)((endAngle - startAngle)*ceilf(2*PI/th)/360); if (segments <= 0) segments = 4; } float stepLength = (float)(endAngle - startAngle)/(float)segments; - float angle = startAngle; + float angle = (float)startAngle; // Hide the cap lines when the circle is full bool showCapLines = true; @@ -364,11 +364,11 @@ void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Co for (int i = 0; i < 360; i += 10) { rlColor4ub(color1.r, color1.g, color1.b, color1.a); - rlVertex2f(centerX, centerY); + rlVertex2f((float)centerX, (float)centerY); rlColor4ub(color2.r, color2.g, color2.b, color2.a); - rlVertex2f(centerX + sinf(DEG2RAD*i)*radius, centerY + cosf(DEG2RAD*i)*radius); + rlVertex2f((float)centerX + sinf(DEG2RAD*i)*radius, (float)centerY + cosf(DEG2RAD*i)*radius); rlColor4ub(color2.r, color2.g, color2.b, color2.a); - rlVertex2f(centerX + sinf(DEG2RAD*(i + 10))*radius, centerY + cosf(DEG2RAD*(i + 10))*radius); + rlVertex2f((float)centerX + sinf(DEG2RAD*(i + 10))*radius, (float)centerY + cosf(DEG2RAD*(i + 10))*radius); } rlEnd(); } @@ -406,9 +406,9 @@ void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color c for (int i = 0; i < 360; i += 10) { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(centerX, centerY); - rlVertex2f(centerX + sinf(DEG2RAD*i)*radiusH, centerY + cosf(DEG2RAD*i)*radiusV); - rlVertex2f(centerX + sinf(DEG2RAD*(i + 10))*radiusH, centerY + cosf(DEG2RAD*(i + 10))*radiusV); + rlVertex2f((float)centerX, (float)centerY); + rlVertex2f((float)centerX + sinf(DEG2RAD*i)*radiusH, (float)centerY + cosf(DEG2RAD*i)*radiusV); + rlVertex2f((float)centerX + sinf(DEG2RAD*(i + 10))*radiusH, (float)centerY + cosf(DEG2RAD*(i + 10))*radiusV); } rlEnd(); } @@ -455,7 +455,7 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng { // Calculate the maximum angle between segments based on the error rate (usually 0.5f) float th = acosf(2*powf(1 - SMOOTH_CIRCLE_ERROR_RATE/outerRadius, 2) - 1); - segments = (endAngle - startAngle)*ceilf(2*PI/th)/360; + segments = (int)((endAngle - startAngle)*ceilf(2*PI/th)/360); if (segments <= 0) segments = 4; } @@ -468,7 +468,7 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng } float stepLength = (float)(endAngle - startAngle)/(float)segments; - float angle = startAngle; + float angle = (float)startAngle; #if defined(SUPPORT_QUADS_DRAW_MODE) if (rlCheckBufferLimit(4*segments)) rlglDraw(); @@ -546,7 +546,7 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta { // Calculate the maximum angle between segments based on the error rate (usually 0.5f) float th = acosf(2*powf(1 - SMOOTH_CIRCLE_ERROR_RATE/outerRadius, 2) - 1); - segments = (endAngle - startAngle)*ceilf(2*PI/th)/360; + segments = (int)((endAngle - startAngle)*ceilf(2*PI/th)/360); if (segments <= 0) segments = 4; } @@ -558,7 +558,7 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta } float stepLength = (float)(endAngle - startAngle)/(float)segments; - float angle = startAngle; + float angle = (float)startAngle; bool showCapLines = true; int limit = 4*(segments + 1); @@ -755,7 +755,7 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co { // Calculate the maximum angle between segments based on the error rate (usually 0.5f) float th = acosf(2*powf(1 - SMOOTH_CIRCLE_ERROR_RATE/radius, 2) - 1); - segments = ceilf(2*PI/th)/4; + segments = (int)(ceilf(2*PI/th)/4.0f); if (segments <= 0) segments = 4; } @@ -975,7 +975,7 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, int { // Calculate the maximum angle between segments based on the error rate (usually 0.5f) float th = acosf(2*powf(1 - SMOOTH_CIRCLE_ERROR_RATE/radius, 2) - 1); - segments = ceilf(2*PI/th)/2; + segments = (int)(ceilf(2*PI/th)/2.0f); if (segments <= 0) segments = 4; } diff --git a/src/text.c b/src/text.c index 1bd8a0f88..c85d27b64 100644 --- a/src/text.c +++ b/src/text.c @@ -93,8 +93,9 @@ // Global variables //---------------------------------------------------------------------------------- #if defined(SUPPORT_DEFAULT_FONT) -static Font defaultFont = { 0 }; // Default font provided by raylib -// NOTE: defaultFont is loaded on InitWindow and disposed on CloseWindow [module: core] +// Default font provided by raylib +// NOTE: Default font is loaded on InitWindow() and disposed on CloseWindow() [module: core] +static Font defaultFont = { 0 }; #endif //---------------------------------------------------------------------------------- @@ -957,7 +958,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f bool isGlyphSelected = false; if ((selectStart >= 0) && (k >= selectStart) && (k < (selectStart + selectLength))) { - DrawRectangleRec((Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, glyphWidth, (int)((float)font.baseSize*scaleFactor) }, selectBackTint); + DrawRectangleRec((Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, (float)glyphWidth, (float)font.baseSize*scaleFactor }, selectBackTint); isGlyphSelected = true; } @@ -1229,7 +1230,7 @@ char *TextReplace(char *text, const char *replace, const char *by) while (count--) { insertPoint = strstr(text, replace); - lastReplacePos = insertPoint - text; + lastReplacePos = (int)(insertPoint - text); temp = strncpy(temp, text, lastReplacePos) + lastReplacePos; temp = strcpy(temp, by) + byLen; text += lastReplacePos + replaceLen; // Move to next "end of replace" @@ -1346,7 +1347,7 @@ int TextFindIndex(const char *text, const char *find) char *ptr = strstr(text, find); - if (ptr != NULL) position = ptr - text; + if (ptr != NULL) position = (int)(ptr - text); return position; } diff --git a/src/textures.c b/src/textures.c index 7df3a2582..d08ee9506 100644 --- a/src/textures.c +++ b/src/textures.c @@ -202,6 +202,7 @@ Image LoadImage(const char *fileName) #if defined(SUPPORT_FILEFORMAT_PNG) || \ defined(SUPPORT_FILEFORMAT_BMP) || \ defined(SUPPORT_FILEFORMAT_TGA) || \ + defined(SUPPORT_FILEFORMAT_JPG) || \ defined(SUPPORT_FILEFORMAT_GIF) || \ defined(SUPPORT_FILEFORMAT_PIC) || \ defined(SUPPORT_FILEFORMAT_HDR) || \ @@ -689,7 +690,7 @@ Rectangle GetImageAlphaBorder(Image image, float threshold) // Check for empty blank image if ((xMin != 65536) && (xMax != 65536)) { - crop = (Rectangle){ xMin, yMin, (xMax + 1) - xMin, (yMax + 1) - yMin }; + crop = (Rectangle){ (float)xMin, (float)yMin, (float)((xMax + 1) - xMin), (float)((yMax + 1) - yMin) }; } RL_FREE(pixels); @@ -1273,12 +1274,12 @@ TextureCubemap LoadTextureCubemap(Image image, int layoutType) Image faces = { 0 }; // Vertical column image Rectangle faceRecs[6] = { 0 }; // Face source rectangles - for (int i = 0; i < 6; i++) faceRecs[i] = (Rectangle){ 0, 0, size, size }; + for (int i = 0; i < 6; i++) faceRecs[i] = (Rectangle){ 0, 0, (float)size, (float)size }; if (layoutType == CUBEMAP_LINE_VERTICAL) { faces = image; - for (int i = 0; i < 6; i++) faceRecs[i].y = size*i; + for (int i = 0; i < 6; i++) faceRecs[i].y = (float)size*i; } else if (layoutType == CUBEMAP_PANORAMA) { @@ -1287,24 +1288,24 @@ TextureCubemap LoadTextureCubemap(Image image, int layoutType) } else { - if (layoutType == CUBEMAP_LINE_HORIZONTAL) for (int i = 0; i < 6; i++) faceRecs[i].x = size*i; + if (layoutType == CUBEMAP_LINE_HORIZONTAL) for (int i = 0; i < 6; i++) faceRecs[i].x = (float)size*i; else if (layoutType == CUBEMAP_CROSS_THREE_BY_FOUR) { - faceRecs[0].x = size; faceRecs[0].y = size; - faceRecs[1].x = size; faceRecs[1].y = 3*size; - faceRecs[2].x = size; faceRecs[2].y = 0; - faceRecs[3].x = size; faceRecs[3].y = 2*size; - faceRecs[4].x = 0; faceRecs[4].y = size; - faceRecs[5].x = 2*size; faceRecs[5].y = size; + faceRecs[0].x = (float)size; faceRecs[0].y = (float)size; + faceRecs[1].x = (float)size; faceRecs[1].y = (float)size*3; + faceRecs[2].x = (float)size; faceRecs[2].y = 0; + faceRecs[3].x = (float)size; faceRecs[3].y = (float)size*2; + faceRecs[4].x = 0; faceRecs[4].y = (float)size; + faceRecs[5].x = (float)size*2; faceRecs[5].y = (float)size; } else if (layoutType == CUBEMAP_CROSS_FOUR_BY_THREE) { - faceRecs[0].x = 2*size; faceRecs[0].y = size; - faceRecs[1].x = 0; faceRecs[1].y = size; - faceRecs[2].x = size; faceRecs[2].y = 0; - faceRecs[3].x = size; faceRecs[3].y = 2*size; - faceRecs[4].x = size; faceRecs[4].y = size; - faceRecs[5].x = 3*size; faceRecs[5].y = size; + faceRecs[0].x = (float)size*2; faceRecs[0].y = (float)size; + faceRecs[1].x = 0; faceRecs[1].y = (float)size; + faceRecs[2].x = (float)size; faceRecs[2].y = 0; + faceRecs[3].x = (float)size; faceRecs[3].y = (float)size*2; + faceRecs[4].x = (float)size; faceRecs[4].y = (float)size; + faceRecs[5].x = (float)size*3; faceRecs[5].y = (float)size; } // Convert image data to 6 faces in a vertical column, that's the optimum layout for loading @@ -1314,7 +1315,7 @@ TextureCubemap LoadTextureCubemap(Image image, int layoutType) // TODO: Image formating does not work with compressed textures! } - for (int i = 0; i < 6; i++) ImageDraw(&faces, image, faceRecs[i], (Rectangle){ 0, size*i, size, size }, WHITE); + for (int i = 0; i < 6; i++) ImageDraw(&faces, image, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, WHITE); cubemap.id = rlLoadTextureCubemap(faces.data, size, faces.format); if (cubemap.id == 0) TRACELOG(LOG_WARNING, "IMAGE: Failed to load cubemap image"); @@ -1396,7 +1397,7 @@ void ImageAlphaCrop(Image *image, float threshold) } } - Rectangle crop = { xMin, yMin, (xMax + 1) - xMin, (yMax + 1) - yMin }; + Rectangle crop = { (float)xMin, (float)yMin, (float)((xMax + 1) - xMin), (float)((yMax + 1) - yMin) }; RL_FREE(pixels); @@ -1479,23 +1480,23 @@ void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, i // Support offsets out of canvas new size -> original image is cropped if (offsetX < 0) { - ImageCrop(image, (Rectangle) { -offsetX, 0, image->width + offsetX, image->height }); + ImageCrop(image, (Rectangle) { -(float)offsetX, 0, (float)(image->width + offsetX), (float)image->height }); offsetX = 0; } else if (offsetX > (newWidth - image->width)) { - ImageCrop(image, (Rectangle) { 0, 0, image->width - (offsetX - (newWidth - image->width)), image->height }); + ImageCrop(image, (Rectangle) { 0, 0, (float)(image->width - (offsetX - (newWidth - image->width))), (float)image->height }); offsetX = newWidth - image->width; } if (offsetY < 0) { - ImageCrop(image, (Rectangle) { 0, -offsetY, image->width, image->height + offsetY }); + ImageCrop(image, (Rectangle) { 0, -(float)offsetY, (float)image->width, (float)(image->height + offsetY) }); offsetY = 0; } else if (offsetY > (newHeight - image->height)) { - ImageCrop(image, (Rectangle) { 0, 0, image->width, image->height - (offsetY - (newHeight - image->height)) }); + ImageCrop(image, (Rectangle) { 0, 0, (float)image->width, (float)(image->height - (offsetY - (newHeight - image->height))) }); offsetY = newHeight - image->height; } @@ -1525,15 +1526,15 @@ void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, i if (newWidth < image->width) { - srcRec.x = offsetX; - srcRec.width = newWidth; + srcRec.x = (float)offsetX; + srcRec.width = (float)newWidth; dstRec.x = 0.0f; } if (newHeight < image->height) { - srcRec.y = offsetY; - srcRec.height = newHeight; + srcRec.y = (float)offsetY; + srcRec.height = (float)newHeight; dstRec.y = 0.0f; } @@ -1913,7 +1914,7 @@ Image ImageText(const char *text, int fontSize, Color color) // Create an image from text (custom sprite font) Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint) { - int length = strlen(text); + int length = (int)strlen(text); int textOffsetX = 0; // Image drawing position X int textOffsetY = 0; // Offset between lines (on line break '\n') @@ -1940,14 +1941,14 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co // NOTE: Fixed line spacing of 1.5 line-height // TODO: Support custom line spacing defined by user textOffsetY += (font.baseSize + font.baseSize/2); - textOffsetX = 0.0f; + textOffsetX = 0; } else { if ((codepoint != ' ') && (codepoint != '\t')) { - Rectangle rec = { textOffsetX + font.chars[index].offsetX, textOffsetY + font.chars[index].offsetY, font.recs[index].width, font.recs[index].height }; - ImageDraw(&imText, font.chars[index].image, (Rectangle){ 0, 0, font.chars[index].image.width, font.chars[index].image.height }, rec, tint); + Rectangle rec = { (float)(textOffsetX + font.chars[index].offsetX), (float)(textOffsetY + font.chars[index].offsetY), (float)font.recs[index].width, (float)font.recs[index].height }; + ImageDraw(&imText, font.chars[index].image, (Rectangle){ 0, 0, (float)font.chars[index].image.width, (float)font.chars[index].image.height }, rec, tint); } if (font.chars[index].advanceX == 0) textOffsetX += (int)(font.recs[index].width + spacing); @@ -1974,13 +1975,13 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co // Draw rectangle within an image void ImageDrawRectangle(Image *dst, int posX, int posY, int width, int height, Color color) { - ImageDrawRectangleRec(dst, (Rectangle){ posX, posY, width, height }, color); + ImageDrawRectangleRec(dst, (Rectangle){ (float)posX, (float)posY, (float)width, (float)height }, color); } // Draw rectangle within an image (Vector version) void ImageDrawRectangleV(Image *dst, Vector2 position, Vector2 size, Color color) { - ImageDrawRectangle(dst, position.x, position.y, size.x, size.y, color); + ImageDrawRectangle(dst, (int)position.x, (int)position.y, (int)size.x, (int)size.y, color); } // Draw rectangle within an image @@ -1997,10 +1998,10 @@ void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color) // Draw rectangle lines within an image void ImageDrawRectangleLines(Image *dst, Rectangle rec, int thick, Color color) { - ImageDrawRectangle(dst, rec.x, rec.y, rec.width, thick, color); - ImageDrawRectangle(dst, rec.x, rec.y + thick, thick, rec.height - thick*2, color); - ImageDrawRectangle(dst, rec.x + rec.width - thick, rec.y + thick, thick, rec.height - thick*2, color); - ImageDrawRectangle(dst, rec.x, rec.y + rec.height - thick, rec.width, thick, color); + ImageDrawRectangle(dst, (int)rec.x, (int)rec.y, (int)rec.width, thick, color); + ImageDrawRectangle(dst, (int)rec.x, (int)(rec.y + thick), thick, (int)(rec.height - thick*2), color); + ImageDrawRectangle(dst, (int)(rec.x + rec.width - thick), (int)(rec.y + thick), thick, (int)(rec.height - thick*2), color); + ImageDrawRectangle(dst, (int)rec.x, (int)(rec.y + rec.height - thick), (int)rec.width, thick, color); } // Clear image background with given color @@ -2338,10 +2339,10 @@ void ImageColorTint(Image *image, Color color) for (int x = 0; x < image->width; x++) { int index = y * image->width + x; - unsigned char r = 255*((float)pixels[index].r/255*cR); - unsigned char g = 255*((float)pixels[index].g/255*cG); - unsigned char b = 255*((float)pixels[index].b/255*cB); - unsigned char a = 255*((float)pixels[index].a/255*cA); + unsigned char r = (unsigned char)(((float)pixels[index].r/255*cR)*255.0f); + unsigned char g = (unsigned char)(((float)pixels[index].g/255*cG)*255.0f); + unsigned char b = (unsigned char)(((float)pixels[index].b/255*cB)*255.0f); + unsigned char a = (unsigned char)(((float)pixels[index].a/255*cA)*255.0f); pixels[y*image->width + x].r = r; pixels[y*image->width + x].g = g; @@ -3614,7 +3615,7 @@ static int SaveKTX(Image image, const char *fileName) if (ktxHeader.glFormat == -1) TRACELOG(LOG_WARNING, "IMAGE: GL format not supported for KTX export (%i)", ktxHeader.glFormat); else { - success = fwrite(&ktxHeader, sizeof(KTXHeader), 1, ktxFile); + success = (int)fwrite(&ktxHeader, sizeof(KTXHeader), 1, ktxFile); int width = image.width; int height = image.height; @@ -3624,8 +3625,8 @@ static int SaveKTX(Image image, const char *fileName) for (int i = 0; i < image.mipmaps; i++) { unsigned int dataSize = GetPixelDataSize(width, height, image.format); - success = fwrite(&dataSize, sizeof(unsigned int), 1, ktxFile); - success = fwrite((unsigned char *)image.data + dataOffset, dataSize, 1, ktxFile); + success = (int)fwrite(&dataSize, sizeof(unsigned int), 1, ktxFile); + success = (int)fwrite((unsigned char *)image.data + dataOffset, dataSize, 1, ktxFile); width /= 2; height /= 2; diff --git a/src/utils.c b/src/utils.c index 4d2dd050e..518815f44 100644 --- a/src/utils.c +++ b/src/utils.c @@ -202,7 +202,7 @@ unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead) data = (unsigned char *)RL_MALLOC(sizeof(unsigned char)*size); // NOTE: fread() returns number of read elements instead of bytes, so we read [1 byte, size elements] - unsigned int count = fread(data, sizeof(unsigned char), size, file); + unsigned int count = (unsigned int)fread(data, sizeof(unsigned char), size, file); *bytesRead = count; if (count != size) TRACELOG(LOG_WARNING, "FILEIO: [%s] File partially loaded", fileName); @@ -233,7 +233,7 @@ void SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite) if (file != NULL) { - unsigned int count = fwrite(data, sizeof(unsigned char), bytesToWrite, file); + unsigned int count = (unsigned int)fwrite(data, sizeof(unsigned char), bytesToWrite, file); if (count == 0) TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to write file", fileName); else if (count != bytesToWrite) TRACELOG(LOG_WARNING, "FILEIO: [%s] File partially written", fileName); @@ -269,13 +269,13 @@ char *LoadFileText(const char *fileName) // text mode causes carriage return-linefeed translation... // ...but using fseek() should return correct byte-offset fseek(textFile, 0, SEEK_END); - int size = ftell(textFile); + unsigned int size = (unsigned int)ftell(textFile); fseek(textFile, 0, SEEK_SET); if (size > 0) { text = (char *)RL_MALLOC(sizeof(char)*(size + 1)); - int count = fread(text, sizeof(char), size, textFile); + unsigned int count = (unsigned int)fread(text, sizeof(char), size, textFile); // WARNING: \r\n is converted to \n on reading, so, // read bytes count gets reduced by the number of lines diff --git a/templates/advance_game/screens/screen_logo.c b/templates/advance_game/screens/screen_logo.c index a9440e4b2..148fbd6ea 100644 --- a/templates/advance_game/screens/screen_logo.c +++ b/templates/advance_game/screens/screen_logo.c @@ -64,11 +64,6 @@ void InitLogoScreen(void) logoPositionX = GetScreenWidth()/2 - 128; logoPositionY = GetScreenHeight()/2 - 128; - topSideRecWidth = LOGO_RECS_SIDE; - leftSideRecHeight = LOGO_RECS_SIDE; - bottomSideRecWidth = LOGO_RECS_SIDE; - rightSideRecHeight = LOGO_RECS_SIDE; - for (int i = 0; i < 8; i++) raylib[i] = '\0'; state = 0; @@ -206,4 +201,4 @@ void UnloadLogoScreen(void) int FinishLogoScreen(void) { return finishScreen; -} \ No newline at end of file +}