synced with master

This commit is contained in:
TheLastBilly 2023-05-30 11:46:05 -04:00
commit 5eaa1d99ac
27 changed files with 3103 additions and 2057 deletions

View File

@ -31,6 +31,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to
| h-raylib | **4.5** | [Haskell](https://haskell.org/) | Apache-2.0 | https://github.com/Anut-py/h-raylib |
| raylib-hx | 4.2 | [Haxe](https://haxe.org/) | Zlib | https://github.com/foreignsasquatch/raylib-hx |
| hb-raylib | 3.5 | [Harbour](https://harbour.github.io) | MIT | https://github.com/MarcosLeonardoMendezGerencir/hb-raylib |
| jaylib | 4.5 | [Janet](https://janet-lang.org/) | MIT | https://github.com/janet-lang/jaylib |
| jaylib | 4.2 | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | GPLv3+CE | https://github.com/electronstudio/jaylib/ |
| raylib-j | 4.0 | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | Zlib | https://github.com/CreedVI/Raylib-J |
| raylib.jl | 4.2 | [Julia](https://julialang.org/) | Zlib | https://github.com/irishgreencitrus/raylib.jl |
@ -133,7 +134,6 @@ These are older raylib bindings that are more than 2 versions old or have not be
| raylib-jai | 3.1-dev | [Jai](https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md) | https://github.com/kujukuju/raylib-jai |
| ray.zig | 2.5 | [Zig](https://ziglang.org/) | https://github.com/BitPuffin/zig-raylib-experiments |
| raylib-Ada | 3.0 | [Ada](https://www.adacore.com/about-ada) | https://github.com/mimo/raylib-Ada |
| jaylib | 3.0 | [Janet](https://janet-lang.org/) | https://github.com/janet-lang/jaylib |
| raykit | ? | [Kit](https://www.kitlang.org/) | https://github.com/Gamerfiend/raykit |
| ray.mod | 3.0 | [BlitzMax](https://blitzmax.org/) | https://github.com/bmx-ng/ray.mod |
| raylib-mosaic | 3.0 | [Mosaic](https://github.com/sal55/langs/tree/master/Mosaic) | https://github.com/pluckyporcupine/raylib-mosaic |

6
FAQ.md
View File

@ -14,7 +14,7 @@
- [What does raylib provide that other engines or libraries don't?](#what-does-raylib-provide-that-other-engines-or-libraries-dont)
- [How does raylib compare to Unity/Unreal/Godot?](#how-does-raylib-compare-to-unityunrealgodot)
- [What development tools are required for raylib?](#what-development-tools-are-required-for-raylib)
- [Which are raylib external dependencies?](#which-are-raylib-external-dependencies)
- [What are raylib's external dependencies?](#what-are-raylibs-external-dependencies)
- [Can I use raylib with other technologies or libraries?](#can-i-use-raylib-with-other-technologies-or-libraries)
- [What file formats are supported by raylib?](#what-file-formats-are-supported-by-raylib)
- [Does raylib support the Vulkan API?](#does-raylib-support-the-vulkan-api)
@ -119,8 +119,8 @@ raylib can load data from multiple standard file formats:
- Image/Textures: PNG, BMP, TGA, JPG, GIF, QOI, PSD, DDS, HDR, KTX, ASTC, PKM, PVR
- Fonts: FNT (sprite font), TTF, OTF
- Models/Meshes: OBJ, IQM, GLTF, VOX
- Audio: WAV, OGG, MP3, FLAC, XM, MOD
- Models/Meshes: OBJ, IQM, GLTF, VOX, M3D
- Audio: WAV, OGG, MP3, FLAC, XM, MOD, QOA
### Does raylib support the Vulkan API?

View File

@ -1,4 +1,4 @@
<img align="left" src="https://github.com/raysan5/raylib/blob/master/logo/raylib_logo_animation.gif" width="288px">
<img align="left" style="width:260px" src="https://github.com/raysan5/raylib/blob/master/logo/raylib_logo_animation.gif" width="288px">
**raylib is a simple and easy-to-use library to enjoy videogames programming.**

View File

@ -1,6 +1,7 @@
const std = @import("std");
const raylib = @import("src/build.zig");
pub fn build(b: *std.build.Builder) void {
// This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
pub fn build(b: *std.Build) void {
raylib.build(b);
}

View File

@ -25,7 +25,7 @@ if (${PLATFORM} MATCHES "Desktop")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
find_package(OpenGL QUIET)
set(LIBS_PRIVATE ${OPENGL_LIBRARIES} winmm)
else ()
elseif (UNIX)
find_library(pthread NAMES pthread)
find_package(OpenGL QUIET)
if ("${OPENGL_LIBRARIES}" STREQUAL "")
@ -36,9 +36,22 @@ if (${PLATFORM} MATCHES "Desktop")
find_library(OSS_LIBRARY ossaudio)
endif ()
set(LIBS_PRIVATE m pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY})
else ()
find_library(pthread NAMES pthread)
find_package(OpenGL QUIET)
if ("${OPENGL_LIBRARIES}" STREQUAL "")
set(OPENGL_LIBRARIES "GL")
endif ()
set(LIBS_PRIVATE m atomic pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY})
if (USE_AUDIO)
if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD")
find_library(OSS_LIBRARY ossaudio)
set(LIBS_PRIVATE m pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY})
endif ()
if (NOT "${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD" AND USE_AUDIO)
set(LIBS_PRIVATE ${LIBS_PRIVATE} dl)
endif ()
endif ()

View File

@ -453,6 +453,7 @@ TEXTURES = \
textures/textures_image_generation \
textures/textures_image_loading \
textures/textures_image_processing \
textures/textures_image_rotate \
textures/textures_image_text \
textures/textures_to_image \
textures/textures_raw_data \

View File

@ -1,6 +1,7 @@
const std = @import("std");
const builtin = @import("builtin");
// This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step {
if (target.getOsTag() == .emscripten) {
@panic("Emscripten building via Zig unsupported");

View File

@ -13,7 +13,7 @@
#include "raylib.h"
#define NUM_TEXTURES 6 // Currently we have 7 generation algorithms
#define NUM_TEXTURES 9 // Currently we have 8 generation algorithms but some are have multiple purposes (Linear and Square Gradients)
//------------------------------------------------------------------------------------
// Program main entry point
@ -27,28 +27,37 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - procedural images generation");
Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE);
Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE);
Image verticalGradient = GenImageGradientLinear(screenWidth, screenHeight, 0, RED, BLUE);
Image horizontalGradient = GenImageGradientLinear(screenWidth, screenHeight, 90, RED, BLUE);
Image diagonalGradient = GenImageGradientLinear(screenWidth, screenHeight, 45, RED, BLUE);
Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK);
Image squareGradient = GenImageGradientSquare(screenWidth, screenHeight, 0.0f, WHITE, BLACK);
Image checked = GenImageChecked(screenWidth, screenHeight, 32, 32, RED, BLUE);
Image whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f);
Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f);
Image cellular = GenImageCellular(screenWidth, screenHeight, 32);
Texture2D textures[NUM_TEXTURES] = { 0 };
textures[0] = LoadTextureFromImage(verticalGradient);
textures[1] = LoadTextureFromImage(horizontalGradient);
textures[2] = LoadTextureFromImage(radialGradient);
textures[3] = LoadTextureFromImage(checked);
textures[4] = LoadTextureFromImage(whiteNoise);
textures[5] = LoadTextureFromImage(cellular);
textures[2] = LoadTextureFromImage(diagonalGradient);
textures[3] = LoadTextureFromImage(radialGradient);
textures[4] = LoadTextureFromImage(squareGradient);
textures[5] = LoadTextureFromImage(checked);
textures[6] = LoadTextureFromImage(whiteNoise);
textures[7] = LoadTextureFromImage(perlinNoise);
textures[8] = LoadTextureFromImage(cellular);
// Unload image data (CPU RAM)
UnloadImage(verticalGradient);
UnloadImage(horizontalGradient);
UnloadImage(diagonalGradient);
UnloadImage(radialGradient);
UnloadImage(squareGradient);
UnloadImage(checked);
UnloadImage(whiteNoise);
UnloadImage(perlinNoise);
UnloadImage(cellular);
int currentTexture = 0;
@ -83,10 +92,13 @@ int main(void)
{
case 0: DrawText("VERTICAL GRADIENT", 560, 10, 20, RAYWHITE); break;
case 1: DrawText("HORIZONTAL GRADIENT", 540, 10, 20, RAYWHITE); break;
case 2: DrawText("RADIAL GRADIENT", 580, 10, 20, LIGHTGRAY); break;
case 3: DrawText("CHECKED", 680, 10, 20, RAYWHITE); break;
case 4: DrawText("WHITE NOISE", 640, 10, 20, RED); break;
case 5: DrawText("CELLULAR", 670, 10, 20, RAYWHITE); break;
case 2: DrawText("DIAGONAL GRADIENT", 540, 10, 20, RAYWHITE); break;
case 3: DrawText("RADIAL GRADIENT", 580, 10, 20, LIGHTGRAY); break;
case 4: DrawText("SQUARE GRADIENT", 580, 10, 20, LIGHTGRAY); break;
case 5: DrawText("CHECKED", 680, 10, 20, RAYWHITE); break;
case 6: DrawText("WHITE NOISE", 640, 10, 20, RED); break;
case 7: DrawText("PERLIN NOISE", 640, 10, 20, RED); break;
case 8: DrawText("CELLULAR", 670, 10, 20, RAYWHITE); break;
default: break;
}

View File

@ -0,0 +1,79 @@
/*******************************************************************************************
*
* raylib [textures] example - Image Rotation
*
* Example originally created with raylib 1.0, last time updated with raylib 1.0
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#define NUM_TEXTURES 3
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture rotation");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Image image45 = LoadImage("resources/raylib_logo.png");
Image image90 = LoadImage("resources/raylib_logo.png");
Image imageNeg90 = LoadImage("resources/raylib_logo.png");
ImageRotate(&image45, 45);
ImageRotate(&image90, 90);
ImageRotate(&imageNeg90, -90);
Texture2D textures[NUM_TEXTURES] = { 0 };
textures[0] = LoadTextureFromImage(image45);
textures[1] = LoadTextureFromImage(image90);
textures[2] = LoadTextureFromImage(imageNeg90);
int currentTexture = 0;
//---------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsKeyPressed(KEY_RIGHT))
{
currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexture(textures[currentTexture], screenWidth/2 - textures[currentTexture].width/2, screenHeight/2 - textures[currentTexture].height/2, WHITE);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -15,7 +15,7 @@
{
"name": "RAYLIB_VERSION_MINOR",
"type": "INT",
"value": 5,
"value": 6,
"description": ""
},
{
@ -27,7 +27,7 @@
{
"name": "RAYLIB_VERSION",
"type": "STRING",
"value": "4.5",
"value": "4.6-dev",
"description": ""
},
{
@ -1032,6 +1032,11 @@
"type": "Transform **",
"name": "framePoses",
"description": "Poses array by frame"
},
{
"type": "char[32]",
"name": "name",
"description": "Animation name"
}
]
},
@ -6236,8 +6241,8 @@
]
},
{
"name": "GenImageGradientV",
"description": "Generate image: vertical gradient",
"name": "GenImageGradientLinear",
"description": "Generate image: linear gradient, direction in degrees [0..360], 0=Vertical gradient",
"returnType": "Image",
"params": [
{
@ -6248,36 +6253,17 @@
"type": "int",
"name": "height"
},
{
"type": "Color",
"name": "top"
},
{
"type": "Color",
"name": "bottom"
}
]
},
{
"name": "GenImageGradientH",
"description": "Generate image: horizontal gradient",
"returnType": "Image",
"params": [
{
"type": "int",
"name": "width"
},
{
"type": "int",
"name": "height"
"name": "direction"
},
{
"type": "Color",
"name": "left"
"name": "start"
},
{
"type": "Color",
"name": "right"
"name": "end"
}
]
},
@ -6308,6 +6294,33 @@
}
]
},
{
"name": "GenImageGradientSquare",
"description": "Generate image: square gradient",
"returnType": "Image",
"params": [
{
"type": "int",
"name": "width"
},
{
"type": "int",
"name": "height"
},
{
"type": "float",
"name": "density"
},
{
"type": "Color",
"name": "inner"
},
{
"type": "Color",
"name": "outer"
}
]
},
{
"name": "GenImageChecked",
"description": "Generate image: checked",
@ -6744,6 +6757,21 @@
}
]
},
{
"name": "ImageRotate",
"description": "Rotate image by input angle in degrees (-359 to 359) ",
"returnType": "void",
"params": [
{
"type": "Image *",
"name": "image"
},
{
"type": "int",
"name": "degrees"
}
]
},
{
"name": "ImageRotateCW",
"description": "Rotate image clockwise 90deg",

View File

@ -15,7 +15,7 @@ return {
{
name = "RAYLIB_VERSION_MINOR",
type = "INT",
value = 5,
value = 6,
description = ""
},
{
@ -27,7 +27,7 @@ return {
{
name = "RAYLIB_VERSION",
type = "STRING",
value = "4.5",
value = "4.6-dev",
description = ""
},
{
@ -1032,6 +1032,11 @@ return {
type = "Transform **",
name = "framePoses",
description = "Poses array by frame"
},
{
type = "char[32]",
name = "name",
description = "Animation name"
}
}
},
@ -4991,25 +4996,15 @@ return {
}
},
{
name = "GenImageGradientV",
description = "Generate image: vertical gradient",
name = "GenImageGradientLinear",
description = "Generate image: linear gradient, direction in degrees [0..360], 0=Vertical gradient",
returnType = "Image",
params = {
{type = "int", name = "width"},
{type = "int", name = "height"},
{type = "Color", name = "top"},
{type = "Color", name = "bottom"}
}
},
{
name = "GenImageGradientH",
description = "Generate image: horizontal gradient",
returnType = "Image",
params = {
{type = "int", name = "width"},
{type = "int", name = "height"},
{type = "Color", name = "left"},
{type = "Color", name = "right"}
{type = "int", name = "direction"},
{type = "Color", name = "start"},
{type = "Color", name = "end"}
}
},
{
@ -5024,6 +5019,18 @@ return {
{type = "Color", name = "outer"}
}
},
{
name = "GenImageGradientSquare",
description = "Generate image: square gradient",
returnType = "Image",
params = {
{type = "int", name = "width"},
{type = "int", name = "height"},
{type = "float", name = "density"},
{type = "Color", name = "inner"},
{type = "Color", name = "outer"}
}
},
{
name = "GenImageChecked",
description = "Generate image: checked",
@ -5259,6 +5266,15 @@ return {
{type = "Image *", name = "image"}
}
},
{
name = "ImageRotate",
description = "Rotate image by input angle in degrees (-359 to 359) ",
returnType = "void",
params = {
{type = "Image *", name = "image"},
{type = "int", name = "degrees"}
}
},
{
name = "ImageRotateCW",
description = "Rotate image clockwise 90deg",

File diff suppressed because it is too large Load Diff

View File

@ -3,9 +3,9 @@
<Defines count="56">
<Define name="RAYLIB_H" type="GUARD" value="" desc="" />
<Define name="RAYLIB_VERSION_MAJOR" type="INT" value="4" desc="" />
<Define name="RAYLIB_VERSION_MINOR" type="INT" value="5" desc="" />
<Define name="RAYLIB_VERSION_MINOR" type="INT" value="6" desc="" />
<Define name="RAYLIB_VERSION_PATCH" type="INT" value="0" desc="" />
<Define name="RAYLIB_VERSION" type="STRING" value="4.5" desc="" />
<Define name="RAYLIB_VERSION" type="STRING" value="4.6-dev" desc="" />
<Define name="__declspec(x)" type="MACRO" value="__attribute__((x))" desc="" />
<Define name="RLAPI" type="UNKNOWN" value="__declspec(dllexport)" desc="We are building the library as a Win32 shared library (.dll)" />
<Define name="PI" type="FLOAT" value="3.14159265358979323846" desc="" />
@ -210,11 +210,12 @@
<Field type="BoneInfo *" name="bones" desc="Bones information (skeleton)" />
<Field type="Transform *" name="bindPose" desc="Bones base transformation (pose)" />
</Struct>
<Struct name="ModelAnimation" fieldCount="4" desc="ModelAnimation">
<Struct name="ModelAnimation" fieldCount="5" desc="ModelAnimation">
<Field type="int" name="boneCount" desc="Number of bones" />
<Field type="int" name="frameCount" desc="Number of animation frames" />
<Field type="BoneInfo *" name="bones" desc="Bones information (skeleton)" />
<Field type="Transform **" name="framePoses" desc="Poses array by frame" />
<Field type="char[32]" name="name" desc="Animation name" />
</Struct>
<Struct name="Ray" fieldCount="2" desc="Ray, ray for raycasting">
<Field type="Vector3" name="position" desc="Ray position (origin)" />
@ -655,7 +656,7 @@
<Param type="unsigned int" name="frames" desc="" />
</Callback>
</Callbacks>
<Functions count="517">
<Functions count="518">
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
@ -1548,17 +1549,12 @@
<Param type="int" name="height" desc="" />
<Param type="Color" name="color" desc="" />
</Function>
<Function name="GenImageGradientV" retType="Image" paramCount="4" desc="Generate image: vertical gradient">
<Function name="GenImageGradientLinear" retType="Image" paramCount="5" desc="Generate image: linear gradient, direction in degrees [0..360], 0=Vertical gradient">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
<Param type="Color" name="top" desc="" />
<Param type="Color" name="bottom" desc="" />
</Function>
<Function name="GenImageGradientH" retType="Image" paramCount="4" desc="Generate image: horizontal gradient">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
<Param type="Color" name="left" desc="" />
<Param type="Color" name="right" desc="" />
<Param type="int" name="direction" desc="" />
<Param type="Color" name="start" desc="" />
<Param type="Color" name="end" desc="" />
</Function>
<Function name="GenImageGradientRadial" retType="Image" paramCount="5" desc="Generate image: radial gradient">
<Param type="int" name="width" desc="" />
@ -1567,6 +1563,13 @@
<Param type="Color" name="inner" desc="" />
<Param type="Color" name="outer" desc="" />
</Function>
<Function name="GenImageGradientSquare" retType="Image" paramCount="5" desc="Generate image: square gradient">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
<Param type="float" name="density" desc="" />
<Param type="Color" name="inner" desc="" />
<Param type="Color" name="outer" desc="" />
</Function>
<Function name="GenImageChecked" retType="Image" paramCount="6" desc="Generate image: checked">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
@ -1682,6 +1685,10 @@
<Function name="ImageFlipHorizontal" retType="void" paramCount="1" desc="Flip image horizontally">
<Param type="Image *" name="image" desc="" />
</Function>
<Function name="ImageRotate" retType="void" paramCount="2" desc="Rotate image by input angle in degrees (-359 to 359) ">
<Param type="Image *" name="image" desc="" />
<Param type="int" name="degrees" desc="" />
</Function>
<Function name="ImageRotateCW" retType="void" paramCount="1" desc="Rotate image clockwise 90deg">
<Param type="Image *" name="image" desc="" />
</Function>

View File

@ -5,12 +5,13 @@ project(example)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Dependencies
set(RAYLIB_VERSION 4.2.0)
set(RAYLIB_VERSION 4.5.0)
find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED
if (NOT raylib_FOUND) # If there's none, fetch and build raylib
include(FetchContent)
FetchContent_Declare(
raylib
DOWNLOAD_EXTRACT_TIMESTAMP OFF
URL https://github.com/raysan5/raylib/archive/refs/tags/${RAYLIB_VERSION}.tar.gz
)
FetchContent_GetProperties(raylib)

View File

@ -202,6 +202,7 @@ ImageDrawText|void|(Image *dst, Vector2 position, const char *text, int fontSize
ImageDrawTextEx|void|(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float spacing, Color color);|
ImageFlipVertical|void|(Image *image);|
ImageFlipHorizontal|void|(Image *image);|
ImageRotate|void|(Image *image, int degrees);|
ImageRotateCW|void|(Image *image);|
ImageRotateCCW|void|(Image *image);|
ImageColorTint|void|(Image *image, Color color);|
@ -211,9 +212,9 @@ ImageColorContrast|void|(Image *image, float contrast);|
ImageColorBrightness|void|(Image *image, int brightness);|
ImageColorReplace|void|(Image *image, Color color, Color replace);|
GenImageColor|Image|(int width, int height, Color color);|
GenImageGradientV|Image|(int width, int height, Color top, Color bottom);|
GenImageGradientH|Image|(int width, int height, Color left, Color right);|
GenImageGradientLinear|Image|(int width, int height, int direction, Color start, Color end);|
GenImageGradientRadial|Image|(int width, int height, float density, Color inner, Color outer);|
GenImageGradientSquare|Image|(int width, int height, float density, Color inner, Color outer);|
GenImageChecked|Image|(int width, int height, int checksX, int checksY, Color col1, Color col2);|
GenImageWhiteNoise|Image|(int width, int height, float factor);|
GenImagePerlinNoise|Image|(int width, int height, int offsetX, int offsetY, float scale);|

View File

@ -1378,20 +1378,13 @@
<Param name="Color color" />
</Overload>
</KeyWord>
<KeyWord name="GenImageGradientV" func="yes">
<Overload retVal="Image" descr="Generate image: vertical gradient">
<KeyWord name="GenImageGradientLinear" func="yes">
<Overload retVal="Image" descr="Generate image: linear gradient">
<Param name="int width" />
<Param name="int height" />
<Param name="Color top" />
<Param name="Color bottom" />
</Overload>
</KeyWord>
<KeyWord name="GenImageGradientH" func="yes">
<Overload retVal="Image" descr="Generate image: horizontal gradient">
<Param name="int width" />
<Param name="int height" />
<Param name="Color left" />
<Param name="Color right" />
<Param name="int direction" />
<Param name="Color start" />
<Param name="Color end" />
</Overload>
</KeyWord>
<KeyWord name="GenImageGradientRadial" func="yes">
@ -1403,6 +1396,15 @@
<Param name="Color outer" />
</Overload>
</KeyWord>
<KeyWord name="GenImageGradientSquare" func="yes">
<Overload retVal="Image" descr="Generate image: square gradient">
<Param name="int width" />
<Param name="int height" />
<Param name="float density" />
<Param name="Color inner" />
<Param name="Color outer" />
</Overload>
</KeyWord>
<KeyWord name="GenImageChecked" func="yes">
<Overload retVal="Image" descr="Generate image: checked">
<Param name="int width" />
@ -1568,6 +1570,12 @@
<Param name="Image *image" />
</Overload>
</KeyWord>
<KeyWord name="ImageRotate" func="yes">
<Overload retVal="void" descr="Rotate image by input angle in degrees (-359 to 359)">
<Param name="Image *image" />
<Param name="int degrees" />
</Overload>
</KeyWord>
<KeyWord name="ImageRotateCW" func="yes">
<Overload retVal="void" descr="Rotate image clockwise 90deg">
<Param name="Image *image" />

View File

@ -317,9 +317,9 @@ RLAPI bool ExportImageAsCode(Image image, const char *fileName);
// Image generation functions
RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color
RLAPI Image GenImageGradientV(int width, int height, Color top, Color bottom); // Generate image: vertical gradient
RLAPI Image GenImageGradientH(int width, int height, Color left, Color right); // Generate image: horizontal gradient
RLAPI Image GenImageGradientLinear(int width, int height, int direction, Color start, Color end); // Generate image: linear gradient
RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient
RLAPI Image GenImageGradientSquare(int width, int height, float density, Color inner, Color outer); // Generate image: square gradient
RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2); // Generate image: checked
RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise
RLAPI Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale); // Generate image: perlin noise
@ -346,6 +346,7 @@ RLAPI void ImageMipmaps(Image *image);
RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
RLAPI void ImageFlipVertical(Image *image); // Flip image vertically
RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally
RLAPI void ImageRotate(Image *image, int degrees); // Rotate image by input angle in degrees (-359 to 359)
RLAPI void ImageRotateCW(Image *image); // Rotate image clockwise 90deg
RLAPI void ImageRotateCCW(Image *image); // Rotate image counter-clockwise 90deg
RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint

View File

@ -1,6 +1,7 @@
const std = @import("std");
pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
// This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) *std.Build.CompileStep {
const raylib_flags = &[_][]const u8{
"-std=gnu99",
"-D_GNU_SOURCE",
@ -8,7 +9,11 @@ pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
};
const raylib = b.addStaticLibrary("raylib", null);
const raylib = b.addStaticLibrary(.{
.name = "raylib",
.target = target,
.optimize = optimize,
});
raylib.linkLibC();
raylib.addIncludePath(srcdir ++ "/external/glfw/include");
@ -99,7 +104,7 @@ pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.
return raylib;
}
pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
@ -108,10 +113,10 @@ pub fn build(b: *std.build.Builder) void {
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
// const optimize = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});
const lib = addRaylib(b, target);
b.installFile("src/raylib.h", "raylib.h");
const lib = addRaylib(b, target, optimize);
lib.installHeader("src/raylib.h", "raylib.h");
b.installArtifact(lib);
}

3964
src/external/miniaudio.h vendored

File diff suppressed because it is too large Load Diff

View File

@ -1239,9 +1239,9 @@ RLAPI bool ExportImageAsCode(Image image, const char *fileName);
// Image generation functions
RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color
RLAPI Image GenImageGradientV(int width, int height, Color top, Color bottom); // Generate image: vertical gradient
RLAPI Image GenImageGradientH(int width, int height, Color left, Color right); // Generate image: horizontal gradient
RLAPI Image GenImageGradientLinear(int width, int height, int direction, Color start, Color end); // Generate image: linear gradient, direction in degrees [0..360], 0=Vertical gradient
RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient
RLAPI Image GenImageGradientSquare(int width, int height, float density, Color inner, Color outer); // Generate image: square gradient
RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2); // Generate image: checked
RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise
RLAPI Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale); // Generate image: perlin noise
@ -1268,6 +1268,7 @@ RLAPI void ImageMipmaps(Image *image);
RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
RLAPI void ImageFlipVertical(Image *image); // Flip image vertically
RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally
RLAPI void ImageRotate(Image *image, int degrees); // Rotate image by input angle in degrees (-359 to 359)
RLAPI void ImageRotateCW(Image *image); // Rotate image clockwise 90deg
RLAPI void ImageRotateCCW(Image *image); // Rotate image counter-clockwise 90deg
RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint

View File

@ -447,14 +447,30 @@ void UpdateCamera(Camera *camera, int mode)
if (IsKeyDown(KEY_Q)) CameraRoll(camera, -CAMERA_ROTATION_SPEED);
if (IsKeyDown(KEY_E)) CameraRoll(camera, CAMERA_ROTATION_SPEED);
CameraYaw(camera, -mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
CameraPitch(camera, -mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
// Camera movement
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
if (!IsGamepadAvailable(0))
{
// Mouse/Keyboard support
CameraYaw(camera, -mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
CameraPitch(camera, -mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
}
else
{
// Gamepad controller support
CameraYaw(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) * 2)*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
CameraPitch(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y) * 2)*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) <= -0.75f) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) <= -0.75f) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) >= 0.75f) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) >= 0.75f) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
}
//if (IsKeyDown(KEY_SPACE)) CameraMoveUp(camera, CAMERA_MOVE_SPEED);
//if (IsKeyDown(KEY_LEFT_CONTROL)) CameraMoveUp(camera, -CAMERA_MOVE_SPEED);
}

View File

@ -718,6 +718,25 @@ void android_main(struct android_app *app)
// NOTE: Return codes != 0 are skipped
(void)main(1, (char *[]) { arg0, NULL });
// Finish native activity
ANativeActivity_finish(CORE.Android.app->activity);
// Android ALooper_pollAll() variables
int pollResult = 0;
int pollEvents = 0;
// Wait for app events to close
while (!CORE.Android.app->destroyRequested)
{
while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&CORE.Android.source)) >= 0)
{
if (CORE.Android.source != NULL) CORE.Android.source->process(CORE.Android.app, CORE.Android.source);
}
}
// WARNING: Check for deallocation and ensure no other processes are running from the application
exit(0); // Closes the application completely without going through Java
}
// NOTE: Add this to header (if apps really need it)
@ -1785,7 +1804,10 @@ int GetCurrentMonitor(void)
monitor = monitors[i];
glfwGetMonitorWorkarea(monitor, &mx, &my, &width, &height);
if (x >= mx && x <= (mx + width) && y >= my && y <= (my + height))
if ((x >= mx) &&
(x < (mx + width)) &&
(y >= my) &&
(y < (my + height)))
{
index = i;
break;
@ -5079,7 +5101,6 @@ void PollInputEvents(void)
// Get current gamepad state
// NOTE: There is no callback available, so we get it manually
// Get remapped buttons
GLFWgamepadstate state = { 0 };
glfwGetGamepadState(i, &state); // This remapps all gamepads so they have their buttons mapped like an xbox controller
@ -5087,7 +5108,7 @@ void PollInputEvents(void)
for (int k = 0; (buttons != NULL) && (k < GLFW_GAMEPAD_BUTTON_DPAD_LEFT + 1) && (k < MAX_GAMEPAD_BUTTONS); k++)
{
GamepadButton button = -1;
int button = -1; // GamepadButton enum values assigned
switch (k)
{
@ -5728,8 +5749,9 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
case APP_CMD_STOP: break;
case APP_CMD_DESTROY:
{
// TODO: Finish activity?
//ANativeActivity_finish(CORE.Android.app->activity);
// NOTE 1: Call ANativeActivity_finish again to free resources unconditionally.
// NOTE 2: You can deallocate other things that are NativeActivity related here.
ANativeActivity_finish(CORE.Android.app->activity);
} break;
case APP_CMD_CONFIG_CHANGED:
{

View File

@ -5434,7 +5434,7 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, unsigned in
cgltf_free(data);
}
UnloadFileData(fileData);
return animations;
}
#endif

View File

@ -1340,7 +1340,7 @@ int TextToInteger(const char *text)
text++;
}
for (int i = 0; ((text[i] >= '0') && (text[i] <= '9')); ++i) value = value*10 + (int)(text[i] - '0');
for (int i = 0; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10 + (int)(text[i] - '0');
return value*sign;
}

View File

@ -684,48 +684,34 @@ Image GenImageColor(int width, int height, Color color)
}
#if defined(SUPPORT_IMAGE_GENERATION)
// Generate image: vertical gradient
Image GenImageGradientV(int width, int height, Color top, Color bottom)
// Generate image: linear gradient
// The direction value specifies the direction of the gradient (in degrees)
// with 0 being vertical (from top to bottom), 90 being horizontal (from left to right).
// The gradient effectively rotates counter-clockwise by the specified amount.
Image GenImageGradientLinear(int width, int height, int direction, Color start, Color end)
{
Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
for (int j = 0; j < height; j++)
{
float factor = (float)j/(float)height;
for (int i = 0; i < width; i++)
{
pixels[j*width + i].r = (int)((float)bottom.r*factor + (float)top.r*(1.f - factor));
pixels[j*width + i].g = (int)((float)bottom.g*factor + (float)top.g*(1.f - factor));
pixels[j*width + i].b = (int)((float)bottom.b*factor + (float)top.b*(1.f - factor));
pixels[j*width + i].a = (int)((float)bottom.a*factor + (float)top.a*(1.f - factor));
}
}
Image image = {
.data = pixels,
.width = width,
.height = height,
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
.mipmaps = 1
};
return image;
}
// Generate image: horizontal gradient
Image GenImageGradientH(int width, int height, Color left, Color right)
{
Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
float radianDirection = (float)(90 - direction)/180.f*3.14159f;
float cosDir = cos(radianDirection);
float sinDir = sin(radianDirection);
for (int i = 0; i < width; i++)
{
float factor = (float)i/(float)width;
for (int j = 0; j < height; j++)
{
pixels[j*width + i].r = (int)((float)right.r*factor + (float)left.r*(1.f - factor));
pixels[j*width + i].g = (int)((float)right.g*factor + (float)left.g*(1.f - factor));
pixels[j*width + i].b = (int)((float)right.b*factor + (float)left.b*(1.f - factor));
pixels[j*width + i].a = (int)((float)right.a*factor + (float)left.a*(1.f - factor));
// Calculate the relative position of the pixel along the gradient direction
float pos = (i*cosDir + j*sinDir)/(width*cosDir + height*sinDir);
float factor = pos;
factor = (factor > 1.0f)? 1.0f : factor; // Clamp to [0,1]
factor = (factor < 0.0f)? 0.0f : factor; // Clamp to [0,1]
// Generate the color for this pixel
pixels[j*width + i].r = (int)((float)end.r*factor + (float)start.r*(1.0f - factor));
pixels[j*width + i].g = (int)((float)end.g*factor + (float)start.g*(1.0f - factor));
pixels[j*width + i].b = (int)((float)end.b*factor + (float)start.b*(1.0f - factor));
pixels[j*width + i].a = (int)((float)end.a*factor + (float)start.a*(1.0f - factor));
}
}
@ -777,6 +763,55 @@ Image GenImageGradientRadial(int width, int height, float density, Color inner,
return image;
}
// Generate image: square gradient
Image GenImageGradientSquare(int width, int height, float density, Color inner, Color outer)
{
Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
float centerX = (float)width/2.0f;
float centerY = (float)height/2.0f;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
// Calculate the Manhattan distance from the center
float distX = fabsf(x - centerX);
float distY = fabsf(y - centerY);
// Normalize the distances by the dimensions of the gradient rectangle
float normalizedDistX = distX / centerX;
float normalizedDistY = distY / centerY;
// Calculate the total normalized Manhattan distance
float manhattanDist = fmax(normalizedDistX, normalizedDistY);
// Subtract the density from the manhattanDist, then divide by (1 - density)
// This makes the gradient start from the center when density is 0, and from the edge when density is 1
float factor = (manhattanDist - density)/(1.0f - density);
// Clamp the factor between 0 and 1
factor = fminf(fmaxf(factor, 0.0f), 1.0f);
// Blend the colors based on the calculated factor
pixels[y*width + x].r = (int)((float)outer.r*factor + (float)inner.r*(1.0f - factor));
pixels[y*width + x].g = (int)((float)outer.g*factor + (float)inner.g*(1.0f - factor));
pixels[y*width + x].b = (int)((float)outer.b*factor + (float)inner.b*(1.0f - factor));
pixels[y*width + x].a = (int)((float)outer.a*factor + (float)inner.a*(1.0f - factor));
}
}
Image image = {
.data = pixels,
.width = width,
.height = height,
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
.mipmaps = 1
};
return image;
}
// Generate image: checked
Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2)
{
@ -833,18 +868,27 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
{
for (int x = 0; x < width; x++)
{
float nx = (float)(x + offsetX)*scale/(float)width;
float ny = (float)(y + offsetY)*scale/(float)height;
float nx = (float)(x + offsetX)*(scale/(float)width);
float ny = (float)(y + offsetY)*(scale/(float)height);
// Basic perlin noise implementation (not used)
//float p = (stb_perlin_noise3(nx, ny, 0.0f, 0, 0, 0);
// Calculate a better perlin noise using fbm (fractal brownian motion)
// Typical values to start playing with:
// lacunarity = ~2.0 -- spacing between successive octaves (use exactly 2.0 for wrapping output)
// gain = 0.5 -- relative weighting applied to each successive octave
// octaves = 6 -- number of "octaves" of noise3() to sum
float p = stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6);
// NOTE: We need to translate the data from [-1..1] to [0..1]
float p = (stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6) + 1.0f)/2.0f;
// Clamp between -1.0f and 1.0f
if (p < -1.0f) p = -1.0f;
if (p > 1.0f) p = 1.0f;
int intensity = (int)(p*255.0f);
// We need to normalize the data from [-1..1] to [0..1]
float np = (p + 1.0f)/2.0f;
int intensity = (int)(np*255.0f);
pixels[y*width + x] = (Color){ intensity, intensity, intensity, 255 };
}
}
@ -2046,7 +2090,7 @@ void ImageFlipHorizontal(Image *image)
{
for (int x = 0; x < image->width; x++)
{
// OPTION 1: Move pixels with memcopy()
// OPTION 1: Move pixels with memcpy()
//memcpy(flippedData + (y*image->width + x)*bytesPerPixel, ((unsigned char *)image->data) + (y*image->width + (image->width - 1 - x))*bytesPerPixel, bytesPerPixel);
// OPTION 2: Just copy data pixel by pixel
@ -2074,6 +2118,65 @@ void ImageFlipHorizontal(Image *image)
}
}
// Rotate image in degrees
void ImageRotate(Image *image, int degrees)
{
// Security check to avoid program crash
if ((image->data == NULL) || (image->width == 0) || (image->height == 0)) return;
if (image->mipmaps > 1) TRACELOG(LOG_WARNING, "Image manipulation only applied to base mipmap level");
if (image->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
else
{
float rad = degrees*PI/180.0f;
float sinRadius = sin(rad);
float cosRadius = cos(rad);
int width = fabsf(image->width*cosRadius) + fabsf(image->height*sinRadius);
int height = fabsf(image->height*cosRadius) + fabsf(image->width*sinRadius);
int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
unsigned char *rotatedData = (unsigned char *)RL_CALLOC(width*height, bytesPerPixel);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
float oldX = ((x - width/2.0f)*cosRadius + (y - height/2.0f)*sinRadius) + image->width/2.0f;
float oldY = ((y - height/2.0f)*cosRadius - (x - width/2.0f)*sinRadius) + image->height/2.0f;
if ((oldX >= 0) && (oldX < image->width) && (oldY >= 0) && (oldY < image->height))
{
int x1 = (int)floorf(oldX);
int y1 = (int)floorf(oldY);
int x2 = MIN(x1 + 1, image->width - 1);
int y2 = MIN(y1 + 1, image->height - 1);
float px = oldX - x1;
float py = oldY - y1;
for (int i = 0; i < bytesPerPixel; i++)
{
float f1 = ((unsigned char *)image->data)[(y1*image->width + x1)*bytesPerPixel + i];
float f2 = ((unsigned char *)image->data)[(y1*image->width + x2)*bytesPerPixel + i];
float f3 = ((unsigned char *)image->data)[(y2*image->width + x1)*bytesPerPixel + i];
float f4 = ((unsigned char *)image->data)[(y2*image->width + x2)*bytesPerPixel + i];
float val = f1*(1 - px)*(1 - py) + f2*px*(1 - py) + f3*(1 - px)*py + f4*px*py;
rotatedData[(y*width + x)*bytesPerPixel + i] = (unsigned char)val;
}
}
}
}
RL_FREE(image->data);
image->data = rotatedData;
image->width = width;
image->height = height;
}
}
// Rotate image clockwise 90deg
void ImageRotateCW(Image *image)
{

View File

@ -207,12 +207,16 @@ unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead)
{
data = (unsigned char *)RL_MALLOC(size*sizeof(unsigned char));
// NOTE: fread() returns number of read elements instead of bytes, so we read [1 byte, size elements]
unsigned int count = (unsigned int)fread(data, sizeof(unsigned char), size, file);
*bytesRead = count;
if (data != NULL)
{
// NOTE: fread() returns number of read elements instead of bytes, so we read [1 byte, size elements]
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);
else TRACELOG(LOG_INFO, "FILEIO: [%s] File loaded successfully", fileName);
if (count != size) TRACELOG(LOG_WARNING, "FILEIO: [%s] File partially loaded", fileName);
else TRACELOG(LOG_INFO, "FILEIO: [%s] File loaded successfully", fileName);
}
else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to allocated memory for file reading", fileName);
}
else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to read file", fileName);
@ -344,16 +348,21 @@ char *LoadFileText(const char *fileName)
if (size > 0)
{
text = (char *)RL_MALLOC((size + 1)*sizeof(char));
unsigned int count = (unsigned int)fread(text, sizeof(char), size, file);
// WARNING: \r\n is converted to \n on reading, so,
// read bytes count gets reduced by the number of lines
if (count < size) text = RL_REALLOC(text, count + 1);
if (text != NULL)
{
unsigned int count = (unsigned int)fread(text, sizeof(char), size, file);
// Zero-terminate the string
text[count] = '\0';
// WARNING: \r\n is converted to \n on reading, so,
// read bytes count gets reduced by the number of lines
if (count < size) text = RL_REALLOC(text, count + 1);
TRACELOG(LOG_INFO, "FILEIO: [%s] Text file loaded successfully", fileName);
// Zero-terminate the string
text[count] = '\0';
TRACELOG(LOG_INFO, "FILEIO: [%s] Text file loaded successfully", fileName);
}
else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to allocated memory for file reading", fileName);
}
else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to read text file", fileName);