Review exposed #defines and allow user re-defining
There are multiple #define values around raylib, usually not exposed for redefinition, just reviewed all of them to allow users redefining them on compile time if required. Also, multiple #define have been renamed and commented.
This commit is contained in:
parent
1c15dc7292
commit
51c3bef497
@ -135,6 +135,9 @@ void SetCameraMoveControls(int frontKey, int backKey,
|
||||
|
||||
#include <math.h> // Required for: sinf(), cosf(), sqrtf()
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#ifndef PI
|
||||
#define PI 3.14159265358979323846
|
||||
#endif
|
||||
@ -145,9 +148,6 @@ void SetCameraMoveControls(int frontKey, int backKey,
|
||||
#define RAD2DEG (180.0f/PI)
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
// Camera mouse movement sensitivity
|
||||
#define CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f
|
||||
#define CAMERA_MOUSE_SCROLL_SENSITIVITY 1.5f
|
||||
|
150
src/core.c
150
src/core.c
@ -113,36 +113,36 @@
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#include "raylib.h" // Declares module functions
|
||||
#include "raylib.h" // Declares module functions
|
||||
|
||||
// Check if config flags have been externally provided on compilation line
|
||||
#if !defined(EXTERNAL_CONFIG_FLAGS)
|
||||
#include "config.h" // Defines module configuration flags
|
||||
#include "config.h" // Defines module configuration flags
|
||||
#else
|
||||
#define RAYLIB_VERSION "3.0"
|
||||
#endif
|
||||
|
||||
#include "utils.h" // Required for: TRACELOG macros
|
||||
#include "utils.h" // Required for: TRACELOG macros
|
||||
|
||||
#if (defined(__linux__) || defined(PLATFORM_WEB)) && _POSIX_C_SOURCE < 199309L
|
||||
#undef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext.
|
||||
#endif
|
||||
|
||||
#define RAYMATH_IMPLEMENTATION // Define external out-of-line implementation of raymath here
|
||||
#include "raymath.h" // Required for: Vector3 and Matrix functions
|
||||
#define RAYMATH_IMPLEMENTATION // Define external out-of-line implementation of raymath here
|
||||
#include "raymath.h" // Required for: Vector3 and Matrix functions
|
||||
|
||||
#define RLGL_IMPLEMENTATION
|
||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
#define GESTURES_IMPLEMENTATION
|
||||
#include "gestures.h" // Gestures detection functionality
|
||||
#include "gestures.h" // Gestures detection functionality
|
||||
#endif
|
||||
|
||||
#if defined(SUPPORT_CAMERA_SYSTEM)
|
||||
#define CAMERA_IMPLEMENTATION
|
||||
#include "camera.h" // Camera system functionality
|
||||
#include "camera.h" // Camera system functionality
|
||||
#endif
|
||||
|
||||
#if defined(SUPPORT_GIF_RECORDING)
|
||||
@ -150,20 +150,16 @@
|
||||
#define RGIF_FREE RL_FREE
|
||||
|
||||
#define RGIF_IMPLEMENTATION
|
||||
#include "external/rgif.h" // Support GIF recording
|
||||
#include "external/rgif.h" // Support GIF recording
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define SUPPORT_HIGH_DPI // Force HighDPI support on macOS
|
||||
#endif
|
||||
#include <stdlib.h> // Required for: srand(), rand(), atexit()
|
||||
#include <stdio.h> // Required for: sprintf() [Used in OpenURL()]
|
||||
#include <string.h> // Required for: strrchr(), strcmp(), strlen()
|
||||
#include <time.h> // Required for: time() [Used in InitTimer()]
|
||||
#include <math.h> // Required for: tan() [Used in BeginMode3D()]
|
||||
|
||||
#include <stdlib.h> // Required for: srand(), rand(), atexit()
|
||||
#include <stdio.h> // Required for: sprintf() [Used in OpenURL()]
|
||||
#include <string.h> // Required for: strrchr(), strcmp(), strlen()
|
||||
#include <time.h> // Required for: time() [Used in InitTimer()]
|
||||
#include <math.h> // Required for: tan() [Used in BeginMode3D()]
|
||||
|
||||
#include <sys/stat.h> // Required for: stat() [Used in GetFileModTime()]
|
||||
#include <sys/stat.h> // Required for: stat() [Used in GetFileModTime()]
|
||||
|
||||
#if (defined(PLATFORM_DESKTOP) || defined(PLATFORM_UWP)) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__))
|
||||
#define DIRENT_MALLOC RL_MALLOC
|
||||
@ -203,65 +199,59 @@
|
||||
#endif
|
||||
|
||||
#elif defined(__linux__)
|
||||
#include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
|
||||
#include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
|
||||
|
||||
//#define GLFW_EXPOSE_NATIVE_X11 // WARNING: Exposing Xlib.h > X.h results in dup symbols for Font type
|
||||
//#define GLFW_EXPOSE_NATIVE_X11 // WARNING: Exposing Xlib.h > X.h results in dup symbols for Font type
|
||||
//#define GLFW_EXPOSE_NATIVE_WAYLAND
|
||||
//#define GLFW_EXPOSE_NATIVE_MIR
|
||||
#include <GLFW/glfw3native.h> // Required for: glfwGetX11Window()
|
||||
#include <GLFW/glfw3native.h> // Required for: glfwGetX11Window()
|
||||
#elif defined(__APPLE__)
|
||||
#include <unistd.h> // Required for: usleep()
|
||||
#include <unistd.h> // Required for: usleep()
|
||||
|
||||
//#define GLFW_EXPOSE_NATIVE_COCOA // WARNING: Fails due to type redefinition
|
||||
#include <GLFW/glfw3native.h> // Required for: glfwGetCocoaWindow()
|
||||
//#define GLFW_EXPOSE_NATIVE_COCOA // WARNING: Fails due to type redefinition
|
||||
#include <GLFW/glfw3native.h> // Required for: glfwGetCocoaWindow()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#define MAX_FILEPATH_LENGTH 4096 // Use Linux PATH_MAX value
|
||||
#else
|
||||
#define MAX_FILEPATH_LENGTH 512 // Use common value
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
//#include <android/sensor.h> // Android sensors functions (accelerometer, gyroscope, light...)
|
||||
#include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
|
||||
#include <android_native_app_glue.h> // Defines basic app state struct and manages activity
|
||||
|
||||
#include <EGL/egl.h> // Khronos EGL library - Native platform display device control functions
|
||||
#include <GLES2/gl2.h> // Khronos OpenGL ES 2.0 library
|
||||
#include <EGL/egl.h> // EGL library - Native platform display device control functions
|
||||
#include <GLES2/gl2.h> // OpenGL ES 2.0 library
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_RPI)
|
||||
#include <fcntl.h> // POSIX file control definitions - open(), creat(), fcntl()
|
||||
#include <unistd.h> // POSIX standard function definitions - read(), close(), STDIN_FILENO
|
||||
#include <termios.h> // POSIX terminal control definitions - tcgetattr(), tcsetattr()
|
||||
#include <pthread.h> // POSIX threads management (inputs reading)
|
||||
#include <dirent.h> // POSIX directory browsing
|
||||
|
||||
#include <sys/ioctl.h> // UNIX System call for device-specific input/output operations - ioctl()
|
||||
#include <linux/kd.h> // Linux: KDSKBMODE, K_MEDIUMRAM constants definition
|
||||
#include <linux/input.h> // Linux: Keycodes constants definition (KEY_A, ...)
|
||||
#include <linux/joystick.h> // Linux: Joystick support library
|
||||
|
||||
#include "bcm_host.h" // Raspberry Pi VideoCore IV access functions
|
||||
|
||||
#include "EGL/egl.h" // Khronos EGL library - Native platform display device control functions
|
||||
#include "EGL/eglext.h" // Khronos EGL library - Extensions
|
||||
#include "GLES2/gl2.h" // Khronos OpenGL ES 2.0 library
|
||||
#include <fcntl.h> // POSIX file control definitions - open(), creat(), fcntl()
|
||||
#include <unistd.h> // POSIX standard function definitions - read(), close(), STDIN_FILENO
|
||||
#include <termios.h> // POSIX terminal control definitions - tcgetattr(), tcsetattr()
|
||||
#include <pthread.h> // POSIX threads management (inputs reading)
|
||||
#include <dirent.h> // POSIX directory browsing
|
||||
|
||||
#include <sys/ioctl.h> // UNIX System call for device-specific input/output operations - ioctl()
|
||||
#include <linux/kd.h> // Linux: KDSKBMODE, K_MEDIUMRAM constants definition
|
||||
#include <linux/input.h> // Linux: Keycodes constants definition (KEY_A, ...)
|
||||
#include <linux/joystick.h> // Linux: Joystick support library
|
||||
|
||||
#include "bcm_host.h" // Raspberry Pi VideoCore IV access functions
|
||||
|
||||
#include "EGL/egl.h" // EGL library - Native platform display device control functions
|
||||
#include "EGL/eglext.h" // EGL library - Extensions
|
||||
#include "GLES2/gl2.h" // OpenGL ES 2.0 library
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_UWP)
|
||||
#include "EGL/egl.h" // Khronos EGL library - Native platform display device control functions
|
||||
#include "EGL/eglext.h" // Khronos EGL library - Extensions
|
||||
#include "GLES2/gl2.h" // Khronos OpenGL ES 2.0 library
|
||||
#include "uwp_events.h" // UWP bootstrapping functions
|
||||
#include "EGL/egl.h" // EGL library - Native platform display device control functions
|
||||
#include "EGL/eglext.h" // EGL library - Extensions
|
||||
#include "GLES2/gl2.h" // OpenGL ES 2.0 library
|
||||
#include "uwp_events.h" // UWP bootstrapping functions
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#define GLFW_INCLUDE_ES2 // GLFW3: Enable OpenGL ES 2.0 (translated to WebGL)
|
||||
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
||||
#include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
|
||||
#define GLFW_INCLUDE_ES2 // GLFW3: Enable OpenGL ES 2.0 (translated to WebGL)
|
||||
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
||||
#include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
|
||||
|
||||
#include <emscripten/emscripten.h> // Emscripten library - LLVM to JavaScript compiler
|
||||
#include <emscripten/html5.h> // Emscripten HTML5 library
|
||||
@ -288,18 +278,36 @@
|
||||
//#define DEFAULT_KEYBOARD_DEV "/dev/input/eventN"
|
||||
//#define DEFAULT_MOUSE_DEV "/dev/input/eventN"
|
||||
//#define DEFAULT_GAMEPAD_DEV "/dev/input/eventN"
|
||||
|
||||
#define MOUSE_SENSITIVITY 0.8f
|
||||
#endif
|
||||
|
||||
#define MAX_GAMEPADS 4 // Max number of gamepads supported
|
||||
#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad)
|
||||
#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad)
|
||||
#ifndef MAX_FILEPATH_LENGTH
|
||||
#if defined(__linux__)
|
||||
#define MAX_FILEPATH_LENGTH 4096 // Maximum length for filepaths (Linux PATH_MAX default value)
|
||||
#else
|
||||
#define MAX_FILEPATH_LENGTH 512 // Maximum length supported for filepaths
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MAX_CHARS_QUEUE 16 // Max number of characters in the input queue
|
||||
#ifndef MAX_GAMEPADS
|
||||
#define MAX_GAMEPADS 4 // Max number of gamepads supported
|
||||
#endif
|
||||
#ifndef MAX_GAMEPAD_AXIS
|
||||
#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad)
|
||||
#endif
|
||||
#ifndef MAX_GAMEPAD_BUTTONS
|
||||
#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad)
|
||||
#endif
|
||||
#ifndef MAX_TOUCH_POINTS
|
||||
#define MAX_TOUCH_POINTS 10 // Maximum number of touch points supported
|
||||
#endif
|
||||
#ifndef MAX_KEY_PRESSED_QUEUE
|
||||
#define MAX_KEY_PRESSED_QUEUE 16 // Max number of characters in the key input queue
|
||||
#endif
|
||||
|
||||
#if defined(SUPPORT_DATA_STORAGE)
|
||||
#define STORAGE_DATA_FILE "storage.data"
|
||||
#ifndef STORAGE_DATA_FILE
|
||||
#define STORAGE_DATA_FILE "storage.data" // Automatic storage filename
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -390,7 +398,7 @@ typedef struct CoreData {
|
||||
char currentKeyState[512]; // Registers current frame key state
|
||||
char previousKeyState[512]; // Registers previous frame key state
|
||||
|
||||
int keyPressedQueue[MAX_CHARS_QUEUE]; // Input characters queue
|
||||
int keyPressedQueue[MAX_KEY_PRESSED_QUEUE]; // Input characters queue
|
||||
int keyPressedQueueCount; // Input characters queue count
|
||||
#if defined(PLATFORM_RPI)
|
||||
int defaultMode; // Default keyboard mode
|
||||
@ -1400,7 +1408,7 @@ void BeginMode3D(Camera3D camera)
|
||||
double top = 0.01*tan(camera.fovy*0.5*DEG2RAD);
|
||||
double right = top*aspect;
|
||||
|
||||
rlFrustum(-right, right, -top, top, RL_NEAR_CULL_DISTANCE, RL_FAR_CULL_DISTANCE);
|
||||
rlFrustum(-right, right, -top, top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||
}
|
||||
else if (camera.type == CAMERA_ORTHOGRAPHIC)
|
||||
{
|
||||
@ -1408,7 +1416,7 @@ void BeginMode3D(Camera3D camera)
|
||||
double top = camera.fovy/2.0;
|
||||
double right = top*aspect;
|
||||
|
||||
rlOrtho(-right, right, -top,top, RL_NEAR_CULL_DISTANCE, RL_FAR_CULL_DISTANCE);
|
||||
rlOrtho(-right, right, -top,top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||
}
|
||||
|
||||
// NOTE: zNear and zFar values are important when computing depth buffer values
|
||||
@ -1521,7 +1529,7 @@ Ray GetMouseRay(Vector2 mouse, Camera camera)
|
||||
if (camera.type == CAMERA_PERSPECTIVE)
|
||||
{
|
||||
// Calculate projection matrix from perspective
|
||||
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), RL_NEAR_CULL_DISTANCE, RL_FAR_CULL_DISTANCE);
|
||||
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||
}
|
||||
else if (camera.type == CAMERA_ORTHOGRAPHIC)
|
||||
{
|
||||
@ -1605,7 +1613,7 @@ Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int heigh
|
||||
if (camera.type == CAMERA_PERSPECTIVE)
|
||||
{
|
||||
// Calculate projection matrix from perspective
|
||||
matProj = MatrixPerspective(camera.fovy * DEG2RAD, ((double)width/(double)height), RL_NEAR_CULL_DISTANCE, RL_FAR_CULL_DISTANCE);
|
||||
matProj = MatrixPerspective(camera.fovy * DEG2RAD, ((double)width/(double)height), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||
}
|
||||
else if (camera.type == CAMERA_ORTHOGRAPHIC)
|
||||
{
|
||||
@ -1614,7 +1622,7 @@ Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int heigh
|
||||
double right = top*aspect;
|
||||
|
||||
// Calculate projection matrix from orthographic
|
||||
matProj = MatrixOrtho(-right, right, -top, top, RL_NEAR_CULL_DISTANCE, RL_FAR_CULL_DISTANCE);
|
||||
matProj = MatrixOrtho(-right, right, -top, top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||
}
|
||||
|
||||
// Calculate view matrix from camera look at (and transpose it)
|
||||
@ -3989,7 +3997,7 @@ static void CharCallback(GLFWwindow *window, unsigned int key)
|
||||
// Ref: https://www.glfw.org/docs/latest/input_guide.html#input_char
|
||||
|
||||
// Check if there is space available in the queue
|
||||
if (CORE.Input.Keyboard.keyPressedQueueCount < MAX_CHARS_QUEUE)
|
||||
if (CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE)
|
||||
{
|
||||
// Add character to the queue
|
||||
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = key;
|
||||
@ -5261,7 +5269,7 @@ void UWPKeyDownEvent(int key, bool down, bool controlKey)
|
||||
|
||||
void UWPKeyCharEvent(int key)
|
||||
{
|
||||
if (CORE.Input.Keyboard.keyPressedQueueCount < MAX_CHARS_QUEUE)
|
||||
if (CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE)
|
||||
{
|
||||
// Add character to the queue
|
||||
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = key;
|
||||
|
@ -174,6 +174,7 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Gestures module state context
|
||||
typedef struct {
|
||||
int current; // Current detected gesture
|
||||
unsigned int enabledFlags; // Enabled gestures flags
|
||||
|
32
src/models.c
32
src/models.c
@ -92,7 +92,9 @@
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#define MAX_MESH_VBO 7 // Maximum number of vbo per mesh
|
||||
#ifndef DEFAULT_MESH_VERTEX_BUFFERS
|
||||
#define DEFAULT_MESH_VERTEX_BUFFERS 7 // Number of vertex buffers (VBO) per mesh
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -1224,7 +1226,7 @@ bool IsModelAnimationValid(Model model, ModelAnimation anim)
|
||||
Mesh GenMeshPoly(int sides, float radius)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
int vertexCount = sides*3;
|
||||
|
||||
// Vertices definition
|
||||
@ -1287,7 +1289,7 @@ Mesh GenMeshPoly(int sides, float radius)
|
||||
Mesh GenMeshPlane(float width, float length, int resX, int resZ)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
#define CUSTOM_MESH_GEN_PLANE
|
||||
#if defined(CUSTOM_MESH_GEN_PLANE)
|
||||
@ -1390,7 +1392,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
|
||||
mesh.vertices = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
|
||||
mesh.texcoords = (float *)RL_MALLOC(plane->ntriangles*3*2*sizeof(float));
|
||||
mesh.normals = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
mesh.vertexCount = plane->ntriangles*3;
|
||||
mesh.triangleCount = plane->ntriangles;
|
||||
@ -1422,7 +1424,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
|
||||
Mesh GenMeshCube(float width, float height, float length)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
#define CUSTOM_MESH_GEN_CUBE
|
||||
#if defined(CUSTOM_MESH_GEN_CUBE)
|
||||
@ -1588,7 +1590,7 @@ par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron
|
||||
RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
par_shapes_mesh *sphere = par_shapes_create_parametric_sphere(slices, rings);
|
||||
par_shapes_scale(sphere, radius, radius, radius);
|
||||
@ -1627,7 +1629,7 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
|
||||
RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
par_shapes_mesh *sphere = par_shapes_create_hemisphere(slices, rings);
|
||||
par_shapes_scale(sphere, radius, radius, radius);
|
||||
@ -1666,7 +1668,7 @@ RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
|
||||
Mesh GenMeshCylinder(float radius, float height, int slices)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
// Instance a cylinder that sits on the Z=0 plane using the given tessellation
|
||||
// levels across the UV domain. Think of "slices" like a number of pizza
|
||||
@ -1726,7 +1728,7 @@ Mesh GenMeshCylinder(float radius, float height, int slices)
|
||||
Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
if (radius > 1.0f) radius = 1.0f;
|
||||
else if (radius < 0.1f) radius = 0.1f;
|
||||
@ -1769,7 +1771,7 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
|
||||
Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
if (radius > 3.0f) radius = 3.0f;
|
||||
else if (radius < 0.5f) radius = 0.5f;
|
||||
@ -1813,7 +1815,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
||||
#define GRAY_VALUE(c) ((c.r+c.g+c.b)/3)
|
||||
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
int mapX = heightmap.width;
|
||||
int mapZ = heightmap.height;
|
||||
@ -1947,7 +1949,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
||||
Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
Color *cubicmapPixels = GetImageData(cubicmap);
|
||||
|
||||
@ -2889,7 +2891,7 @@ static Model LoadOBJ(const char *fileName)
|
||||
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
||||
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
|
||||
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
int vCount = 0;
|
||||
int vtCount = 0;
|
||||
@ -3161,7 +3163,7 @@ static Model LoadIQM(const char *fileName)
|
||||
model.meshes[i].animVertices = RL_CALLOC(model.meshes[i].vertexCount*3, sizeof(float));
|
||||
model.meshes[i].animNormals = RL_CALLOC(model.meshes[i].vertexCount*3, sizeof(float));
|
||||
|
||||
model.meshes[i].vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
model.meshes[i].vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
}
|
||||
|
||||
// Triangles data processing
|
||||
@ -3551,7 +3553,7 @@ static Model LoadGLTF(const char *fileName)
|
||||
model.materials = RL_MALLOC(model.materialCount*sizeof(Material));
|
||||
model.meshMaterial = RL_MALLOC(model.meshCount*sizeof(int));
|
||||
|
||||
for (int i = 0; i < model.meshCount; i++) model.meshes[i].vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
|
||||
for (int i = 0; i < model.meshCount; i++) model.meshes[i].vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
for (int i = 0; i < model.materialCount - 1; i++)
|
||||
{
|
||||
|
33
src/raudio.c
33
src/raudio.c
@ -223,11 +223,18 @@ typedef struct tagBITMAPINFOHEADER {
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#define AUDIO_DEVICE_FORMAT ma_format_f32
|
||||
#define AUDIO_DEVICE_CHANNELS 2
|
||||
#define AUDIO_DEVICE_SAMPLE_RATE 44100
|
||||
|
||||
#define MAX_AUDIO_BUFFER_POOL_CHANNELS 16
|
||||
#ifndef AUDIO_DEVICE_FORMAT
|
||||
#define AUDIO_DEVICE_FORMAT ma_format_f32 // Device output format (float-32bit)
|
||||
#endif
|
||||
#ifndef AUDIO_DEVICE_CHANNELS
|
||||
#define AUDIO_DEVICE_CHANNELS 2 // Device output channels: stereo
|
||||
#endif
|
||||
#ifndef AUDIO_DEVICE_SAMPLE_RATE
|
||||
#define AUDIO_DEVICE_SAMPLE_RATE 44100 // Device output sample rate
|
||||
#endif
|
||||
#ifndef MAX_AUDIO_BUFFER_POOL_CHANNELS
|
||||
#define MAX_AUDIO_BUFFER_POOL_CHANNELS 16 // Audio pool channels
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -391,14 +398,14 @@ void InitAudioDevice(void)
|
||||
// NOTE: Using the default device. Format is floating point because it simplifies mixing.
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.pDeviceID = NULL; // NULL for the default playback AUDIO.System.device.
|
||||
config.playback.format = AUDIO_DEVICE_FORMAT;
|
||||
config.playback.channels = AUDIO_DEVICE_CHANNELS;
|
||||
config.capture.pDeviceID = NULL; // NULL for the default capture AUDIO.System.device.
|
||||
config.capture.format = ma_format_s16;
|
||||
config.capture.channels = 1;
|
||||
config.sampleRate = AUDIO_DEVICE_SAMPLE_RATE;
|
||||
config.dataCallback = OnSendAudioDataToDevice;
|
||||
config.pUserData = NULL;
|
||||
config.playback.format = AUDIO_DEVICE_FORMAT;
|
||||
config.playback.channels = AUDIO_DEVICE_CHANNELS;
|
||||
config.capture.pDeviceID = NULL; // NULL for the default capture AUDIO.System.device.
|
||||
config.capture.format = ma_format_s16;
|
||||
config.capture.channels = 1;
|
||||
config.sampleRate = AUDIO_DEVICE_SAMPLE_RATE;
|
||||
config.dataCallback = OnSendAudioDataToDevice;
|
||||
config.pUserData = NULL;
|
||||
|
||||
result = ma_device_init(&AUDIO.System.context, &config, &AUDIO.System.device);
|
||||
if (result != MA_SUCCESS)
|
||||
|
@ -99,8 +99,6 @@
|
||||
#define DEG2RAD (PI/180.0f)
|
||||
#define RAD2DEG (180.0f/PI)
|
||||
|
||||
#define MAX_TOUCH_POINTS 10 // Maximum number of touch points supported
|
||||
|
||||
// Allow custom memory allocators
|
||||
#ifndef RL_MALLOC
|
||||
#define RL_MALLOC(sz) malloc(sz)
|
||||
|
80
src/rlgl.h
80
src/rlgl.h
@ -606,22 +606,22 @@ RLAPI int GetPixelDataSize(int width, int height, int format);// Get pixel data
|
||||
#if defined(RLGL_IMPLEMENTATION)
|
||||
|
||||
#if defined(RLGL_STANDALONE)
|
||||
#include <stdio.h> // Required for: fopen(), fseek(), fread(), fclose() [LoadFileText]
|
||||
#include <stdio.h> // Required for: fopen(), fseek(), fread(), fclose() [LoadFileText]
|
||||
#else
|
||||
// Check if config flags have been externally provided on compilation line
|
||||
#if !defined(EXTERNAL_CONFIG_FLAGS)
|
||||
#include "config.h" // Defines module configuration flags
|
||||
#include "config.h" // Defines module configuration flags
|
||||
#endif
|
||||
#include "raymath.h" // Required for: Vector3 and Matrix functions
|
||||
#include "raymath.h" // Required for: Vector3 and Matrix functions
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
|
||||
#include <math.h> // Required for: atan2f(), fabs()
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
|
||||
#include <math.h> // Required for: atan2f()
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenGL/gl.h> // OpenGL 1.1 library for OSX
|
||||
#include <OpenGL/gl.h> // OpenGL 1.1 library for OSX
|
||||
#include <OpenGL/glext.h>
|
||||
#else
|
||||
// APIENTRY for OpenGL function pointer declarations is required
|
||||
@ -713,7 +713,6 @@ RLAPI int GetPixelDataSize(int width, int height, int format);// Get pixel data
|
||||
#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
|
||||
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
||||
#endif
|
||||
|
||||
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
|
||||
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
||||
#endif
|
||||
@ -723,25 +722,36 @@ RLAPI int GetPixelDataSize(int width, int height, int format);// Get pixel data
|
||||
#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
|
||||
#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_21)
|
||||
#define GL_LUMINANCE 0x1909
|
||||
#define GL_LUMINANCE_ALPHA 0x190A
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
#define glClearDepth glClearDepthf
|
||||
#define glClearDepth glClearDepthf
|
||||
#define GL_READ_FRAMEBUFFER GL_FRAMEBUFFER
|
||||
#define GL_DRAW_FRAMEBUFFER GL_FRAMEBUFFER
|
||||
#endif
|
||||
|
||||
// Default vertex attribute names on shader to set location points
|
||||
#define DEFAULT_ATTRIB_POSITION_NAME "vertexPosition" // shader-location = 0
|
||||
#define DEFAULT_ATTRIB_TEXCOORD_NAME "vertexTexCoord" // shader-location = 1
|
||||
#define DEFAULT_ATTRIB_NORMAL_NAME "vertexNormal" // shader-location = 2
|
||||
#define DEFAULT_ATTRIB_COLOR_NAME "vertexColor" // shader-location = 3
|
||||
#define DEFAULT_ATTRIB_TANGENT_NAME "vertexTangent" // shader-location = 4
|
||||
#define DEFAULT_ATTRIB_TEXCOORD2_NAME "vertexTexCoord2" // shader-location = 5
|
||||
// Default shader vertex attribute names to set location points
|
||||
#ifndef DEFAULT_SHADER_ATTRIB_NAME_POSITION
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
|
||||
#endif
|
||||
#ifndef DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
||||
#endif
|
||||
#ifndef DEFAULT_SHADER_ATTRIB_NAME_NORMAL
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
||||
#endif
|
||||
#ifndef DEFAULT_SHADER_ATTRIB_NAME_COLOR
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
||||
#endif
|
||||
#ifndef DEFAULT_SHADER_ATTRIB_NAME_TANGENT
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
||||
#endif
|
||||
#ifndef DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -1386,7 +1396,7 @@ RLAPI void rlScissor(int x, int y, int width, int height) { glScissor(x, y, widt
|
||||
// Enable wire mode
|
||||
void rlEnableWireMode(void)
|
||||
{
|
||||
#if defined (GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||
// NOTE: glPolygonMode() not available on OpenGL ES
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
#endif
|
||||
@ -1395,7 +1405,7 @@ void rlEnableWireMode(void)
|
||||
// Disable wire mode
|
||||
void rlDisableWireMode(void)
|
||||
{
|
||||
#if defined (GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||
// NOTE: glPolygonMode() not available on OpenGL ES
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
#endif
|
||||
@ -3270,7 +3280,7 @@ Texture2D GenTextureCubemap(Shader shader, Texture2D map, int size)
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// Create projection and different views for each face
|
||||
Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_NEAR_CULL_DISTANCE, RL_FAR_CULL_DISTANCE);
|
||||
Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||
Matrix fboViews[6] = {
|
||||
MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
|
||||
MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ -1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
|
||||
@ -3348,7 +3358,7 @@ Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size)
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// Create projection (transposed) and different views for each face
|
||||
Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_NEAR_CULL_DISTANCE, RL_FAR_CULL_DISTANCE);
|
||||
Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||
Matrix fboViews[6] = {
|
||||
MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
|
||||
MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ -1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
|
||||
@ -3429,7 +3439,7 @@ Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size)
|
||||
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
||||
|
||||
// Create projection (transposed) and different views for each face
|
||||
Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_NEAR_CULL_DISTANCE, RL_FAR_CULL_DISTANCE);
|
||||
Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||
Matrix fboViews[6] = {
|
||||
MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
|
||||
MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ -1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
|
||||
@ -3650,7 +3660,7 @@ void SetVrConfiguration(VrDeviceInfo hmd, Shader distortion)
|
||||
|
||||
// Compute camera projection matrices
|
||||
float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1]
|
||||
Matrix proj = MatrixPerspective(fovy, aspect, RL_NEAR_CULL_DISTANCE, RL_FAR_CULL_DISTANCE);
|
||||
Matrix proj = MatrixPerspective(fovy, aspect, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||
RLGL.Vr.config.eyesProjection[0] = MatrixMultiply(proj, MatrixTranslate(projOffset, 0.0f, 0.0f));
|
||||
RLGL.Vr.config.eyesProjection[1] = MatrixMultiply(proj, MatrixTranslate(-projOffset, 0.0f, 0.0f));
|
||||
|
||||
@ -3857,12 +3867,12 @@ static unsigned int LoadShaderProgram(unsigned int vShaderId, unsigned int fShad
|
||||
glAttachShader(program, fShaderId);
|
||||
|
||||
// NOTE: Default attribute shader locations must be binded before linking
|
||||
glBindAttribLocation(program, 0, DEFAULT_ATTRIB_POSITION_NAME);
|
||||
glBindAttribLocation(program, 1, DEFAULT_ATTRIB_TEXCOORD_NAME);
|
||||
glBindAttribLocation(program, 2, DEFAULT_ATTRIB_NORMAL_NAME);
|
||||
glBindAttribLocation(program, 3, DEFAULT_ATTRIB_COLOR_NAME);
|
||||
glBindAttribLocation(program, 4, DEFAULT_ATTRIB_TANGENT_NAME);
|
||||
glBindAttribLocation(program, 5, DEFAULT_ATTRIB_TEXCOORD2_NAME);
|
||||
glBindAttribLocation(program, 0, DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
glBindAttribLocation(program, 1, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
glBindAttribLocation(program, 2, DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
glBindAttribLocation(program, 3, DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
glBindAttribLocation(program, 4, DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
glBindAttribLocation(program, 5, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
|
||||
// NOTE: If some attrib name is no found on the shader, it locations becomes -1
|
||||
|
||||
@ -4014,12 +4024,12 @@ static void SetShaderDefaultLocations(Shader *shader)
|
||||
// vertex texcoord2 location = 5
|
||||
|
||||
// Get handles to GLSL input attibute locations
|
||||
shader->locs[LOC_VERTEX_POSITION] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_POSITION_NAME);
|
||||
shader->locs[LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TEXCOORD_NAME);
|
||||
shader->locs[LOC_VERTEX_TEXCOORD02] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TEXCOORD2_NAME);
|
||||
shader->locs[LOC_VERTEX_NORMAL] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_NORMAL_NAME);
|
||||
shader->locs[LOC_VERTEX_TANGENT] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TANGENT_NAME);
|
||||
shader->locs[LOC_VERTEX_COLOR] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_COLOR_NAME);
|
||||
shader->locs[LOC_VERTEX_POSITION] = glGetAttribLocation(shader->id, DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
shader->locs[LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(shader->id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
shader->locs[LOC_VERTEX_TEXCOORD02] = glGetAttribLocation(shader->id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
shader->locs[LOC_VERTEX_NORMAL] = glGetAttribLocation(shader->id, DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
shader->locs[LOC_VERTEX_TANGENT] = glGetAttribLocation(shader->id, DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
shader->locs[LOC_VERTEX_COLOR] = glGetAttribLocation(shader->id, DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
|
||||
// Get handles to GLSL uniform locations (vertex shader)
|
||||
shader->locs[LOC_MATRIX_MVP] = glGetUniformLocation(shader->id, "mvp");
|
||||
|
67
src/shapes.c
67
src/shapes.c
@ -47,7 +47,12 @@
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
// Nop...
|
||||
|
||||
// Error rate to calculate how many segments we need to draw a smooth circle,
|
||||
// taken from https://stackoverflow.com/a/2244088
|
||||
#ifndef SMOOTH_CIRCLE_ERROR_RATE
|
||||
#define SMOOTH_CIRCLE_ERROR_RATE 0.5f
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -155,17 +160,19 @@ void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color)
|
||||
// Draw line using cubic-bezier curves in-out
|
||||
void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
|
||||
{
|
||||
#define LINE_DIVISIONS 24 // Bezier line divisions
|
||||
#ifndef BEZIER_LINE_DIVISIONS
|
||||
#define BEZIER_LINE_DIVISIONS 24 // Bezier line divisions
|
||||
#endif
|
||||
|
||||
Vector2 previous = startPos;
|
||||
Vector2 current;
|
||||
|
||||
for (int i = 1; i <= LINE_DIVISIONS; i++)
|
||||
for (int i = 1; i <= BEZIER_LINE_DIVISIONS; i++)
|
||||
{
|
||||
// Cubic easing in-out
|
||||
// NOTE: Easing is calculated only for y position value
|
||||
current.y = EaseCubicInOut((float)i, startPos.y, endPos.y - startPos.y, (float)LINE_DIVISIONS);
|
||||
current.x = previous.x + (endPos.x - startPos.x)/ (float)LINE_DIVISIONS;
|
||||
current.y = EaseCubicInOut((float)i, startPos.y, endPos.y - startPos.y, (float)BEZIER_LINE_DIVISIONS);
|
||||
current.x = previous.x + (endPos.x - startPos.x)/ (float)BEZIER_LINE_DIVISIONS;
|
||||
|
||||
DrawLineEx(previous, current, thick, color);
|
||||
|
||||
@ -214,11 +221,8 @@ void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle
|
||||
|
||||
if (segments < 4)
|
||||
{
|
||||
// Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
|
||||
#define CIRCLE_ERROR_RATE 0.5f
|
||||
|
||||
// Calculate the maximum angle between segments based on the error rate.
|
||||
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/radius, 2) - 1);
|
||||
// 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;
|
||||
|
||||
if (segments <= 0) segments = 4;
|
||||
@ -306,13 +310,8 @@ void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int end
|
||||
|
||||
if (segments < 4)
|
||||
{
|
||||
// Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
|
||||
#ifndef CIRCLE_ERROR_RATE
|
||||
#define CIRCLE_ERROR_RATE 0.5f
|
||||
#endif
|
||||
|
||||
// Calculate the maximum angle between segments based on the error rate.
|
||||
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/radius, 2) - 1);
|
||||
// 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;
|
||||
|
||||
if (segments <= 0) segments = 4;
|
||||
@ -454,13 +453,8 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng
|
||||
|
||||
if (segments < 4)
|
||||
{
|
||||
// Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
|
||||
#ifndef CIRCLE_ERROR_RATE
|
||||
#define CIRCLE_ERROR_RATE 0.5f
|
||||
#endif
|
||||
|
||||
// Calculate the maximum angle between segments based on the error rate.
|
||||
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/outerRadius, 2) - 1);
|
||||
// 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;
|
||||
|
||||
if (segments <= 0) segments = 4;
|
||||
@ -550,13 +544,8 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
|
||||
|
||||
if (segments < 4)
|
||||
{
|
||||
// Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
|
||||
#ifndef CIRCLE_ERROR_RATE
|
||||
#define CIRCLE_ERROR_RATE 0.5f
|
||||
#endif
|
||||
|
||||
// Calculate the maximum angle between segments based on the error rate.
|
||||
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/outerRadius, 2) - 1);
|
||||
// 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;
|
||||
|
||||
if (segments <= 0) segments = 4;
|
||||
@ -764,12 +753,8 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co
|
||||
// Calculate number of segments to use for the corners
|
||||
if (segments < 4)
|
||||
{
|
||||
// Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
|
||||
#ifndef CIRCLE_ERROR_RATE
|
||||
#define CIRCLE_ERROR_RATE 0.5f
|
||||
#endif
|
||||
// Calculate the maximum angle between segments based on the error rate.
|
||||
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/radius, 2) - 1);
|
||||
// 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;
|
||||
if (segments <= 0) segments = 4;
|
||||
}
|
||||
@ -988,12 +973,8 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, int
|
||||
// Calculate number of segments to use for the corners
|
||||
if (segments < 4)
|
||||
{
|
||||
// Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
|
||||
#ifndef CIRCLE_ERROR_RATE
|
||||
#define CIRCLE_ERROR_RATE 0.5f
|
||||
#endif
|
||||
// Calculate the maximum angle between segments based on the error rate.
|
||||
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/radius, 2) - 1);
|
||||
// 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;
|
||||
if (segments <= 0) segments = 4;
|
||||
}
|
||||
|
101
src/text.c
101
src/text.c
@ -16,7 +16,7 @@
|
||||
* #define TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH
|
||||
* TextSplit() function static buffer max size
|
||||
*
|
||||
* #define TEXTSPLIT_MAX_SUBSTRINGS_COUNT
|
||||
* #define MAX_TEXTSPLIT_COUNT
|
||||
* TextSplit() function static substrings pointers array (pointing to static buffer)
|
||||
*
|
||||
*
|
||||
@ -73,17 +73,15 @@
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#define MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers used on some functions:
|
||||
// TextFormat(), TextSubtext(), TextToUpper(), TextToLower(), TextToPascal()
|
||||
|
||||
#define MAX_TEXT_UNICODE_CHARS 512 // Maximum number of unicode codepoints
|
||||
|
||||
#if !defined(TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH)
|
||||
#define TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH 1024 // Size of static buffer: TextSplit()
|
||||
#ifndef MAX_TEXT_BUFFER_LENGTH
|
||||
#define MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers used on some functions:
|
||||
// TextFormat(), TextSubtext(), TextToUpper(), TextToLower(), TextToPascal(), TextSplit()
|
||||
#endif
|
||||
|
||||
#if !defined(TEXTSPLIT_MAX_SUBSTRINGS_COUNT)
|
||||
#define TEXTSPLIT_MAX_SUBSTRINGS_COUNT 128 // Size of static pointers array: TextSplit()
|
||||
#ifndef MAX_TEXT_UNICODE_CHARS
|
||||
#define MAX_TEXT_UNICODE_CHARS 512 // Maximum number of unicode codepoints: GetCodepoints()
|
||||
#endif
|
||||
#ifndef MAX_TEXTSPLIT_COUNT
|
||||
#define MAX_TEXTSPLIT_COUNT 128 // Maximum number of substrings to split: TextSplit()
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -295,15 +293,21 @@ Font GetFontDefault()
|
||||
// Load Font from file into GPU memory (VRAM)
|
||||
Font LoadFont(const char *fileName)
|
||||
{
|
||||
// Default hardcoded values for ttf file loading
|
||||
#define DEFAULT_TTF_FONTSIZE 32 // Font first character (32 - space)
|
||||
#define DEFAULT_TTF_NUMCHARS 95 // ASCII 32..126 is 95 glyphs
|
||||
#define DEFAULT_FIRST_CHAR 32 // Expected first char for image sprite font
|
||||
// Default values for ttf font generation
|
||||
#ifndef FONT_TTF_DEFAULT_SIZE
|
||||
#define FONT_TTF_DEFAULT_SIZE 32 // TTF font generation default char size (char-height)
|
||||
#endif
|
||||
#ifndef FONT_TTF_DEFAULT_NUMCHARS
|
||||
#define FONT_TTF_DEFAULT_NUMCHARS 95 // TTF font generation default charset: 95 glyphs (ASCII 32..126)
|
||||
#endif
|
||||
#ifndef FONT_TTF_DEFAULT_FIRST_CHAR
|
||||
#define FONT_TTF_DEFAULT_FIRST_CHAR 32 // TTF font generation default first char for image sprite font (32-Space)
|
||||
#endif
|
||||
|
||||
Font font = { 0 };
|
||||
|
||||
#if defined(SUPPORT_FILEFORMAT_TTF)
|
||||
if (IsFileExtension(fileName, ".ttf;.otf")) font = LoadFontEx(fileName, DEFAULT_TTF_FONTSIZE, NULL, DEFAULT_TTF_NUMCHARS);
|
||||
if (IsFileExtension(fileName, ".ttf;.otf")) font = LoadFontEx(fileName, FONT_TTF_DEFAULT_SIZE, NULL, FONT_TTF_DEFAULT_NUMCHARS);
|
||||
else
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_FNT)
|
||||
@ -312,7 +316,7 @@ Font LoadFont(const char *fileName)
|
||||
#endif
|
||||
{
|
||||
Image image = LoadImage(fileName);
|
||||
if (image.data != NULL) font = LoadFontFromImage(image, MAGENTA, DEFAULT_FIRST_CHAR);
|
||||
if (image.data != NULL) font = LoadFontFromImage(image, MAGENTA, FONT_TTF_DEFAULT_FIRST_CHAR);
|
||||
UnloadImage(image);
|
||||
}
|
||||
|
||||
@ -363,6 +367,10 @@ Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCou
|
||||
// Load an Image font file (XNA style)
|
||||
Font LoadFontFromImage(Image image, Color key, int firstChar)
|
||||
{
|
||||
#ifndef MAX_GLYPHS_FROM_IMAGE
|
||||
#define MAX_GLYPHS_FROM_IMAGE 256 // Maximum number of glyphs supported on image scan
|
||||
#endif
|
||||
|
||||
#define COLOR_EQUAL(col1, col2) ((col1.r == col2.r)&&(col1.g == col2.g)&&(col1.b == col2.b)&&(col1.a == col2.a))
|
||||
|
||||
int charSpacing = 0;
|
||||
@ -371,13 +379,10 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
// Default number of characters supported
|
||||
#define MAX_FONTCHARS 256
|
||||
|
||||
// We allocate a temporal arrays for chars data measures,
|
||||
// once we get the actual number of chars, we copy data to a sized arrays
|
||||
int tempCharValues[MAX_FONTCHARS];
|
||||
Rectangle tempCharRecs[MAX_FONTCHARS];
|
||||
int tempCharValues[MAX_GLYPHS_FROM_IMAGE];
|
||||
Rectangle tempCharRecs[MAX_GLYPHS_FROM_IMAGE];
|
||||
|
||||
Color *pixels = GetImageData(image);
|
||||
|
||||
@ -483,11 +488,18 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
|
||||
{
|
||||
// NOTE: Using some SDF generation default values,
|
||||
// trades off precision with ability to handle *smaller* sizes
|
||||
#define SDF_CHAR_PADDING 4
|
||||
#define SDF_ON_EDGE_VALUE 128
|
||||
#define SDF_PIXEL_DIST_SCALE 64.0f
|
||||
|
||||
#define BITMAP_ALPHA_THRESHOLD 80
|
||||
#ifndef FONT_SDF_CHAR_PADDING
|
||||
#define FONT_SDF_CHAR_PADDING 4 // SDF font generation char padding
|
||||
#endif
|
||||
#ifndef FONT_SDF_ON_EDGE_VALUE
|
||||
#define FONT_SDF_ON_EDGE_VALUE 128 // SDF font generation on edge value
|
||||
#endif
|
||||
#ifndef FONT_SDF_PIXEL_DIST_SCALE
|
||||
#define FONT_SDF_PIXEL_DIST_SCALE 64.0f // SDF font generation pixel distance scale
|
||||
#endif
|
||||
#ifndef FONT_BITMAP_ALPHA_THRESHOLD
|
||||
#define FONT_BITMAP_ALPHA_THRESHOLD 80 // Bitmap (B&W) font generation alpha threshold
|
||||
#endif
|
||||
|
||||
CharInfo *chars = NULL;
|
||||
|
||||
@ -541,7 +553,7 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
|
||||
// stbtt_MakeCodepointBitmap() -- renders into bitmap you provide
|
||||
|
||||
if (type != FONT_SDF) chars[i].image.data = stbtt_GetCodepointBitmap(&fontInfo, scaleFactor, scaleFactor, ch, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY);
|
||||
else if (ch != 32) chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, SDF_CHAR_PADDING, SDF_ON_EDGE_VALUE, SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY);
|
||||
else if (ch != 32) chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, FONT_SDF_CHAR_PADDING, FONT_SDF_ON_EDGE_VALUE, FONT_SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY);
|
||||
else chars[i].image.data = NULL;
|
||||
|
||||
stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL);
|
||||
@ -568,7 +580,7 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
|
||||
// NOTE: For optimum results, bitmap font should be generated at base pixel size
|
||||
for (int p = 0; p < chw*chh; p++)
|
||||
{
|
||||
if (((unsigned char *)chars[i].image.data)[p] < BITMAP_ALPHA_THRESHOLD) ((unsigned char *)chars[i].image.data)[p] = 0;
|
||||
if (((unsigned char *)chars[i].image.data)[p] < FONT_BITMAP_ALPHA_THRESHOLD) ((unsigned char *)chars[i].image.data)[p] = 0;
|
||||
else ((unsigned char *)chars[i].image.data)[p] = 255;
|
||||
}
|
||||
}
|
||||
@ -1053,11 +1065,14 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
|
||||
// Returns index position for a unicode character on spritefont
|
||||
int GetGlyphIndex(Font font, int codepoint)
|
||||
{
|
||||
#define TEXT_CHARACTER_NOTFOUND 63 // Character: '?'
|
||||
#ifndef GLYPH_NOTFOUND_CHAR_FALLBACK
|
||||
#define GLYPH_NOTFOUND_CHAR_FALLBACK 63 // Character used if requested codepoint is not found: '?'
|
||||
#endif
|
||||
|
||||
#define UNORDERED_CHARSET
|
||||
#if defined(UNORDERED_CHARSET)
|
||||
int index = TEXT_CHARACTER_NOTFOUND;
|
||||
// Support charsets with any characters order
|
||||
#define SUPPORT_UNORDERED_CHARSET
|
||||
#if defined(SUPPORT_UNORDERED_CHARSET)
|
||||
int index = GLYPH_NOTFOUND_CHAR_FALLBACK;
|
||||
|
||||
for (int i = 0; i < font.charsCount; i++)
|
||||
{
|
||||
@ -1128,8 +1143,10 @@ unsigned int TextLength(const char *text)
|
||||
// WARNING: String returned will expire after this function is called MAX_TEXTFORMAT_BUFFERS times
|
||||
const char *TextFormat(const char *text, ...)
|
||||
{
|
||||
#define MAX_TEXTFORMAT_BUFFERS 4
|
||||
|
||||
#ifndef MAX_TEXTFORMAT_BUFFERS
|
||||
#define MAX_TEXTFORMAT_BUFFERS 4 // Maximum number of static buffers for text formatting
|
||||
#endif
|
||||
|
||||
// We create an array of buffers so strings don't expire until MAX_TEXTFORMAT_BUFFERS invocations
|
||||
static char buffers[MAX_TEXTFORMAT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
static int index = 0;
|
||||
@ -1279,12 +1296,12 @@ const char **TextSplit(const char *text, char delimiter, int *count)
|
||||
// NOTE: Current implementation returns a copy of the provided string with '\0' (string end delimiter)
|
||||
// inserted between strings defined by "delimiter" parameter. No memory is dynamically allocated,
|
||||
// all used memory is static... it has some limitations:
|
||||
// 1. Maximum number of possible split strings is set by TEXTSPLIT_MAX_SUBSTRINGS_COUNT
|
||||
// 2. Maximum size of text to split is TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH
|
||||
// 1. Maximum number of possible split strings is set by MAX_TEXTSPLIT_COUNT
|
||||
// 2. Maximum size of text to split is MAX_TEXT_BUFFER_LENGTH
|
||||
|
||||
static const char *result[TEXTSPLIT_MAX_SUBSTRINGS_COUNT] = { NULL };
|
||||
static char buffer[TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
memset(buffer, 0, TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH);
|
||||
static const char *result[MAX_TEXTSPLIT_COUNT] = { NULL };
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
|
||||
result[0] = buffer;
|
||||
int counter = 0;
|
||||
@ -1294,7 +1311,7 @@ const char **TextSplit(const char *text, char delimiter, int *count)
|
||||
counter = 1;
|
||||
|
||||
// Count how many substrings we have on text and point to every one
|
||||
for (int i = 0; i < TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH; i++)
|
||||
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
||||
{
|
||||
buffer[i] = text[i];
|
||||
if (buffer[i] == '\0') break;
|
||||
@ -1304,7 +1321,7 @@ const char **TextSplit(const char *text, char delimiter, int *count)
|
||||
result[counter] = buffer + i + 1;
|
||||
counter++;
|
||||
|
||||
if (counter == TEXTSPLIT_MAX_SUBSTRINGS_COUNT) break;
|
||||
if (counter == MAX_TEXTSPLIT_COUNT) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,9 @@
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
// Nop...
|
||||
#ifndef R5G5B5A1_ALPHA_THRESHOLD
|
||||
#define R5G5B5A1_ALPHA_THRESHOLD 50 // Threshold over 255 to set alpha as 0
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -832,7 +834,9 @@ void ExportImage(Image image, const char *fileName)
|
||||
// Export image as code file (.h) defining an array of bytes
|
||||
void ExportImageAsCode(Image image, const char *fileName)
|
||||
{
|
||||
#define BYTES_TEXT_PER_LINE 20
|
||||
#ifndef TEXT_BYTES_PER_LINE
|
||||
#define TEXT_BYTES_PER_LINE 20
|
||||
#endif
|
||||
|
||||
FILE *txtFile = fopen(fileName, "wt");
|
||||
|
||||
@ -863,7 +867,7 @@ void ExportImageAsCode(Image image, const char *fileName)
|
||||
fprintf(txtFile, "#define %s_FORMAT %i // raylib internal pixel format\n\n", varFileName, image.format);
|
||||
|
||||
fprintf(txtFile, "static unsigned char %s_DATA[%i] = { ", varFileName, dataSize);
|
||||
for (int i = 0; i < dataSize - 1; i++) fprintf(txtFile, ((i%BYTES_TEXT_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), ((unsigned char *)image.data)[i]);
|
||||
for (int i = 0; i < dataSize - 1; i++) fprintf(txtFile, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), ((unsigned char *)image.data)[i]);
|
||||
fprintf(txtFile, "0x%x };\n", ((unsigned char *)image.data)[dataSize - 1]);
|
||||
|
||||
fclose(txtFile);
|
||||
@ -1038,8 +1042,6 @@ void ImageFormat(Image *image, int newFormat)
|
||||
} break;
|
||||
case UNCOMPRESSED_R5G5B5A1:
|
||||
{
|
||||
#define ALPHA_THRESHOLD 50
|
||||
|
||||
image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short));
|
||||
|
||||
unsigned char r = 0;
|
||||
@ -1052,7 +1054,7 @@ void ImageFormat(Image *image, int newFormat)
|
||||
r = (unsigned char)(round(pixels[i].x*31.0f));
|
||||
g = (unsigned char)(round(pixels[i].y*31.0f));
|
||||
b = (unsigned char)(round(pixels[i].z*31.0f));
|
||||
a = (pixels[i].w > ((float)ALPHA_THRESHOLD/255.0f))? 1 : 0;
|
||||
a = (pixels[i].w > ((float)R5G5B5A1_ALPHA_THRESHOLD/255.0f))? 1 : 0;
|
||||
|
||||
((unsigned short *)image->data)[i] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a;
|
||||
}
|
||||
@ -2049,15 +2051,13 @@ void ImageDrawPixel(Image *dst, int x, int y, Color color)
|
||||
} break;
|
||||
case UNCOMPRESSED_R5G5B5A1:
|
||||
{
|
||||
#define PIXEL_ALPHA_THRESHOLD 50
|
||||
|
||||
// NOTE: Calculate R5G5B5A1 equivalent color
|
||||
Vector4 coln = { (float)color.r/255.0f, (float)color.g/255.0f, (float)color.b/255.0f, (float)color.a/255.0f };
|
||||
|
||||
unsigned char r = (unsigned char)(round(coln.x*31.0f));
|
||||
unsigned char g = (unsigned char)(round(coln.y*31.0f));
|
||||
unsigned char b = (unsigned char)(round(coln.z*31.0f));
|
||||
unsigned char a = (coln.w > ((float)PIXEL_ALPHA_THRESHOLD/255.0f))? 1 : 0;;
|
||||
unsigned char a = (coln.w > ((float)R5G5B5A1_ALPHA_THRESHOLD/255.0f))? 1 : 0;;
|
||||
|
||||
((unsigned short *)dst->data)[y*dst->width + x] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a;
|
||||
|
||||
|
14
src/utils.c
14
src/utils.c
@ -50,9 +50,15 @@
|
||||
#include <stdarg.h> // Required for: va_list, va_start(), va_end()
|
||||
#include <string.h> // Required for: strcpy(), strcat()
|
||||
|
||||
#define MAX_TRACELOG_BUFFER_SIZE 128 // Max length of one trace-log message
|
||||
|
||||
#define MAX_UWP_MESSAGES 512 // Max UWP messages to process
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#ifndef MAX_TRACELOG_MSG_LENGTH
|
||||
#define MAX_TRACELOG_MSG_LENGTH 128 // Max length of one trace-log message
|
||||
#endif
|
||||
#ifndef MAX_UWP_MESSAGES
|
||||
#define MAX_UWP_MESSAGES 512 // Max UWP messages to process
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
@ -132,7 +138,7 @@ void TraceLog(int logType, const char *text, ...)
|
||||
default: break;
|
||||
}
|
||||
#else
|
||||
char buffer[MAX_TRACELOG_BUFFER_SIZE] = { 0 };
|
||||
char buffer[MAX_TRACELOG_MSG_LENGTH] = { 0 };
|
||||
|
||||
switch (logType)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user