Merge branch 'raysan5:master' into master
This commit is contained in:
commit
b572b1e816
16 changed files with 4184 additions and 1756 deletions
16
src/Makefile
16
src/Makefile
|
|
@ -190,13 +190,15 @@ endif
|
|||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Emscripten required variables
|
||||
EMSDK_PATH ?= C:/emsdk
|
||||
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten
|
||||
CLANG_PATH = $(EMSDK_PATH)/upstream/bin
|
||||
PYTHON_PATH = $(EMSDK_PATH)/python/3.9.2-1_64bit
|
||||
NODE_PATH = $(EMSDK_PATH)/node/14.15.5_64bit/bin
|
||||
export PATH := $(EMSDK_PATH):$(EMSCRIPTEN_PATH):$(CLANG_PATH):$(NODE_PATH):$(PYTHON_PATH):C:\raylib\MinGW\bin:$(PATH)
|
||||
ifeq ($(PLATFORM_OS), WINDOWS)
|
||||
# Emscripten required variables
|
||||
EMSDK_PATH ?= C:/emsdk
|
||||
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten
|
||||
CLANG_PATH := $(EMSDK_PATH)/upstream/bin
|
||||
PYTHON_PATH := $(EMSDK_PATH)/python/3.9.2-1_64bit
|
||||
NODE_PATH := $(EMSDK_PATH)/node/14.15.5_64bit/bin
|
||||
export PATH := $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH);C:/raylib/MinGW/bin;$(PATH)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
||||
|
|
|
|||
|
|
@ -1,20 +1,16 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
|
||||
// Standard release options allow the person running `zig build` to select
|
||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
const raylib_flags = &[_][]const u8{
|
||||
"-std=gnu99",
|
||||
"-DPLATFORM_DESKTOP",
|
||||
"-D_GNU_SOURCE",
|
||||
"-DGL_SILENCE_DEPRECATION=199309L",
|
||||
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
|
||||
};
|
||||
|
||||
const raylib = b.addStaticLibrary("raylib", srcdir ++ "/raylib.h");
|
||||
const raylib = b.addStaticLibrary("raylib", null);
|
||||
raylib.setTarget(target);
|
||||
raylib.setBuildMode(mode);
|
||||
raylib.linkLibC();
|
||||
|
||||
raylib.addIncludePath(srcdir ++ "/external/glfw/include");
|
||||
|
|
@ -68,6 +64,10 @@ pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.
|
|||
raylib_flags ++ raylib_flags_extra_macos,
|
||||
);
|
||||
raylib.linkFramework("Foundation");
|
||||
raylib.linkFramework("CoreServices");
|
||||
raylib.linkFramework("CoreGraphics");
|
||||
raylib.linkFramework("AppKit");
|
||||
raylib.linkFramework("IOKit");
|
||||
},
|
||||
else => {
|
||||
@panic("Unsupported OS");
|
||||
|
|
@ -89,8 +89,8 @@ pub fn build(b: *std.build.Builder) void {
|
|||
lib.install();
|
||||
}
|
||||
|
||||
const srcdir = getSrcDir();
|
||||
|
||||
fn getSrcDir() []const u8 {
|
||||
return std.fs.path.dirname(@src().file) orelse ".";
|
||||
}
|
||||
const srcdir = struct{
|
||||
fn getSrcDir() []const u8 {
|
||||
return std.fs.path.dirname(@src().file).?;
|
||||
}
|
||||
}.getSrcDir();
|
||||
|
|
|
|||
1659
src/external/glfw/src/mappings.h
vendored
1659
src/external/glfw/src/mappings.h
vendored
File diff suppressed because it is too large
Load diff
1414
src/external/miniaudio.h
vendored
1414
src/external/miniaudio.h
vendored
File diff suppressed because it is too large
Load diff
44
src/external/rl_gputex.h
vendored
44
src/external/rl_gputex.h
vendored
|
|
@ -778,28 +778,28 @@ static int get_pixel_data_size(int width, int height, int format)
|
|||
|
||||
switch (format)
|
||||
{
|
||||
case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: bpp = 8; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA:
|
||||
case PIXELFORMAT_UNCOMPRESSED_R5G6B5:
|
||||
case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
|
||||
case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: bpp = 16; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: bpp = 32; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8: bpp = 24; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32: bpp = 32; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32G32B32: bpp = 32*3; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: bpp = 32*4; break;
|
||||
case PIXELFORMAT_COMPRESSED_DXT1_RGB:
|
||||
case PIXELFORMAT_COMPRESSED_DXT1_RGBA:
|
||||
case PIXELFORMAT_COMPRESSED_ETC1_RGB:
|
||||
case PIXELFORMAT_COMPRESSED_ETC2_RGB:
|
||||
case PIXELFORMAT_COMPRESSED_PVRT_RGB:
|
||||
case PIXELFORMAT_COMPRESSED_PVRT_RGBA: bpp = 4; break;
|
||||
case PIXELFORMAT_COMPRESSED_DXT3_RGBA:
|
||||
case PIXELFORMAT_COMPRESSED_DXT5_RGBA:
|
||||
case PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA:
|
||||
case PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA: bpp = 8; break;
|
||||
case PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: bpp = 2; break;
|
||||
default: break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: bpp = 8; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA:
|
||||
case PIXELFORMAT_UNCOMPRESSED_R5G6B5:
|
||||
case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
|
||||
case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: bpp = 16; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: bpp = 32; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8: bpp = 24; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32: bpp = 32; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32G32B32: bpp = 32*3; break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: bpp = 32*4; break;
|
||||
case PIXELFORMAT_COMPRESSED_DXT1_RGB:
|
||||
case PIXELFORMAT_COMPRESSED_DXT1_RGBA:
|
||||
case PIXELFORMAT_COMPRESSED_ETC1_RGB:
|
||||
case PIXELFORMAT_COMPRESSED_ETC2_RGB:
|
||||
case PIXELFORMAT_COMPRESSED_PVRT_RGB:
|
||||
case PIXELFORMAT_COMPRESSED_PVRT_RGBA: bpp = 4; break;
|
||||
case PIXELFORMAT_COMPRESSED_DXT3_RGBA:
|
||||
case PIXELFORMAT_COMPRESSED_DXT5_RGBA:
|
||||
case PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA:
|
||||
case PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA: bpp = 8; break;
|
||||
case PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: bpp = 2; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
data_size = width*height*bpp/8; // Total data size in bytes
|
||||
|
|
|
|||
17
src/external/vox_loader.h
vendored
17
src/external/vox_loader.h
vendored
|
|
@ -67,7 +67,7 @@ revision history:
|
|||
#define VOX_SUCCESS (0)
|
||||
#define VOX_ERROR_FILE_NOT_FOUND (-1)
|
||||
#define VOX_ERROR_INVALID_FORMAT (-2)
|
||||
#define VOX_ERROR_FILE_VERSION_TOO_OLD (-3)
|
||||
#define VOX_ERROR_FILE_VERSION_NOT_MATCH (-3)
|
||||
|
||||
// VoxColor, 4 components, R8G8B8A8 (32bit)
|
||||
typedef struct {
|
||||
|
|
@ -538,31 +538,26 @@ int Vox_LoadFromMemory(unsigned char* pvoxData, unsigned int voxDataSize, VoxArr
|
|||
// @raysan5: Reviewed (unsigned long) -> (unsigned int), possible issue with Ubuntu 18.04 64bit
|
||||
|
||||
// @raysan5: reviewed signature loading
|
||||
unsigned char signature[4] = { 0 };
|
||||
|
||||
unsigned char* fileData = pvoxData;
|
||||
unsigned char* fileDataPtr = fileData;
|
||||
unsigned char* endfileDataPtr = fileData + voxDataSize;
|
||||
|
||||
signature[0] = fileDataPtr[0];
|
||||
signature[1] = fileDataPtr[1];
|
||||
signature[2] = fileDataPtr[2];
|
||||
signature[3] = fileDataPtr[3];
|
||||
fileDataPtr += 4;
|
||||
|
||||
if ((signature[0] != 'V') && (signature[0] != 'O') && (signature[0] != 'X') && (signature[0] != ' '))
|
||||
if (strncmp((char*)fileDataPtr, "VOX ", 4) != 0)
|
||||
{
|
||||
return VOX_ERROR_INVALID_FORMAT; //"Not an MagicaVoxel File format"
|
||||
}
|
||||
|
||||
fileDataPtr += 4;
|
||||
|
||||
// @raysan5: reviewed version loading
|
||||
unsigned int version = 0;
|
||||
version = ((unsigned int*)fileDataPtr)[0];
|
||||
fileDataPtr += 4;
|
||||
|
||||
if (version < 150)
|
||||
if (version != 150)
|
||||
{
|
||||
return VOX_ERROR_FILE_VERSION_TOO_OLD; //"MagicaVoxel version too old"
|
||||
return VOX_ERROR_FILE_VERSION_NOT_MATCH; //"MagicaVoxel version doesn't match"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -526,7 +526,9 @@ void CloseAudioDevice(void)
|
|||
|
||||
AUDIO.System.isReady = false;
|
||||
RL_FREE(AUDIO.System.pcmBuffer);
|
||||
|
||||
AUDIO.System.pcmBuffer = NULL;
|
||||
AUDIO.System.pcmBufferSize = 0;
|
||||
|
||||
TRACELOG(LOG_INFO, "AUDIO: Device closed successfully");
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "AUDIO: Device could not be closed, not currently initialized");
|
||||
|
|
|
|||
36
src/raylib.h
36
src/raylib.h
|
|
@ -1,6 +1,6 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib v4.2 - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
|
||||
* raylib v4.5-dev - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
|
||||
*
|
||||
* FEATURES:
|
||||
* - NO external dependencies, all required libraries included with raylib
|
||||
|
|
@ -81,7 +81,7 @@
|
|||
|
||||
#include <stdarg.h> // Required for: va_list - Only used by TraceLogCallback
|
||||
|
||||
#define RAYLIB_VERSION "4.2"
|
||||
#define RAYLIB_VERSION "4.5-dev"
|
||||
|
||||
// Function specifiers in case library is build/used as a shared library (Windows)
|
||||
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
||||
|
|
@ -305,7 +305,7 @@ typedef struct Camera3D {
|
|||
Vector3 position; // Camera position
|
||||
Vector3 target; // Camera target it looks-at
|
||||
Vector3 up; // Camera up vector (rotation over its axis)
|
||||
float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
|
||||
float fovy; // Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic
|
||||
int projection; // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
|
||||
} Camera3D;
|
||||
|
||||
|
|
@ -364,7 +364,7 @@ typedef struct Material {
|
|||
float params[4]; // Material generic parameters (if required)
|
||||
} Material;
|
||||
|
||||
// Transform, vectex transformation data
|
||||
// Transform, vertex transformation data
|
||||
typedef struct Transform {
|
||||
Vector3 translation; // Translation
|
||||
Quaternion rotation; // Rotation
|
||||
|
|
@ -663,7 +663,7 @@ typedef enum {
|
|||
MOUSE_BUTTON_MIDDLE = 2, // Mouse button middle (pressed wheel)
|
||||
MOUSE_BUTTON_SIDE = 3, // Mouse button side (advanced mouse device)
|
||||
MOUSE_BUTTON_EXTRA = 4, // Mouse button extra (advanced mouse device)
|
||||
MOUSE_BUTTON_FORWARD = 5, // Mouse button fordward (advanced mouse device)
|
||||
MOUSE_BUTTON_FORWARD = 5, // Mouse button forward (advanced mouse device)
|
||||
MOUSE_BUTTON_BACK = 6, // Mouse button back (advanced mouse device)
|
||||
} MouseButton;
|
||||
|
||||
|
|
@ -857,7 +857,8 @@ typedef enum {
|
|||
BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
|
||||
BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
|
||||
BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha
|
||||
BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendMode())
|
||||
BLEND_CUSTOM, // Blend textures using custom src/dst factors (use rlSetBlendFactors())
|
||||
BLEND_CUSTOM_SEPARATE // Blend textures using custom rgb/alpha separate src/dst factors (use rlSetBlendFactorsSeparate())
|
||||
} BlendMode;
|
||||
|
||||
// Gesture
|
||||
|
|
@ -967,7 +968,7 @@ RLAPI void DisableEventWaiting(void); // Disable wai
|
|||
|
||||
// Custom frame control functions
|
||||
// NOTE: Those functions are intended for advance users that want full control over the frame processing
|
||||
// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timming + PollInputEvents()
|
||||
// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timing + PollInputEvents()
|
||||
// To avoid that behaviour and control frame processes manually, enable in config.h: SUPPORT_CUSTOM_FRAME_CONTROL
|
||||
RLAPI void SwapScreenBuffer(void); // Swap back buffer with front buffer (screen drawing)
|
||||
RLAPI void PollInputEvents(void); // Register all input events
|
||||
|
|
@ -1057,7 +1058,7 @@ RLAPI void SetSaveFileTextCallback(SaveFileTextCallback callback); // Set custom
|
|||
RLAPI unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead); // Load file data as byte array (read)
|
||||
RLAPI void UnloadFileData(unsigned char *data); // Unload file data allocated by LoadFileData()
|
||||
RLAPI bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite); // Save data to file from byte array (write), returns true on success
|
||||
RLAPI bool ExportDataAsCode(const char *data, unsigned int size, const char *fileName); // Export data to code (.h), returns true on success
|
||||
RLAPI bool ExportDataAsCode(const unsigned char *data, unsigned int size, const char *fileName); // Export data to code (.h), returns true on success
|
||||
RLAPI char *LoadFileText(const char *fileName); // Load text data from file (read), returns a '\0' terminated string
|
||||
RLAPI void UnloadFileText(char *text); // Unload file text data allocated by LoadFileText()
|
||||
RLAPI bool SaveFileText(const char *fileName, char *text); // Save text data to file (write), string must be '\0' terminated, returns true on success
|
||||
|
|
@ -1243,6 +1244,7 @@ RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Col
|
|||
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
|
||||
RLAPI Image GenImageCellular(int width, int height, int tileSize); // Generate image: cellular algorithm, bigger tileSize means bigger cells
|
||||
RLAPI Image GenImageText(int width, int height, const char *text); // Generate image: grayscale image from text data
|
||||
|
||||
// Image manipulation functions
|
||||
RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations)
|
||||
|
|
@ -1256,6 +1258,7 @@ RLAPI void ImageAlphaCrop(Image *image, float threshold);
|
|||
RLAPI void ImageAlphaClear(Image *image, Color color, float threshold); // Clear alpha channel to desired color
|
||||
RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image
|
||||
RLAPI void ImageAlphaPremultiply(Image *image); // Premultiply alpha channel
|
||||
RLAPI void ImageBlurGaussian(Image *image, int blurSize); // Apply Gaussian blur using a box blur approximation
|
||||
RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize image (Bicubic scaling algorithm)
|
||||
RLAPI void ImageResizeNN(Image *image, int newWidth,int newHeight); // Resize image (Nearest-Neighbor scaling algorithm)
|
||||
RLAPI void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, int offsetY, Color fill); // Resize canvas and fill with color
|
||||
|
|
@ -1318,11 +1321,8 @@ RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint);
|
|||
RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2
|
||||
RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters
|
||||
RLAPI void DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle
|
||||
RLAPI void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Rectangle quad, Color tint); // Draw texture quad with tiling and offset parameters
|
||||
RLAPI void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint); // Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest.
|
||||
RLAPI void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters
|
||||
RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draws a texture (or part of it) that stretches or shrinks nicely
|
||||
RLAPI void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint); // Draw a textured polygon
|
||||
RLAPI void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters
|
||||
RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draws a texture (or part of it) that stretches or shrinks nicely
|
||||
|
||||
// Color/pixel related functions
|
||||
RLAPI Color Fade(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f
|
||||
|
|
@ -1412,8 +1412,6 @@ RLAPI void DrawCube(Vector3 position, float width, float height, float length, C
|
|||
RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version)
|
||||
RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires
|
||||
RLAPI void DrawCubeWiresV(Vector3 position, Vector3 size, Color color); // Draw cube wires (Vector version)
|
||||
RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured
|
||||
RLAPI void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color); // Draw cube with a region of a texture
|
||||
RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere
|
||||
RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters
|
||||
RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires
|
||||
|
|
@ -1421,6 +1419,8 @@ RLAPI void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, f
|
|||
RLAPI void DrawCylinderEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color); // Draw a cylinder with base at startPos and top at endPos
|
||||
RLAPI void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires
|
||||
RLAPI void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color); // Draw a cylinder wires with base at startPos and top at endPos
|
||||
RLAPI void DrawCapsule(Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color); // Draw a capsule with the center of its sphere caps at startPos and endPos
|
||||
RLAPI void DrawCapsuleWires(Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color); // Draw capsule wireframe with the center of its sphere caps at startPos and endPos
|
||||
RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ
|
||||
RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line
|
||||
RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0))
|
||||
|
|
@ -1437,11 +1437,11 @@ RLAPI void UnloadModelKeepMeshes(Model model);
|
|||
RLAPI BoundingBox GetModelBoundingBox(Model model); // Compute model bounding box limits (considers all meshes)
|
||||
|
||||
// Model drawing functions
|
||||
RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
|
||||
RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
|
||||
RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters
|
||||
RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set)
|
||||
RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set)
|
||||
RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
|
||||
RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires)
|
||||
RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires)
|
||||
RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float size, Color tint); // Draw a billboard texture
|
||||
RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint); // Draw a billboard texture defined by source
|
||||
RLAPI void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint); // Draw a billboard texture defined by source and rotation
|
||||
|
|
|
|||
221
src/rcore.c
221
src/rcore.c
|
|
@ -246,7 +246,7 @@
|
|||
//#define GLFW_EXPOSE_NATIVE_COCOA // WARNING: Fails due to type redefinition
|
||||
#include "GLFW/glfw3native.h" // Required for: glfwGetCocoaWindow()
|
||||
#endif
|
||||
|
||||
|
||||
// TODO: HACK: Added flag if not provided by GLFW when using external library
|
||||
// Latest GLFW release (GLFW 3.3.8) does not implement this flag, it was added for 3.4.0-dev
|
||||
#if !defined(GLFW_MOUSE_PASSTHROUGH)
|
||||
|
|
@ -1732,49 +1732,58 @@ int GetMonitorCount(void)
|
|||
// Get number of monitors
|
||||
int GetCurrentMonitor(void)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
int monitorCount;
|
||||
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
|
||||
GLFWmonitor* monitor = NULL;
|
||||
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
|
||||
GLFWmonitor *monitor = NULL;
|
||||
|
||||
if (monitorCount == 1) // easy out
|
||||
return 0;
|
||||
|
||||
if (IsWindowFullscreen())
|
||||
if (monitorCount > 1)
|
||||
{
|
||||
monitor = glfwGetWindowMonitor(CORE.Window.handle);
|
||||
for (int i = 0; i < monitorCount; i++)
|
||||
if (IsWindowFullscreen())
|
||||
{
|
||||
if (monitors[i] == monitor)
|
||||
return i;
|
||||
// Get the handle of the monitor that the specified window is in full screen on
|
||||
monitor = glfwGetWindowMonitor(CORE.Window.handle);
|
||||
|
||||
for (int i = 0; i < monitorCount; i++)
|
||||
{
|
||||
if (monitors[i] == monitor)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
glfwGetWindowPos(CORE.Window.handle, &x, &y);
|
||||
|
||||
for (int i = 0; i < monitorCount; i++)
|
||||
else
|
||||
{
|
||||
int mx = 0;
|
||||
int my = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
glfwGetWindowPos(CORE.Window.handle, &x, &y);
|
||||
|
||||
monitor = monitors[i];
|
||||
glfwGetMonitorWorkarea(monitor, &mx, &my, &width, &height);
|
||||
if (x >= mx && x <= (mx + width) && y >= my && y <= (my + height))
|
||||
return i;
|
||||
for (int i = 0; i < monitorCount; i++)
|
||||
{
|
||||
int mx = 0;
|
||||
int my = 0;
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
monitor = monitors[i];
|
||||
glfwGetMonitorWorkarea(monitor, &mx, &my, &width, &height);
|
||||
|
||||
if (x >= mx && x <= (mx + width) && y >= my && y <= (my + height))
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
// Get selected monitor position
|
||||
|
|
@ -1782,7 +1791,7 @@ Vector2 GetMonitorPosition(int monitor)
|
|||
{
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
int monitorCount;
|
||||
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
|
||||
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
|
||||
|
||||
if ((monitor >= 0) && (monitor < monitorCount))
|
||||
{
|
||||
|
|
@ -1852,7 +1861,7 @@ int GetMonitorPhysicalWidth(int monitor)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Get primary monitor physical height in millimetres
|
||||
// Get selected monitor physical height in millimetres
|
||||
int GetMonitorPhysicalHeight(int monitor)
|
||||
{
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
|
|
@ -1870,6 +1879,7 @@ int GetMonitorPhysicalHeight(int monitor)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Get selected monitor refresh rate
|
||||
int GetMonitorRefreshRate(int monitor)
|
||||
{
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
|
|
@ -1903,7 +1913,7 @@ Vector2 GetWindowPosition(void)
|
|||
return (Vector2){ (float)x, (float)y };
|
||||
}
|
||||
|
||||
// Get window scale DPI factor
|
||||
// Get window scale DPI factor for current monitor
|
||||
Vector2 GetWindowScaleDPI(void)
|
||||
{
|
||||
Vector2 scale = { 1.0f, 1.0f };
|
||||
|
|
@ -1937,7 +1947,7 @@ Vector2 GetWindowScaleDPI(void)
|
|||
return scale;
|
||||
}
|
||||
|
||||
// Get the human-readable, UTF-8 encoded name of the primary monitor
|
||||
// Get the human-readable, UTF-8 encoded name of the selected monitor
|
||||
const char *GetMonitorName(int monitor)
|
||||
{
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
|
|
@ -1964,18 +1974,6 @@ void SetClipboardText(const char *text)
|
|||
#endif
|
||||
}
|
||||
|
||||
// Enable waiting for events on EndDrawing(), no automatic event polling
|
||||
void EnableEventWaiting(void)
|
||||
{
|
||||
CORE.Window.eventWaiting = true;
|
||||
}
|
||||
|
||||
// Disable waiting for events on EndDrawing(), automatic events polling
|
||||
void DisableEventWaiting(void)
|
||||
{
|
||||
CORE.Window.eventWaiting = false;
|
||||
}
|
||||
|
||||
// Get clipboard text content
|
||||
// NOTE: returned string is allocated and freed by GLFW
|
||||
const char *GetClipboardText(void)
|
||||
|
|
@ -1989,6 +1987,18 @@ const char *GetClipboardText(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Enable waiting for events on EndDrawing(), no automatic event polling
|
||||
void EnableEventWaiting(void)
|
||||
{
|
||||
CORE.Window.eventWaiting = true;
|
||||
}
|
||||
|
||||
// Disable waiting for events on EndDrawing(), automatic events polling
|
||||
void DisableEventWaiting(void)
|
||||
{
|
||||
CORE.Window.eventWaiting = false;
|
||||
}
|
||||
|
||||
// Show mouse cursor
|
||||
void ShowCursor(void)
|
||||
{
|
||||
|
|
@ -2843,6 +2853,13 @@ int GetRandomValue(int min, int max)
|
|||
max = min;
|
||||
min = tmp;
|
||||
}
|
||||
|
||||
// WARNING: Ranges higher than RAND_MAX will return invalid results. More specifically, if (max - min) > INT_MAX there will
|
||||
// be an overflow, and otherwise if (max - min) > RAND_MAX the random value will incorrectly never exceed a certain threshold.
|
||||
if ((unsigned int)(max - min) > (unsigned int)RAND_MAX)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "Invalid GetRandomValue arguments. Range should not be higher than %i.", RAND_MAX);
|
||||
}
|
||||
|
||||
return (rand()%(abs(max - min) + 1) + min);
|
||||
}
|
||||
|
|
@ -3208,14 +3225,12 @@ FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool
|
|||
}
|
||||
|
||||
// Unload directory filepaths
|
||||
// WARNING: files.count is not reseted to 0 after unloading
|
||||
void UnloadDirectoryFiles(FilePathList files)
|
||||
{
|
||||
if (files.capacity > 0)
|
||||
{
|
||||
for (unsigned int i = 0; i < files.capacity; i++) RL_FREE(files.paths[i]);
|
||||
for (unsigned int i = 0; i < files.capacity; i++) RL_FREE(files.paths[i]);
|
||||
|
||||
RL_FREE(files.paths);
|
||||
}
|
||||
RL_FREE(files.paths);
|
||||
}
|
||||
|
||||
// Change working directory, returns true on success
|
||||
|
|
@ -3315,6 +3330,9 @@ unsigned char *DecompressData(const unsigned char *compData, int compDataSize, i
|
|||
// Decompress data from a valid DEFLATE stream
|
||||
data = RL_CALLOC(MAX_DECOMPRESSION_SIZE*1024*1024, 1);
|
||||
int length = sinflate(data, MAX_DECOMPRESSION_SIZE*1024*1024, compData, compDataSize);
|
||||
|
||||
// WARNING: RL_REALLOC can make (and leave) data copies in memory, be careful with sensitive compressed data!
|
||||
// TODO: Use a different approach, create another buffer, copy data manually to it and wipe original buffer memory
|
||||
unsigned char *temp = RL_REALLOC(data, length);
|
||||
|
||||
if (temp != NULL) data = temp;
|
||||
|
|
@ -3438,7 +3456,7 @@ void OpenURL(const char *url)
|
|||
else
|
||||
{
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
char *cmd = (char *)RL_CALLOC(strlen(url) + 10, sizeof(char));
|
||||
char *cmd = (char *)RL_CALLOC(strlen(url) + 32, sizeof(char));
|
||||
#if defined(_WIN32)
|
||||
sprintf(cmd, "explorer \"%s\"", url);
|
||||
#endif
|
||||
|
|
@ -3817,7 +3835,7 @@ float GetMouseWheelMove(void)
|
|||
Vector2 GetMouseWheelMoveV(void)
|
||||
{
|
||||
Vector2 result = { 0 };
|
||||
|
||||
|
||||
result = CORE.Input.Mouse.currentWheelMove;
|
||||
|
||||
return result;
|
||||
|
|
@ -3934,30 +3952,6 @@ static bool InitGraphicsDevice(int width, int height)
|
|||
return false;
|
||||
}
|
||||
|
||||
// NOTE: Getting video modes is not implemented in emscripten GLFW3 version
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
// Find monitor resolution
|
||||
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
|
||||
if (!monitor)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GLFW: Failed to get primary monitor");
|
||||
return false;
|
||||
}
|
||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||
|
||||
CORE.Window.display.width = mode->width;
|
||||
CORE.Window.display.height = mode->height;
|
||||
|
||||
// Set screen width/height to the display width/height if they are 0
|
||||
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
||||
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
||||
#endif // PLATFORM_DESKTOP
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
CORE.Window.display.width = CORE.Window.screen.width;
|
||||
CORE.Window.display.height = CORE.Window.screen.height;
|
||||
#endif // PLATFORM_WEB
|
||||
|
||||
glfwDefaultWindowHints(); // Set default windows hints
|
||||
//glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
|
||||
//glfwWindowHint(GLFW_GREEN_BITS, 8); // Framebuffer green color component bits
|
||||
|
|
@ -4074,6 +4068,31 @@ static bool InitGraphicsDevice(int width, int height)
|
|||
if (MAX_GAMEPADS > 0) glfwSetJoystickCallback(NULL);
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
// Find monitor resolution
|
||||
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
|
||||
if (!monitor)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GLFW: Failed to get primary monitor");
|
||||
return false;
|
||||
}
|
||||
|
||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||
|
||||
CORE.Window.display.width = mode->width;
|
||||
CORE.Window.display.height = mode->height;
|
||||
|
||||
// Set screen width/height to the display width/height if they are 0
|
||||
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
||||
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
||||
#endif // PLATFORM_DESKTOP
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
// NOTE: Getting video modes is not implemented in emscripten GLFW3 version
|
||||
CORE.Window.display.width = CORE.Window.screen.width;
|
||||
CORE.Window.display.height = CORE.Window.screen.height;
|
||||
#endif // PLATFORM_WEB
|
||||
|
||||
if (CORE.Window.fullscreen)
|
||||
{
|
||||
// remember center for switchinging from fullscreen to window
|
||||
|
|
@ -4133,16 +4152,6 @@ static bool InitGraphicsDevice(int width, int height)
|
|||
|
||||
if (CORE.Window.handle)
|
||||
{
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
// Center window on screen
|
||||
int windowPosX = CORE.Window.display.width/2 - CORE.Window.screen.width/2;
|
||||
int windowPosY = CORE.Window.display.height/2 - CORE.Window.screen.height/2;
|
||||
|
||||
if (windowPosX < 0) windowPosX = 0;
|
||||
if (windowPosY < 0) windowPosY = 0;
|
||||
|
||||
glfwSetWindowPos(CORE.Window.handle, windowPosX, windowPosY);
|
||||
#endif
|
||||
CORE.Window.render.width = CORE.Window.screen.width;
|
||||
CORE.Window.render.height = CORE.Window.screen.height;
|
||||
}
|
||||
|
|
@ -4163,6 +4172,7 @@ static bool InitGraphicsDevice(int width, int height)
|
|||
glfwSetWindowIconifyCallback(CORE.Window.handle, WindowIconifyCallback);
|
||||
glfwSetWindowFocusCallback(CORE.Window.handle, WindowFocusCallback);
|
||||
glfwSetDropCallback(CORE.Window.handle, WindowDropCallback);
|
||||
|
||||
// Set input callback events
|
||||
glfwSetKeyCallback(CORE.Window.handle, KeyCallback);
|
||||
glfwSetCharCallback(CORE.Window.handle, CharCallback);
|
||||
|
|
@ -4171,11 +4181,11 @@ static bool InitGraphicsDevice(int width, int height)
|
|||
glfwSetScrollCallback(CORE.Window.handle, MouseScrollCallback);
|
||||
glfwSetCursorEnterCallback(CORE.Window.handle, CursorEnterCallback);
|
||||
|
||||
glfwSetInputMode(CORE.Window.handle, GLFW_LOCK_KEY_MODS, GLFW_TRUE); // Enable lock keys modifiers (CAPS, NUM)
|
||||
|
||||
glfwMakeContextCurrent(CORE.Window.handle);
|
||||
|
||||
#if !defined(PLATFORM_WEB)
|
||||
glfwSetInputMode(CORE.Window.handle, GLFW_LOCK_KEY_MODS, GLFW_TRUE); // Enable lock keys modifiers (CAPS, NUM)
|
||||
|
||||
glfwSwapInterval(0); // No V-Sync by default
|
||||
#endif
|
||||
|
||||
|
|
@ -4295,6 +4305,7 @@ static bool InitGraphicsDevice(int width, int height)
|
|||
drmModeFreeConnector(con);
|
||||
}
|
||||
}
|
||||
|
||||
if (!CORE.Window.connector)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: No suitable DRM connector found");
|
||||
|
|
@ -4340,18 +4351,20 @@ static bool InitGraphicsDevice(int width, int height)
|
|||
|
||||
const bool allowInterlaced = CORE.Window.flags & FLAG_INTERLACED_HINT;
|
||||
const int fps = (CORE.Time.target > 0) ? (1.0/CORE.Time.target) : 60;
|
||||
// try to find an exact matching mode
|
||||
|
||||
// Try to find an exact matching mode
|
||||
CORE.Window.modeIndex = FindExactConnectorMode(CORE.Window.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, allowInterlaced);
|
||||
// if nothing found, try to find a nearly matching mode
|
||||
if (CORE.Window.modeIndex < 0)
|
||||
CORE.Window.modeIndex = FindNearestConnectorMode(CORE.Window.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, allowInterlaced);
|
||||
// if nothing found, try to find an exactly matching mode including interlaced
|
||||
if (CORE.Window.modeIndex < 0)
|
||||
CORE.Window.modeIndex = FindExactConnectorMode(CORE.Window.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, true);
|
||||
// if nothing found, try to find a nearly matching mode including interlaced
|
||||
if (CORE.Window.modeIndex < 0)
|
||||
CORE.Window.modeIndex = FindNearestConnectorMode(CORE.Window.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, true);
|
||||
// if nothing found, there is no suitable mode
|
||||
|
||||
// If nothing found, try to find a nearly matching mode
|
||||
if (CORE.Window.modeIndex < 0) CORE.Window.modeIndex = FindNearestConnectorMode(CORE.Window.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, allowInterlaced);
|
||||
|
||||
// If nothing found, try to find an exactly matching mode including interlaced
|
||||
if (CORE.Window.modeIndex < 0) CORE.Window.modeIndex = FindExactConnectorMode(CORE.Window.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, true);
|
||||
|
||||
// If nothing found, try to find a nearly matching mode including interlaced
|
||||
if (CORE.Window.modeIndex < 0) CORE.Window.modeIndex = FindNearestConnectorMode(CORE.Window.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, true);
|
||||
|
||||
// If nothing found, there is no suitable mode
|
||||
if (CORE.Window.modeIndex < 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Failed to find a suitable DRM connector mode");
|
||||
|
|
@ -5514,15 +5527,17 @@ static void WindowFocusCallback(GLFWwindow *window, int focused)
|
|||
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key < 0) return; // Security check, macOS fn key generates -1
|
||||
|
||||
|
||||
// WARNING: GLFW could return GLFW_REPEAT, we need to consider it as 1
|
||||
// to work properly with our implementation (IsKeyDown/IsKeyUp checks)
|
||||
if (action == GLFW_RELEASE) CORE.Input.Keyboard.currentKeyState[key] = 0;
|
||||
else CORE.Input.Keyboard.currentKeyState[key] = 1;
|
||||
|
||||
#if !defined(PLATFORM_WEB)
|
||||
// WARNING: Check if CAPS/NUM key modifiers are enabled and force down state for those keys
|
||||
if (((key == KEY_CAPS_LOCK) && ((mods & GLFW_MOD_CAPS_LOCK) > 0)) ||
|
||||
((key == KEY_NUM_LOCK) && ((mods & GLFW_MOD_NUM_LOCK) > 0))) CORE.Input.Keyboard.currentKeyState[key] = 1;
|
||||
#endif
|
||||
|
||||
// Check if there is space available in the key queue
|
||||
if ((CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) && (action == GLFW_PRESS))
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
|
|||
|
||||
#if defined(GESTURES_IMPLEMENTATION)
|
||||
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
#if defined(_WIN32)
|
||||
#if defined(__cplusplus)
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
|
|
@ -175,6 +176,7 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
|
|||
#include <mach/clock.h> // Required for: clock_get_time()
|
||||
#include <mach/mach.h> // Required for: mach_timespec_t
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
|
|
@ -526,6 +528,9 @@ static double rgGetCurrentTime(void)
|
|||
{
|
||||
double time = 0;
|
||||
|
||||
#if !defined(GESTURES_STANDALONE)
|
||||
time = GetTime();
|
||||
#else
|
||||
#if defined(_WIN32)
|
||||
unsigned long long int clockFrequency, currentTime;
|
||||
|
||||
|
|
@ -558,6 +563,7 @@ static double rgGetCurrentTime(void)
|
|||
unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds
|
||||
|
||||
time = ((double)nowTime/1000000.0); // Time in miliseconds
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return time;
|
||||
|
|
|
|||
89
src/rlgl.h
89
src/rlgl.h
|
|
@ -413,7 +413,8 @@ typedef enum {
|
|||
RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
|
||||
RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
|
||||
RL_BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha
|
||||
RL_BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendFactors())
|
||||
RL_BLEND_CUSTOM, // Blend textures using custom src/dst factors (use rlSetBlendFactors())
|
||||
RL_BLEND_CUSTOM_SEPARATE // Blend textures using custom src/dst factors (use rlSetBlendFactorsSeparate())
|
||||
} rlBlendMode;
|
||||
|
||||
// Shader location point type
|
||||
|
|
@ -449,7 +450,7 @@ typedef enum {
|
|||
#define RL_SHADER_LOC_MAP_DIFFUSE RL_SHADER_LOC_MAP_ALBEDO
|
||||
#define RL_SHADER_LOC_MAP_SPECULAR RL_SHADER_LOC_MAP_METALNESS
|
||||
|
||||
// Shader uniform data type
|
||||
// Shader uniform data type
|
||||
typedef enum {
|
||||
RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float
|
||||
RL_SHADER_UNIFORM_VEC2, // Shader uniform type: vec2 (2 float)
|
||||
|
|
@ -497,6 +498,12 @@ typedef enum {
|
|||
RL_ATTACHMENT_RENDERBUFFER = 200, // Framebuffer texture attachment type: renderbuffer
|
||||
} rlFramebufferAttachTextureType;
|
||||
|
||||
// Face culling mode
|
||||
typedef enum {
|
||||
RL_CULL_FACE_FRONT = 0,
|
||||
RL_CULL_FACE_BACK
|
||||
} rlCullMode;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Matrix operations
|
||||
//------------------------------------------------------------------------------------
|
||||
|
|
@ -512,7 +519,7 @@ RLAPI void rlLoadIdentity(void); // Reset current matrix to
|
|||
RLAPI void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
|
||||
RLAPI void rlRotatef(float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix
|
||||
RLAPI void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
|
||||
RLAPI void rlMultMatrixf(float *matf); // Multiply the current matrix by another matrix
|
||||
RLAPI void rlMultMatrixf(const float *matf); // Multiply the current matrix by another matrix
|
||||
RLAPI void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar);
|
||||
RLAPI void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar);
|
||||
RLAPI void rlViewport(int x, int y, int width, int height); // Set the viewport area
|
||||
|
|
@ -577,6 +584,7 @@ RLAPI void rlEnableDepthMask(void); // Enable depth write
|
|||
RLAPI void rlDisableDepthMask(void); // Disable depth write
|
||||
RLAPI void rlEnableBackfaceCulling(void); // Enable backface culling
|
||||
RLAPI void rlDisableBackfaceCulling(void); // Disable backface culling
|
||||
RLAPI void rlSetCullFace(int mode); // Set face culling mode
|
||||
RLAPI void rlEnableScissorTest(void); // Enable scissor test
|
||||
RLAPI void rlDisableScissorTest(void); // Disable scissor test
|
||||
RLAPI void rlScissor(int x, int y, int width, int height); // Scissor test
|
||||
|
|
@ -595,6 +603,7 @@ RLAPI void rlClearScreenBuffers(void); // Clear used screen buf
|
|||
RLAPI void rlCheckErrors(void); // Check and log OpenGL error codes
|
||||
RLAPI void rlSetBlendMode(int mode); // Set blending mode
|
||||
RLAPI void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // Set blending mode factor and equation (using OpenGL factors)
|
||||
RLAPI void rlSetBlendFactorsSeparate(int glSrcRGB, int glDstRGB, int glSrcAlpha, int glDstAlpha, int glEqRGB, int glEqAlpha); // Set blending mode factors and equations separately (using OpenGL factors)
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - rlgl functionality
|
||||
|
|
@ -687,7 +696,7 @@ RLAPI void rlCopyShaderBuffer(unsigned int destId, unsigned int srcId, unsigned
|
|||
RLAPI unsigned int rlGetShaderBufferSize(unsigned int id); // Get SSBO buffer size
|
||||
|
||||
// Buffer management
|
||||
RLAPI void rlBindImageTexture(unsigned int id, unsigned int index, unsigned int format, int readonly); // Bind image texture
|
||||
RLAPI void rlBindImageTexture(unsigned int id, unsigned int index, int format, bool readonly); // Bind image texture
|
||||
|
||||
// Matrix state management
|
||||
RLAPI Matrix rlGetMatrixModelview(void); // Get internal modelview matrix
|
||||
|
|
@ -926,10 +935,18 @@ typedef struct rlglData {
|
|||
Matrix projectionStereo[2]; // VR stereo rendering eyes projection matrices
|
||||
Matrix viewOffsetStereo[2]; // VR stereo rendering eyes view offset matrices
|
||||
|
||||
// Blending variables
|
||||
int currentBlendMode; // Blending mode active
|
||||
int glBlendSrcFactor; // Blending source factor
|
||||
int glBlendDstFactor; // Blending destination factor
|
||||
int glBlendEquation; // Blending equation
|
||||
int glBlendSrcFactorRGB; // Blending source RGB factor
|
||||
int glBlendDestFactorRGB; // Blending destination RGB factor
|
||||
int glBlendSrcFactorAlpha; // Blending source alpha factor
|
||||
int glBlendDestFactorAlpha; // Blending destination alpha factor
|
||||
int glBlendEquationRGB; // Blending equation for RGB
|
||||
int glBlendEquationAlpha; // Blending equation for alpha
|
||||
bool glCustomBlendModeModified; // Custom blending factor and equation modification status
|
||||
|
||||
int framebufferWidth; // Current framebuffer width
|
||||
int framebufferHeight; // Current framebuffer height
|
||||
|
|
@ -1031,7 +1048,7 @@ void rlLoadIdentity(void) { glLoadIdentity(); }
|
|||
void rlTranslatef(float x, float y, float z) { glTranslatef(x, y, z); }
|
||||
void rlRotatef(float angle, float x, float y, float z) { glRotatef(angle, x, y, z); }
|
||||
void rlScalef(float x, float y, float z) { glScalef(x, y, z); }
|
||||
void rlMultMatrixf(float *matf) { glMultMatrixf(matf); }
|
||||
void rlMultMatrixf(const float *matf) { glMultMatrixf(matf); }
|
||||
#endif
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// Choose the current matrix to be transformed
|
||||
|
|
@ -1156,7 +1173,7 @@ void rlScalef(float x, float y, float z)
|
|||
}
|
||||
|
||||
// Multiply the current matrix by another matrix
|
||||
void rlMultMatrixf(float *matf)
|
||||
void rlMultMatrixf(const float *matf)
|
||||
{
|
||||
// Matrix creation from array
|
||||
Matrix mat = { matf[0], matf[4], matf[8], matf[12],
|
||||
|
|
@ -1661,6 +1678,17 @@ void rlEnableBackfaceCulling(void) { glEnable(GL_CULL_FACE); }
|
|||
// Disable backface culling
|
||||
void rlDisableBackfaceCulling(void) { glDisable(GL_CULL_FACE); }
|
||||
|
||||
// Set face culling mode
|
||||
void rlSetCullFace(int mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case RL_CULL_FACE_BACK: glCullFace(GL_BACK); break;
|
||||
case RL_CULL_FACE_FRONT: glCullFace(GL_FRONT); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable scissor test
|
||||
void rlEnableScissorTest(void) { glEnable(GL_SCISSOR_TEST); }
|
||||
|
||||
|
|
@ -1788,7 +1816,7 @@ void rlCheckErrors()
|
|||
void rlSetBlendMode(int mode)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if (RLGL.State.currentBlendMode != mode)
|
||||
if ((RLGL.State.currentBlendMode != mode) || ((mode == RL_BLEND_CUSTOM || mode == RL_BLEND_CUSTOM_SEPARATE) && RLGL.State.glCustomBlendModeModified))
|
||||
{
|
||||
rlDrawRenderBatch(RLGL.currentBatch);
|
||||
|
||||
|
|
@ -1804,11 +1832,20 @@ void rlSetBlendMode(int mode)
|
|||
{
|
||||
// NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()
|
||||
glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation);
|
||||
|
||||
} break;
|
||||
case RL_BLEND_CUSTOM_SEPARATE:
|
||||
{
|
||||
// NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactorsSeparate()
|
||||
glBlendFuncSeparate(RLGL.State.glBlendSrcFactorRGB, RLGL.State.glBlendDestFactorRGB, RLGL.State.glBlendSrcFactorAlpha, RLGL.State.glBlendDestFactorAlpha);
|
||||
glBlendEquationSeparate(RLGL.State.glBlendEquationRGB, RLGL.State.glBlendEquationAlpha);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
RLGL.State.currentBlendMode = mode;
|
||||
RLGL.State.glCustomBlendModeModified = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1817,9 +1854,39 @@ void rlSetBlendMode(int mode)
|
|||
void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
RLGL.State.glBlendSrcFactor = glSrcFactor;
|
||||
RLGL.State.glBlendDstFactor = glDstFactor;
|
||||
RLGL.State.glBlendEquation = glEquation;
|
||||
if ((RLGL.State.glBlendSrcFactor != glSrcFactor) ||
|
||||
(RLGL.State.glBlendDstFactor != glDstFactor) ||
|
||||
(RLGL.State.glBlendEquation != glEquation))
|
||||
{
|
||||
RLGL.State.glBlendSrcFactor = glSrcFactor;
|
||||
RLGL.State.glBlendDstFactor = glDstFactor;
|
||||
RLGL.State.glBlendEquation = glEquation;
|
||||
|
||||
RLGL.State.glCustomBlendModeModified = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set blending mode factor and equation separately for RGB and alpha
|
||||
void rlSetBlendFactorsSeparate(int glSrcRGB, int glDstRGB, int glSrcAlpha, int glDstAlpha, int glEqRGB, int glEqAlpha)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if ((RLGL.State.glBlendSrcFactorRGB != glSrcRGB) ||
|
||||
(RLGL.State.glBlendDestFactorRGB != glDstRGB) ||
|
||||
(RLGL.State.glBlendSrcFactorAlpha != glSrcAlpha) ||
|
||||
(RLGL.State.glBlendDestFactorAlpha != glDstAlpha) ||
|
||||
(RLGL.State.glBlendEquationRGB != glEqRGB) ||
|
||||
(RLGL.State.glBlendEquationAlpha != glEqAlpha))
|
||||
{
|
||||
RLGL.State.glBlendSrcFactorRGB = glSrcRGB;
|
||||
RLGL.State.glBlendDestFactorRGB = glDstRGB;
|
||||
RLGL.State.glBlendSrcFactorAlpha = glSrcAlpha;
|
||||
RLGL.State.glBlendDestFactorAlpha = glDstAlpha;
|
||||
RLGL.State.glBlendEquationRGB = glEqRGB;
|
||||
RLGL.State.glBlendEquationAlpha = glEqAlpha;
|
||||
|
||||
RLGL.State.glCustomBlendModeModified = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -3988,7 +4055,7 @@ void rlCopyShaderBuffer(unsigned int destId, unsigned int srcId, unsigned int de
|
|||
}
|
||||
|
||||
// Bind image texture
|
||||
void rlBindImageTexture(unsigned int id, unsigned int index, unsigned int format, int readonly)
|
||||
void rlBindImageTexture(unsigned int id, unsigned int index, int format, bool readonly)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_43)
|
||||
unsigned int glInternalFormat = 0, glFormat = 0, glType = 0;
|
||||
|
|
|
|||
454
src/rmodels.c
454
src/rmodels.c
|
|
@ -397,151 +397,6 @@ void DrawCubeWiresV(Vector3 position, Vector3 size, Color color)
|
|||
DrawCubeWires(position, size.x, size.y, size.z, color);
|
||||
}
|
||||
|
||||
// Draw cube
|
||||
// NOTE: Cube position is the center position
|
||||
void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color)
|
||||
{
|
||||
float x = position.x;
|
||||
float y = position.y;
|
||||
float z = position.z;
|
||||
|
||||
rlSetTexture(texture.id);
|
||||
|
||||
//rlPushMatrix();
|
||||
// NOTE: Transformation is applied in inverse order (scale -> rotate -> translate)
|
||||
//rlTranslatef(2.0f, 0.0f, 0.0f);
|
||||
//rlRotatef(45, 0, 1, 0);
|
||||
//rlScalef(2.0f, 2.0f, 2.0f);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
// Front Face
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad
|
||||
// Back Face
|
||||
rlNormal3f(0.0f, 0.0f, - 1.0f); // Normal Pointing Away From Viewer
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad
|
||||
// Top Face
|
||||
rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad
|
||||
// Bottom Face
|
||||
rlNormal3f(0.0f, - 1.0f, 0.0f); // Normal Pointing Down
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad
|
||||
// Right face
|
||||
rlNormal3f(1.0f, 0.0f, 0.0f); // Normal Pointing Right
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad
|
||||
// Left Face
|
||||
rlNormal3f( - 1.0f, 0.0f, 0.0f); // Normal Pointing Left
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad
|
||||
rlEnd();
|
||||
//rlPopMatrix();
|
||||
|
||||
rlSetTexture(0);
|
||||
}
|
||||
|
||||
// Draw cube with texture piece applied to all faces
|
||||
void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color)
|
||||
{
|
||||
float x = position.x;
|
||||
float y = position.y;
|
||||
float z = position.z;
|
||||
float texWidth = (float)texture.width;
|
||||
float texHeight = (float)texture.height;
|
||||
|
||||
rlSetTexture(texture.id);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
// Front face
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z + length/2);
|
||||
|
||||
// Back face
|
||||
rlNormal3f(0.0f, 0.0f, - 1.0f);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z - length/2);
|
||||
|
||||
// Top face
|
||||
rlNormal3f(0.0f, 1.0f, 0.0f);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z - length/2);
|
||||
|
||||
// Bottom face
|
||||
rlNormal3f(0.0f, - 1.0f, 0.0f);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z + length/2);
|
||||
|
||||
// Right face
|
||||
rlNormal3f(1.0f, 0.0f, 0.0f);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z - length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x + width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x + width/2, y - height/2, z + length/2);
|
||||
|
||||
// Left face
|
||||
rlNormal3f( - 1.0f, 0.0f, 0.0f);
|
||||
rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z - length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
|
||||
rlVertex3f(x - width/2, y - height/2, z + length/2);
|
||||
rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z + length/2);
|
||||
rlTexCoord2f(source.x/texWidth, source.y/texHeight);
|
||||
rlVertex3f(x - width/2, y + height/2, z - length/2);
|
||||
|
||||
rlEnd();
|
||||
|
||||
rlSetTexture(0);
|
||||
}
|
||||
|
||||
// Draw sphere
|
||||
void DrawSphere(Vector3 centerPos, float radius, Color color)
|
||||
{
|
||||
|
|
@ -817,6 +672,284 @@ void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, fl
|
|||
rlEnd();
|
||||
}
|
||||
|
||||
// Draw a capsule with the center of its sphere caps at startPos and endPos
|
||||
void DrawCapsule(Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color)
|
||||
{
|
||||
if (slices < 3) slices = 3;
|
||||
|
||||
Vector3 direction = { endPos.x - startPos.x, endPos.y - startPos.y, endPos.z - startPos.z };
|
||||
|
||||
// draw a sphere if start and end points are the same
|
||||
bool sphereCase = (direction.x == 0) && (direction.y == 0) && (direction.z == 0);
|
||||
if (sphereCase) direction = (Vector3){0.0f, 1.0f, 0.0f};
|
||||
|
||||
// Construct a basis of the base and the caps:
|
||||
Vector3 b0 = Vector3Normalize(direction);
|
||||
Vector3 b1 = Vector3Normalize(Vector3Perpendicular(direction));
|
||||
Vector3 b2 = Vector3Normalize(Vector3CrossProduct(b1, direction));
|
||||
Vector3 capCenter = endPos;
|
||||
|
||||
float baseSliceAngle = (2.0f*PI)/slices;
|
||||
float baseRingAngle = PI * 0.5 / rings;
|
||||
|
||||
rlBegin(RL_TRIANGLES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
// render both caps
|
||||
for (int c = 0; c < 2; c++)
|
||||
{
|
||||
for (int i = 0; i < rings; i++)
|
||||
{
|
||||
for (int j = 0; j < slices; j++)
|
||||
{
|
||||
|
||||
// we build up the rings from capCenter in the direction of the 'direction' vector we computed earlier
|
||||
|
||||
// as we iterate through the rings they must be placed higher above the center, the height we need is sin(angle(i))
|
||||
// as we iterate through the rings they must get smaller by the cos(angle(i))
|
||||
|
||||
// compute the four vertices
|
||||
float ringSin1 = sinf(baseSliceAngle*(j + 0))*cosf(baseRingAngle * ( i + 0 ));
|
||||
float ringCos1 = cosf(baseSliceAngle*(j + 0))*cosf(baseRingAngle * ( i + 0 ));
|
||||
Vector3 w1 = (Vector3){
|
||||
capCenter.x + (sinf(baseRingAngle * ( i + 0 ))*b0.x + ringSin1*b1.x + ringCos1*b2.x) * radius,
|
||||
capCenter.y + (sinf(baseRingAngle * ( i + 0 ))*b0.y + ringSin1*b1.y + ringCos1*b2.y) * radius,
|
||||
capCenter.z + (sinf(baseRingAngle * ( i + 0 ))*b0.z + ringSin1*b1.z + ringCos1*b2.z) * radius
|
||||
};
|
||||
float ringSin2 = sinf(baseSliceAngle*(j + 1))*cosf(baseRingAngle * ( i + 0 ));
|
||||
float ringCos2 = cosf(baseSliceAngle*(j + 1))*cosf(baseRingAngle * ( i + 0 ));
|
||||
Vector3 w2 = (Vector3){
|
||||
capCenter.x + (sinf(baseRingAngle * ( i + 0 ))*b0.x + ringSin2*b1.x + ringCos2*b2.x) * radius,
|
||||
capCenter.y + (sinf(baseRingAngle * ( i + 0 ))*b0.y + ringSin2*b1.y + ringCos2*b2.y) * radius,
|
||||
capCenter.z + (sinf(baseRingAngle * ( i + 0 ))*b0.z + ringSin2*b1.z + ringCos2*b2.z) * radius
|
||||
};
|
||||
|
||||
float ringSin3 = sinf(baseSliceAngle*(j + 0))*cosf(baseRingAngle * ( i + 1 ));
|
||||
float ringCos3 = cosf(baseSliceAngle*(j + 0))*cosf(baseRingAngle * ( i + 1 ));
|
||||
Vector3 w3 = (Vector3){
|
||||
capCenter.x + (sinf(baseRingAngle * ( i + 1 ))*b0.x + ringSin3*b1.x + ringCos3*b2.x) * radius,
|
||||
capCenter.y + (sinf(baseRingAngle * ( i + 1 ))*b0.y + ringSin3*b1.y + ringCos3*b2.y) * radius,
|
||||
capCenter.z + (sinf(baseRingAngle * ( i + 1 ))*b0.z + ringSin3*b1.z + ringCos3*b2.z) * radius
|
||||
};
|
||||
float ringSin4 = sinf(baseSliceAngle*(j + 1))*cosf(baseRingAngle * ( i + 1 ));
|
||||
float ringCos4 = cosf(baseSliceAngle*(j + 1))*cosf(baseRingAngle * ( i + 1 ));
|
||||
Vector3 w4 = (Vector3){
|
||||
capCenter.x + (sinf(baseRingAngle * ( i + 1 ))*b0.x + ringSin4*b1.x + ringCos4*b2.x) * radius,
|
||||
capCenter.y + (sinf(baseRingAngle * ( i + 1 ))*b0.y + ringSin4*b1.y + ringCos4*b2.y) * radius,
|
||||
capCenter.z + (sinf(baseRingAngle * ( i + 1 ))*b0.z + ringSin4*b1.z + ringCos4*b2.z) * radius
|
||||
};
|
||||
|
||||
// make sure cap triangle normals are facing outwards
|
||||
if(c == 0)
|
||||
{
|
||||
rlVertex3f(w1.x, w1.y, w1.z);
|
||||
rlVertex3f(w2.x, w2.y, w2.z);
|
||||
rlVertex3f(w3.x, w3.y, w3.z);
|
||||
|
||||
rlVertex3f(w2.x, w2.y, w2.z);
|
||||
rlVertex3f(w4.x, w4.y, w4.z);
|
||||
rlVertex3f(w3.x, w3.y, w3.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
rlVertex3f(w1.x, w1.y, w1.z);
|
||||
rlVertex3f(w3.x, w3.y, w3.z);
|
||||
rlVertex3f(w2.x, w2.y, w2.z);
|
||||
|
||||
rlVertex3f(w2.x, w2.y, w2.z);
|
||||
rlVertex3f(w3.x, w3.y, w3.z);
|
||||
rlVertex3f(w4.x, w4.y, w4.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
capCenter = startPos;
|
||||
b0 = Vector3Scale(b0, -1.0f);
|
||||
}
|
||||
// render middle
|
||||
if (!sphereCase)
|
||||
{
|
||||
for (int j = 0; j < slices; j++)
|
||||
{
|
||||
// compute the four vertices
|
||||
float ringSin1 = sinf(baseSliceAngle*(j + 0))*radius;
|
||||
float ringCos1 = cosf(baseSliceAngle*(j + 0))*radius;
|
||||
Vector3 w1 = {
|
||||
startPos.x + ringSin1*b1.x + ringCos1*b2.x,
|
||||
startPos.y + ringSin1*b1.y + ringCos1*b2.y,
|
||||
startPos.z + ringSin1*b1.z + ringCos1*b2.z
|
||||
};
|
||||
float ringSin2 = sinf(baseSliceAngle*(j + 1))*radius;
|
||||
float ringCos2 = cosf(baseSliceAngle*(j + 1))*radius;
|
||||
Vector3 w2 = {
|
||||
startPos.x + ringSin2*b1.x + ringCos2*b2.x,
|
||||
startPos.y + ringSin2*b1.y + ringCos2*b2.y,
|
||||
startPos.z + ringSin2*b1.z + ringCos2*b2.z
|
||||
};
|
||||
|
||||
float ringSin3 = sinf(baseSliceAngle*(j + 0))*radius;
|
||||
float ringCos3 = cosf(baseSliceAngle*(j + 0))*radius;
|
||||
Vector3 w3 = {
|
||||
endPos.x + ringSin3*b1.x + ringCos3*b2.x,
|
||||
endPos.y + ringSin3*b1.y + ringCos3*b2.y,
|
||||
endPos.z + ringSin3*b1.z + ringCos3*b2.z
|
||||
};
|
||||
float ringSin4 = sinf(baseSliceAngle*(j + 1))*radius;
|
||||
float ringCos4 = cosf(baseSliceAngle*(j + 1))*radius;
|
||||
Vector3 w4 = {
|
||||
endPos.x + ringSin4*b1.x + ringCos4*b2.x,
|
||||
endPos.y + ringSin4*b1.y + ringCos4*b2.y,
|
||||
endPos.z + ringSin4*b1.z + ringCos4*b2.z
|
||||
};
|
||||
// w2 x.-----------x startPos
|
||||
rlVertex3f(w1.x, w1.y, w1.z); // | |\'. T0 /
|
||||
rlVertex3f(w2.x, w2.y, w2.z); // T1 | \ '. /
|
||||
rlVertex3f(w3.x, w3.y, w3.z); // | |T \ '. /
|
||||
// | 2 \ T 'x w1
|
||||
rlVertex3f(w2.x, w2.y, w2.z); // | w4 x.---\-1-|---x endPos
|
||||
rlVertex3f(w4.x, w4.y, w4.z); // T2 '. \ |T3/
|
||||
rlVertex3f(w3.x, w3.y, w3.z); // | '. \ | /
|
||||
// '.\|/
|
||||
// 'x w3
|
||||
}
|
||||
}
|
||||
rlEnd();
|
||||
}
|
||||
|
||||
// Draw capsule wires with the center of its sphere caps at startPos and endPos
|
||||
void DrawCapsuleWires(Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color)
|
||||
{
|
||||
if (slices < 3) slices = 3;
|
||||
|
||||
Vector3 direction = { endPos.x - startPos.x, endPos.y - startPos.y, endPos.z - startPos.z };
|
||||
|
||||
// draw a sphere if start and end points are the same
|
||||
bool sphereCase = (direction.x == 0) && (direction.y == 0) && (direction.z == 0);
|
||||
if (sphereCase) direction = (Vector3){0.0f, 1.0f, 0.0f};
|
||||
|
||||
// Construct a basis of the base and the caps:
|
||||
Vector3 b0 = Vector3Normalize(direction);
|
||||
Vector3 b1 = Vector3Normalize(Vector3Perpendicular(direction));
|
||||
Vector3 b2 = Vector3Normalize(Vector3CrossProduct(b1, direction));
|
||||
Vector3 capCenter = endPos;
|
||||
|
||||
float baseSliceAngle = (2.0f*PI)/slices;
|
||||
float baseRingAngle = PI * 0.5 / rings;
|
||||
|
||||
rlBegin(RL_LINES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
// render both caps
|
||||
for (int c = 0; c < 2; c++)
|
||||
{
|
||||
for (int i = 0; i < rings; i++)
|
||||
{
|
||||
for (int j = 0; j < slices; j++)
|
||||
{
|
||||
|
||||
// we build up the rings from capCenter in the direction of the 'direction' vector we computed earlier
|
||||
|
||||
// as we iterate through the rings they must be placed higher above the center, the height we need is sin(angle(i))
|
||||
// as we iterate through the rings they must get smaller by the cos(angle(i))
|
||||
|
||||
// compute the four vertices
|
||||
float ringSin1 = sinf(baseSliceAngle*(j + 0))*cosf(baseRingAngle * ( i + 0 ));
|
||||
float ringCos1 = cosf(baseSliceAngle*(j + 0))*cosf(baseRingAngle * ( i + 0 ));
|
||||
Vector3 w1 = (Vector3){
|
||||
capCenter.x + (sinf(baseRingAngle * ( i + 0 ))*b0.x + ringSin1*b1.x + ringCos1*b2.x) * radius,
|
||||
capCenter.y + (sinf(baseRingAngle * ( i + 0 ))*b0.y + ringSin1*b1.y + ringCos1*b2.y) * radius,
|
||||
capCenter.z + (sinf(baseRingAngle * ( i + 0 ))*b0.z + ringSin1*b1.z + ringCos1*b2.z) * radius
|
||||
};
|
||||
float ringSin2 = sinf(baseSliceAngle*(j + 1))*cosf(baseRingAngle * ( i + 0 ));
|
||||
float ringCos2 = cosf(baseSliceAngle*(j + 1))*cosf(baseRingAngle * ( i + 0 ));
|
||||
Vector3 w2 = (Vector3){
|
||||
capCenter.x + (sinf(baseRingAngle * ( i + 0 ))*b0.x + ringSin2*b1.x + ringCos2*b2.x) * radius,
|
||||
capCenter.y + (sinf(baseRingAngle * ( i + 0 ))*b0.y + ringSin2*b1.y + ringCos2*b2.y) * radius,
|
||||
capCenter.z + (sinf(baseRingAngle * ( i + 0 ))*b0.z + ringSin2*b1.z + ringCos2*b2.z) * radius
|
||||
};
|
||||
|
||||
float ringSin3 = sinf(baseSliceAngle*(j + 0))*cosf(baseRingAngle * ( i + 1 ));
|
||||
float ringCos3 = cosf(baseSliceAngle*(j + 0))*cosf(baseRingAngle * ( i + 1 ));
|
||||
Vector3 w3 = (Vector3){
|
||||
capCenter.x + (sinf(baseRingAngle * ( i + 1 ))*b0.x + ringSin3*b1.x + ringCos3*b2.x) * radius,
|
||||
capCenter.y + (sinf(baseRingAngle * ( i + 1 ))*b0.y + ringSin3*b1.y + ringCos3*b2.y) * radius,
|
||||
capCenter.z + (sinf(baseRingAngle * ( i + 1 ))*b0.z + ringSin3*b1.z + ringCos3*b2.z) * radius
|
||||
};
|
||||
float ringSin4 = sinf(baseSliceAngle*(j + 1))*cosf(baseRingAngle * ( i + 1 ));
|
||||
float ringCos4 = cosf(baseSliceAngle*(j + 1))*cosf(baseRingAngle * ( i + 1 ));
|
||||
Vector3 w4 = (Vector3){
|
||||
capCenter.x + (sinf(baseRingAngle * ( i + 1 ))*b0.x + ringSin4*b1.x + ringCos4*b2.x) * radius,
|
||||
capCenter.y + (sinf(baseRingAngle * ( i + 1 ))*b0.y + ringSin4*b1.y + ringCos4*b2.y) * radius,
|
||||
capCenter.z + (sinf(baseRingAngle * ( i + 1 ))*b0.z + ringSin4*b1.z + ringCos4*b2.z) * radius
|
||||
};
|
||||
|
||||
rlVertex3f(w1.x, w1.y, w1.z);
|
||||
rlVertex3f(w2.x, w2.y, w2.z);
|
||||
|
||||
rlVertex3f(w2.x, w2.y, w2.z);
|
||||
rlVertex3f(w3.x, w3.y, w3.z);
|
||||
|
||||
rlVertex3f(w1.x, w1.y, w1.z);
|
||||
rlVertex3f(w3.x, w3.y, w3.z);
|
||||
|
||||
rlVertex3f(w2.x, w2.y, w2.z);
|
||||
rlVertex3f(w4.x, w4.y, w4.z);
|
||||
|
||||
rlVertex3f(w3.x, w3.y, w3.z);
|
||||
rlVertex3f(w4.x, w4.y, w4.z);
|
||||
}
|
||||
}
|
||||
capCenter = startPos;
|
||||
b0 = Vector3Scale(b0, -1.0f);
|
||||
}
|
||||
// render middle
|
||||
if (!sphereCase)
|
||||
{
|
||||
for (int j = 0; j < slices; j++)
|
||||
{
|
||||
// compute the four vertices
|
||||
float ringSin1 = sinf(baseSliceAngle*(j + 0))*radius;
|
||||
float ringCos1 = cosf(baseSliceAngle*(j + 0))*radius;
|
||||
Vector3 w1 = {
|
||||
startPos.x + ringSin1*b1.x + ringCos1*b2.x,
|
||||
startPos.y + ringSin1*b1.y + ringCos1*b2.y,
|
||||
startPos.z + ringSin1*b1.z + ringCos1*b2.z
|
||||
};
|
||||
float ringSin2 = sinf(baseSliceAngle*(j + 1))*radius;
|
||||
float ringCos2 = cosf(baseSliceAngle*(j + 1))*radius;
|
||||
Vector3 w2 = {
|
||||
startPos.x + ringSin2*b1.x + ringCos2*b2.x,
|
||||
startPos.y + ringSin2*b1.y + ringCos2*b2.y,
|
||||
startPos.z + ringSin2*b1.z + ringCos2*b2.z
|
||||
};
|
||||
|
||||
float ringSin3 = sinf(baseSliceAngle*(j + 0))*radius;
|
||||
float ringCos3 = cosf(baseSliceAngle*(j + 0))*radius;
|
||||
Vector3 w3 = {
|
||||
endPos.x + ringSin3*b1.x + ringCos3*b2.x,
|
||||
endPos.y + ringSin3*b1.y + ringCos3*b2.y,
|
||||
endPos.z + ringSin3*b1.z + ringCos3*b2.z
|
||||
};
|
||||
float ringSin4 = sinf(baseSliceAngle*(j + 1))*radius;
|
||||
float ringCos4 = cosf(baseSliceAngle*(j + 1))*radius;
|
||||
Vector3 w4 = {
|
||||
endPos.x + ringSin4*b1.x + ringCos4*b2.x,
|
||||
endPos.y + ringSin4*b1.y + ringCos4*b2.y,
|
||||
endPos.z + ringSin4*b1.z + ringCos4*b2.z
|
||||
};
|
||||
|
||||
rlVertex3f(w1.x, w1.y, w1.z);
|
||||
rlVertex3f(w3.x, w3.y, w3.z);
|
||||
|
||||
rlVertex3f(w2.x, w2.y, w2.z);
|
||||
rlVertex3f(w4.x, w4.y, w4.z);
|
||||
|
||||
rlVertex3f(w2.x, w2.y, w2.z);
|
||||
rlVertex3f(w3.x, w3.y, w3.z);
|
||||
}
|
||||
}
|
||||
rlEnd();
|
||||
}
|
||||
|
||||
// Draw a plane
|
||||
void DrawPlane(Vector3 centerPos, Vector2 size, Color color)
|
||||
{
|
||||
|
|
@ -1839,13 +1972,14 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||
for (int m = 0; m < model.meshCount; m++)
|
||||
{
|
||||
Mesh mesh = model.meshes[m];
|
||||
|
||||
if (mesh.boneIds == NULL || mesh.boneWeights == NULL)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "MODEL: UpdateModelAnimation Mesh %i has no connection to bones",m);
|
||||
TRACELOG(LOG_WARNING, "MODEL: UpdateModelAnimation(): Mesh %i has no connection to bones", m);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool updated = false; // set to true when anim vertex information is updated
|
||||
bool updated = false; // Flag to check when anim vertex information is updated
|
||||
Vector3 animVertex = { 0 };
|
||||
Vector3 animNormal = { 0 };
|
||||
|
||||
|
|
@ -1862,13 +1996,13 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||
float boneWeight = 0.0;
|
||||
|
||||
const int vValues = mesh.vertexCount*3;
|
||||
for (int vCounter = 0; vCounter < vValues; vCounter+=3)
|
||||
for (int vCounter = 0; vCounter < vValues; vCounter += 3)
|
||||
{
|
||||
mesh.animVertices[vCounter] = 0;
|
||||
mesh.animVertices[vCounter + 1] = 0;
|
||||
mesh.animVertices[vCounter + 2] = 0;
|
||||
|
||||
if (mesh.animNormals!=NULL)
|
||||
if (mesh.animNormals != NULL)
|
||||
{
|
||||
mesh.animNormals[vCounter] = 0;
|
||||
mesh.animNormals[vCounter + 1] = 0;
|
||||
|
|
@ -1879,16 +2013,15 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||
for (int j = 0; j < 4; j++, boneCounter++)
|
||||
{
|
||||
boneWeight = mesh.boneWeights[boneCounter];
|
||||
// early stop when no transformation will be applied
|
||||
if (boneWeight == 0.0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Early stop when no transformation will be applied
|
||||
if (boneWeight == 0.0f) continue;
|
||||
|
||||
boneId = mesh.boneIds[boneCounter];
|
||||
//int boneIdParent = model.bones[boneId].parent;
|
||||
inTranslation = model.bindPose[boneId].translation;
|
||||
inRotation = model.bindPose[boneId].rotation;
|
||||
// inScale = model.bindPose[boneId].scale;
|
||||
//inScale = model.bindPose[boneId].scale;
|
||||
outTranslation = anim.framePoses[frame][boneId].translation;
|
||||
outRotation = anim.framePoses[frame][boneId].rotation;
|
||||
outScale = anim.framePoses[frame][boneId].scale;
|
||||
|
|
@ -1900,7 +2033,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||
animVertex = Vector3Subtract(animVertex, inTranslation);
|
||||
animVertex = Vector3RotateByQuaternion(animVertex, QuaternionMultiply(outRotation, QuaternionInvert(inRotation)));
|
||||
animVertex = Vector3Add(animVertex, outTranslation);
|
||||
// animVertex = Vector3Transform(animVertex, model.transform);
|
||||
//animVertex = Vector3Transform(animVertex, model.transform);
|
||||
mesh.animVertices[vCounter] += animVertex.x*boneWeight;
|
||||
mesh.animVertices[vCounter + 1] += animVertex.y*boneWeight;
|
||||
mesh.animVertices[vCounter + 2] += animVertex.z*boneWeight;
|
||||
|
|
@ -1920,10 +2053,11 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||
}
|
||||
|
||||
// Upload new vertex data to GPU for model drawing
|
||||
// Only update data when values changed.
|
||||
if (updated){
|
||||
rlUpdateVertexBuffer(mesh.vboId[0], mesh.animVertices, mesh.vertexCount*3*sizeof(float), 0); // Update vertex position
|
||||
rlUpdateVertexBuffer(mesh.vboId[2], mesh.animNormals, mesh.vertexCount*3*sizeof(float), 0); // Update vertex normals
|
||||
// NOTE: Only update data when values changed
|
||||
if (updated)
|
||||
{
|
||||
rlUpdateVertexBuffer(mesh.vboId[0], mesh.animVertices, mesh.vertexCount*3*sizeof(float), 0); // Update vertex position
|
||||
rlUpdateVertexBuffer(mesh.vboId[2], mesh.animNormals, mesh.vertexCount*3*sizeof(float), 0); // Update vertex normals
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
107
src/rshapes.c
107
src/rshapes.c
|
|
@ -58,6 +58,7 @@
|
|||
|
||||
#include <math.h> // Required for: sinf(), asinf(), cosf(), acosf(), sqrtf(), fabsf()
|
||||
#include <float.h> // Required for: FLT_EPSILON
|
||||
#include <stdlib.h> // Required for: RL_FREE
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
|
|
@ -104,21 +105,50 @@ void SetShapesTexture(Texture2D texture, Rectangle source)
|
|||
// Draw a pixel
|
||||
void DrawPixel(int posX, int posY, Color color)
|
||||
{
|
||||
rlBegin(RL_LINES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
rlVertex2f(posX, posY);
|
||||
rlVertex2f(posX + 1, posY + 1);
|
||||
rlEnd();
|
||||
DrawPixelV((Vector2){ posX, posY }, color);
|
||||
}
|
||||
|
||||
// Draw a pixel (Vector version)
|
||||
void DrawPixelV(Vector2 position, Color color)
|
||||
{
|
||||
rlBegin(RL_LINES);
|
||||
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
||||
rlSetTexture(texShapes.id);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height);
|
||||
rlVertex2f(position.x, position.y);
|
||||
rlVertex2f(position.x + 1.0f, position.y + 1.0f);
|
||||
|
||||
rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
|
||||
rlVertex2f(position.x, position.y + 1);
|
||||
|
||||
rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
|
||||
rlVertex2f(position.x + 1, position.y + 1);
|
||||
|
||||
rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height);
|
||||
rlVertex2f(position.x + 1, position.y);
|
||||
|
||||
rlEnd();
|
||||
|
||||
rlSetTexture(0);
|
||||
#else
|
||||
rlBegin(RL_TRIANGLES);
|
||||
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
rlVertex2f(position.x, position.y);
|
||||
rlVertex2f(position.x, position.y + 1);
|
||||
rlVertex2f(position.x + 1, position.y);
|
||||
|
||||
rlVertex2f(position.x + 1, position.y);
|
||||
rlVertex2f(position.x, position.y + 1);
|
||||
rlVertex2f(position.x + 1, position.y + 1);
|
||||
|
||||
rlEnd();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draw a line
|
||||
|
|
@ -168,6 +198,8 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
|
|||
Vector2 previous = startPos;
|
||||
Vector2 current = { 0 };
|
||||
|
||||
Vector2 points[2*BEZIER_LINE_DIVISIONS + 2] = { 0 };
|
||||
|
||||
for (int i = 1; i <= BEZIER_LINE_DIVISIONS; i++)
|
||||
{
|
||||
// Cubic easing in-out
|
||||
|
|
@ -175,10 +207,27 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
|
|||
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);
|
||||
float dy = current.y-previous.y;
|
||||
float dx = current.x-previous.x;
|
||||
float size = 0.5*thick/sqrt(dx*dx+dy*dy);
|
||||
|
||||
if (i==1)
|
||||
{
|
||||
points[0].x = previous.x+dy*size;
|
||||
points[0].y = previous.y-dx*size;
|
||||
points[1].x = previous.x-dy*size;
|
||||
points[1].y = previous.y+dx*size;
|
||||
}
|
||||
|
||||
points[2*i+1].x = current.x-dy*size;
|
||||
points[2*i+1].y = current.y+dx*size;
|
||||
points[2*i].x = current.x+dy*size;
|
||||
points[2*i].y = current.y-dx*size;
|
||||
|
||||
previous = current;
|
||||
}
|
||||
|
||||
DrawTriangleStrip(points, 2*BEZIER_LINE_DIVISIONS+2, color);
|
||||
}
|
||||
|
||||
// Draw line using quadratic bezier curves with a control point
|
||||
|
|
@ -190,6 +239,8 @@ void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, fl
|
|||
Vector2 current = { 0 };
|
||||
float t = 0.0f;
|
||||
|
||||
Vector2 points[2*BEZIER_LINE_DIVISIONS + 2] = { 0 };
|
||||
|
||||
for (int i = 0; i <= BEZIER_LINE_DIVISIONS; i++)
|
||||
{
|
||||
t = step*i;
|
||||
|
|
@ -201,10 +252,27 @@ void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, fl
|
|||
current.y = a*startPos.y + b*controlPos.y + c*endPos.y;
|
||||
current.x = a*startPos.x + b*controlPos.x + c*endPos.x;
|
||||
|
||||
DrawLineEx(previous, current, thick, color);
|
||||
float dy = current.y-previous.y;
|
||||
float dx = current.x-previous.x;
|
||||
float size = 0.5*thick/sqrt(dx*dx+dy*dy);
|
||||
|
||||
if (i==1)
|
||||
{
|
||||
points[0].x = previous.x+dy*size;
|
||||
points[0].y = previous.y-dx*size;
|
||||
points[1].x = previous.x-dy*size;
|
||||
points[1].y = previous.y+dx*size;
|
||||
}
|
||||
|
||||
points[2*i+1].x = current.x-dy*size;
|
||||
points[2*i+1].y = current.y+dx*size;
|
||||
points[2*i].x = current.x+dy*size;
|
||||
points[2*i].y = current.y-dx*size;
|
||||
|
||||
previous = current;
|
||||
}
|
||||
|
||||
DrawTriangleStrip(points, 2*BEZIER_LINE_DIVISIONS+2, color);
|
||||
}
|
||||
|
||||
// Draw line using cubic bezier curves with 2 control points
|
||||
|
|
@ -216,6 +284,8 @@ void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlP
|
|||
Vector2 current = { 0 };
|
||||
float t = 0.0f;
|
||||
|
||||
Vector2 points[2*BEZIER_LINE_DIVISIONS + 2] = { 0 };
|
||||
|
||||
for (int i = 0; i <= BEZIER_LINE_DIVISIONS; i++)
|
||||
{
|
||||
t = step*i;
|
||||
|
|
@ -227,10 +297,27 @@ void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlP
|
|||
current.y = a*startPos.y + b*startControlPos.y + c*endControlPos.y + d*endPos.y;
|
||||
current.x = a*startPos.x + b*startControlPos.x + c*endControlPos.x + d*endPos.x;
|
||||
|
||||
DrawLineEx(previous, current, thick, color);
|
||||
float dy = current.y-previous.y;
|
||||
float dx = current.x-previous.x;
|
||||
float size = 0.5*thick/sqrt(dx*dx+dy*dy);
|
||||
|
||||
if (i==1)
|
||||
{
|
||||
points[0].x = previous.x+dy*size;
|
||||
points[0].y = previous.y-dx*size;
|
||||
points[1].x = previous.x-dy*size;
|
||||
points[1].y = previous.y+dx*size;
|
||||
}
|
||||
|
||||
points[2*i+1].x = current.x-dy*size;
|
||||
points[2*i+1].y = current.y+dx*size;
|
||||
points[2*i].x = current.x+dy*size;
|
||||
points[2*i].y = current.y-dx*size;
|
||||
|
||||
previous = current;
|
||||
}
|
||||
|
||||
DrawTriangleStrip(points, 2*BEZIER_LINE_DIVISIONS+2, color);
|
||||
}
|
||||
|
||||
// Draw lines sequence
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
|
||||
#if defined(SUPPORT_MODULE_RTEXT)
|
||||
|
||||
#include "utils.h" // Required for: LoadFileText()
|
||||
#include "utils.h" // Required for: LoadFile*()
|
||||
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2 -> Only DrawTextPro()
|
||||
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
|
|
@ -359,7 +359,7 @@ Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int glyphCou
|
|||
// Loading font from memory data
|
||||
font = LoadFontFromMemory(GetFileExtension(fileName), fileData, fileSize, fontSize, fontChars, glyphCount);
|
||||
|
||||
RL_FREE(fileData);
|
||||
UnloadFileData(fileData);
|
||||
}
|
||||
else font = GetFontDefault();
|
||||
|
||||
|
|
|
|||
311
src/rtextures.c
311
src/rtextures.c
|
|
@ -194,6 +194,10 @@
|
|||
#define PIXELFORMAT_UNCOMPRESSED_R5G5B5A1_ALPHA_THRESHOLD 50 // Threshold over 255 to set alpha as 0
|
||||
#endif
|
||||
|
||||
#ifndef GAUSSIAN_BLUR_ITERATIONS
|
||||
#define GAUSSIAN_BLUR_ITERATIONS 4 // Number of box blur iterations to approximate gaussian blur
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -402,7 +406,6 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
|
|||
#if defined(SUPPORT_FILEFORMAT_DDS)
|
||||
else if (strcmp(fileType, ".dds") == 0)
|
||||
{
|
||||
int format = 0;
|
||||
image.data = rl_load_dds_from_memory(fileData, dataSize, &image.width, &image.height, &image.format, &image.mipmaps);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -894,6 +897,25 @@ Image GenImageCellular(int width, int height, int tileSize)
|
|||
|
||||
return image;
|
||||
}
|
||||
|
||||
// Generate image: grayscale image from text data
|
||||
Image GenImageText(int width, int height, const char *text)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
int textLength = TextLength(text);
|
||||
int imageViewSize = width*height;
|
||||
|
||||
image.width = width;
|
||||
image.height = height;
|
||||
image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
|
||||
image.data = RL_CALLOC(imageViewSize, 1);
|
||||
image.mipmaps = 1;
|
||||
|
||||
memcpy(image.data, text, (textLength > imageViewSize)? imageViewSize : textLength);
|
||||
|
||||
return image;
|
||||
}
|
||||
#endif // SUPPORT_IMAGE_GENERATION
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
|
@ -1230,6 +1252,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
|
|||
|
||||
// NOTE: Text image is generated at font base size, later scaled to desired font size
|
||||
Vector2 imSize = MeasureTextEx(font, text, (float)font.baseSize, spacing); // WARNING: Module required: rtext
|
||||
Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing);
|
||||
|
||||
// Create image to store text
|
||||
imText = GenImageColor((int)imSize.x, (int)imSize.y, BLANK);
|
||||
|
|
@ -1268,12 +1291,13 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
|
|||
}
|
||||
|
||||
// Scale image depending on text size
|
||||
if (fontSize > imSize.y)
|
||||
if (textSize.y != imSize.y)
|
||||
{
|
||||
float scaleFactor = fontSize/imSize.y;
|
||||
float scaleFactor = textSize.y / imSize.y;
|
||||
TRACELOG(LOG_INFO, "IMAGE: Text scaled by factor: %f", scaleFactor);
|
||||
|
||||
// Using nearest-neighbor scaling algorithm for default font
|
||||
// TODO: Allow defining the preferred scaling mechanism externally
|
||||
// WARNING: Module required: rtext
|
||||
if (font.texture.id == GetFontDefault().texture.id) ImageResizeNN(&imText, (int)(imSize.x*scaleFactor), (int)(imSize.y*scaleFactor));
|
||||
else ImageResize(&imText, (int)(imSize.x*scaleFactor), (int)(imSize.y*scaleFactor));
|
||||
|
|
@ -1475,6 +1499,158 @@ void ImageAlphaPremultiply(Image *image)
|
|||
ImageFormat(image, format);
|
||||
}
|
||||
|
||||
// Apply box blur
|
||||
void ImageBlurGaussian(Image *image, int blurSize) {
|
||||
// Security check to avoid program crash
|
||||
if ((image->data == NULL) || (image->width == 0) || (image->height == 0)) return;
|
||||
|
||||
ImageAlphaPremultiply(image);
|
||||
|
||||
Color *pixels = LoadImageColors(*image);
|
||||
|
||||
// Loop switches between pixelsCopy1 and pixelsCopy2
|
||||
Vector4 *pixelsCopy1 = RL_MALLOC((image->height)*(image->width)*sizeof(Vector4));
|
||||
Vector4 *pixelsCopy2 = RL_MALLOC((image->height)*(image->width)*sizeof(Vector4));
|
||||
|
||||
for (int i = 0; i < (image->height)*(image->width); i++) {
|
||||
pixelsCopy1[i].x = pixels[i].r;
|
||||
pixelsCopy1[i].y = pixels[i].g;
|
||||
pixelsCopy1[i].z = pixels[i].b;
|
||||
pixelsCopy1[i].w = pixels[i].a;
|
||||
}
|
||||
|
||||
// Repeated convolution of rectangular window signal by itself converges to a gaussian distribution
|
||||
for (int j = 0; j < GAUSSIAN_BLUR_ITERATIONS; j++) {
|
||||
// Horizontal motion blur
|
||||
for (int row = 0; row < image->height; row++)
|
||||
{
|
||||
float avgR = 0.0f;
|
||||
float avgG = 0.0f;
|
||||
float avgB = 0.0f;
|
||||
float avgAlpha = 0.0f;
|
||||
int convolutionSize = blurSize+1;
|
||||
|
||||
for (int i = 0; i < blurSize+1; i++)
|
||||
{
|
||||
avgR += pixelsCopy1[row*image->width + i].x;
|
||||
avgG += pixelsCopy1[row*image->width + i].y;
|
||||
avgB += pixelsCopy1[row*image->width + i].z;
|
||||
avgAlpha += pixelsCopy1[row*image->width + i].w;
|
||||
}
|
||||
|
||||
pixelsCopy2[row*image->width].x = avgR/convolutionSize;
|
||||
pixelsCopy2[row*image->width].y = avgG/convolutionSize;
|
||||
pixelsCopy2[row*image->width].z = avgB/convolutionSize;
|
||||
pixelsCopy2[row*image->width].w = avgAlpha/convolutionSize;
|
||||
|
||||
for (int x = 1; x < image->width; x++)
|
||||
{
|
||||
if (x-blurSize >= 0)
|
||||
{
|
||||
avgR -= pixelsCopy1[row*image->width + x-blurSize].x;
|
||||
avgG -= pixelsCopy1[row*image->width + x-blurSize].y;
|
||||
avgB -= pixelsCopy1[row*image->width + x-blurSize].z;
|
||||
avgAlpha -= pixelsCopy1[row*image->width + x-blurSize].w;
|
||||
convolutionSize--;
|
||||
}
|
||||
|
||||
if (x+blurSize < image->width)
|
||||
{
|
||||
avgR += pixelsCopy1[row*image->width + x+blurSize].x;
|
||||
avgG += pixelsCopy1[row*image->width + x+blurSize].y;
|
||||
avgB += pixelsCopy1[row*image->width + x+blurSize].z;
|
||||
avgAlpha += pixelsCopy1[row*image->width + x+blurSize].w;
|
||||
convolutionSize++;
|
||||
}
|
||||
|
||||
pixelsCopy2[row*image->width + x].x = avgR/convolutionSize;
|
||||
pixelsCopy2[row*image->width + x].y = avgG/convolutionSize;
|
||||
pixelsCopy2[row*image->width + x].z = avgB/convolutionSize;
|
||||
pixelsCopy2[row*image->width + x].w = avgAlpha/convolutionSize;
|
||||
}
|
||||
}
|
||||
|
||||
// Vertical motion blur
|
||||
for (int col = 0; col < image->width; col++)
|
||||
{
|
||||
float avgR = 0.0f;
|
||||
float avgG = 0.0f;
|
||||
float avgB = 0.0f;
|
||||
float avgAlpha = 0.0f;
|
||||
int convolutionSize = blurSize+1;
|
||||
|
||||
for (int i = 0; i < blurSize+1; i++)
|
||||
{
|
||||
avgR += pixelsCopy2[i*image->width + col].x;
|
||||
avgG += pixelsCopy2[i*image->width + col].y;
|
||||
avgB += pixelsCopy2[i*image->width + col].z;
|
||||
avgAlpha += pixelsCopy2[i*image->width + col].w;
|
||||
}
|
||||
|
||||
pixelsCopy1[col].x = (unsigned char) (avgR/convolutionSize);
|
||||
pixelsCopy1[col].y = (unsigned char) (avgG/convolutionSize);
|
||||
pixelsCopy1[col].z = (unsigned char) (avgB/convolutionSize);
|
||||
pixelsCopy1[col].w = (unsigned char) (avgAlpha/convolutionSize);
|
||||
|
||||
for (int y = 1; y < image->height; y++)
|
||||
{
|
||||
if (y-blurSize >= 0)
|
||||
{
|
||||
avgR -= pixelsCopy2[(y-blurSize)*image->width + col].x;
|
||||
avgG -= pixelsCopy2[(y-blurSize)*image->width + col].y;
|
||||
avgB -= pixelsCopy2[(y-blurSize)*image->width + col].z;
|
||||
avgAlpha -= pixelsCopy2[(y-blurSize)*image->width + col].w;
|
||||
convolutionSize--;
|
||||
}
|
||||
if (y+blurSize < image->height)
|
||||
{
|
||||
avgR += pixelsCopy2[(y+blurSize)*image->width + col].x;
|
||||
avgG += pixelsCopy2[(y+blurSize)*image->width + col].y;
|
||||
avgB += pixelsCopy2[(y+blurSize)*image->width + col].z;
|
||||
avgAlpha += pixelsCopy2[(y+blurSize)*image->width + col].w;
|
||||
convolutionSize++;
|
||||
}
|
||||
|
||||
pixelsCopy1[y*image->width + col].x = (unsigned char) (avgR/convolutionSize);
|
||||
pixelsCopy1[y*image->width + col].y = (unsigned char) (avgG/convolutionSize);
|
||||
pixelsCopy1[y*image->width + col].z = (unsigned char) (avgB/convolutionSize);
|
||||
pixelsCopy1[y*image->width + col].w = (unsigned char) (avgAlpha/convolutionSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reverse premultiply
|
||||
for (int i = 0; i < (image->width)*(image->height); i++)
|
||||
{
|
||||
if (pixelsCopy1[i].w == 0.0f)
|
||||
{
|
||||
pixels[i].r = 0;
|
||||
pixels[i].g = 0;
|
||||
pixels[i].b = 0;
|
||||
pixels[i].a = 0;
|
||||
}
|
||||
else if (pixelsCopy1[i].w <= 255.0f)
|
||||
{
|
||||
float alpha = (float)pixelsCopy1[i].w/255.0f;
|
||||
pixels[i].r = (unsigned char)((float)pixelsCopy1[i].x/alpha);
|
||||
pixels[i].g = (unsigned char)((float)pixelsCopy1[i].y/alpha);
|
||||
pixels[i].b = (unsigned char)((float)pixelsCopy1[i].z/alpha);
|
||||
pixels[i].a = (unsigned char) pixelsCopy1[i].w;
|
||||
}
|
||||
}
|
||||
|
||||
int format = image->format;
|
||||
RL_FREE(image->data);
|
||||
RL_FREE(pixelsCopy1);
|
||||
RL_FREE(pixelsCopy2);
|
||||
|
||||
image->data = pixels;
|
||||
image->format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
|
||||
ImageFormat(image, format);
|
||||
}
|
||||
|
||||
// Resize and image to new size
|
||||
// NOTE: Uses stb default scaling filters (both bicubic):
|
||||
// STBIR_DEFAULT_FILTER_UPSAMPLE STBIR_FILTER_CATMULLROM
|
||||
|
|
@ -3436,104 +3612,6 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2
|
|||
}
|
||||
}
|
||||
|
||||
// Draw texture quad with tiling and offset parameters
|
||||
// NOTE: Tiling and offset should be provided considering normalized texture values [0..1]
|
||||
// i.e tiling = { 1.0f, 1.0f } refers to all texture, offset = { 0.5f, 0.5f } moves texture origin to center
|
||||
void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Rectangle quad, Color tint)
|
||||
{
|
||||
// WARNING: This solution only works if TEXTURE_WRAP_REPEAT is supported,
|
||||
// NPOT textures supported is required and OpenGL ES 2.0 could not support it
|
||||
Rectangle source = { offset.x*texture.width, offset.y*texture.height, tiling.x*texture.width, tiling.y*texture.height };
|
||||
Vector2 origin = { 0.0f, 0.0f };
|
||||
|
||||
DrawTexturePro(texture, source, quad, origin, 0.0f, tint);
|
||||
}
|
||||
|
||||
// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest.
|
||||
// NOTE: For tilling a whole texture DrawTextureQuad() is better
|
||||
void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint)
|
||||
{
|
||||
if ((texture.id <= 0) || (scale <= 0.0f)) return; // Wanna see a infinite loop?!...just delete this line!
|
||||
if ((source.width == 0) || (source.height == 0)) return;
|
||||
|
||||
int tileWidth = (int)(source.width*scale), tileHeight = (int)(source.height*scale);
|
||||
if ((dest.width < tileWidth) && (dest.height < tileHeight))
|
||||
{
|
||||
// Can fit only one tile
|
||||
DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)dest.width/tileWidth)*source.width, ((float)dest.height/tileHeight)*source.height},
|
||||
(Rectangle){dest.x, dest.y, dest.width, dest.height}, origin, rotation, tint);
|
||||
}
|
||||
else if (dest.width <= tileWidth)
|
||||
{
|
||||
// Tiled vertically (one column)
|
||||
int dy = 0;
|
||||
for (;dy+tileHeight < dest.height; dy += tileHeight)
|
||||
{
|
||||
DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)dest.width/tileWidth)*source.width, source.height}, (Rectangle){dest.x, dest.y + dy, dest.width, (float)tileHeight}, origin, rotation, tint);
|
||||
}
|
||||
|
||||
// Fit last tile
|
||||
if (dy < dest.height)
|
||||
{
|
||||
DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)dest.width/tileWidth)*source.width, ((float)(dest.height - dy)/tileHeight)*source.height},
|
||||
(Rectangle){dest.x, dest.y + dy, dest.width, dest.height - dy}, origin, rotation, tint);
|
||||
}
|
||||
}
|
||||
else if (dest.height <= tileHeight)
|
||||
{
|
||||
// Tiled horizontally (one row)
|
||||
int dx = 0;
|
||||
for (;dx+tileWidth < dest.width; dx += tileWidth)
|
||||
{
|
||||
DrawTexturePro(texture, (Rectangle){source.x, source.y, source.width, ((float)dest.height/tileHeight)*source.height}, (Rectangle){dest.x + dx, dest.y, (float)tileWidth, dest.height}, origin, rotation, tint);
|
||||
}
|
||||
|
||||
// Fit last tile
|
||||
if (dx < dest.width)
|
||||
{
|
||||
DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)(dest.width - dx)/tileWidth)*source.width, ((float)dest.height/tileHeight)*source.height},
|
||||
(Rectangle){dest.x + dx, dest.y, dest.width - dx, dest.height}, origin, rotation, tint);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Tiled both horizontally and vertically (rows and columns)
|
||||
int dx = 0;
|
||||
for (;dx+tileWidth < dest.width; dx += tileWidth)
|
||||
{
|
||||
int dy = 0;
|
||||
for (;dy+tileHeight < dest.height; dy += tileHeight)
|
||||
{
|
||||
DrawTexturePro(texture, source, (Rectangle){dest.x + dx, dest.y + dy, (float)tileWidth, (float)tileHeight}, origin, rotation, tint);
|
||||
}
|
||||
|
||||
if (dy < dest.height)
|
||||
{
|
||||
DrawTexturePro(texture, (Rectangle){source.x, source.y, source.width, ((float)(dest.height - dy)/tileHeight)*source.height},
|
||||
(Rectangle){dest.x + dx, dest.y + dy, (float)tileWidth, dest.height - dy}, origin, rotation, tint);
|
||||
}
|
||||
}
|
||||
|
||||
// Fit last column of tiles
|
||||
if (dx < dest.width)
|
||||
{
|
||||
int dy = 0;
|
||||
for (;dy+tileHeight < dest.height; dy += tileHeight)
|
||||
{
|
||||
DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)(dest.width - dx)/tileWidth)*source.width, source.height},
|
||||
(Rectangle){dest.x + dx, dest.y + dy, dest.width - dx, (float)tileHeight}, origin, rotation, tint);
|
||||
}
|
||||
|
||||
// Draw final tile in the bottom right corner
|
||||
if (dy < dest.height)
|
||||
{
|
||||
DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)(dest.width - dx)/tileWidth)*source.width, ((float)(dest.height - dy)/tileHeight)*source.height},
|
||||
(Rectangle){dest.x + dx, dest.y + dy, dest.width - dx, dest.height - dy}, origin, rotation, tint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draws a texture (or part of it) that stretches or shrinks nicely using n-patch info
|
||||
void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint)
|
||||
{
|
||||
|
|
@ -3731,37 +3809,6 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest,
|
|||
}
|
||||
}
|
||||
|
||||
// Draw textured polygon, defined by vertex and texturecoordinates
|
||||
// NOTE: Polygon center must have straight line path to all points
|
||||
// without crossing perimeter, points must be in anticlockwise order
|
||||
void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint)
|
||||
{
|
||||
rlSetTexture(texture.id);
|
||||
|
||||
// Texturing is only supported on RL_QUADS
|
||||
rlBegin(RL_QUADS);
|
||||
|
||||
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
|
||||
|
||||
for (int i = 0; i < pointCount - 1; i++)
|
||||
{
|
||||
rlTexCoord2f(0.5f, 0.5f);
|
||||
rlVertex2f(center.x, center.y);
|
||||
|
||||
rlTexCoord2f(texcoords[i].x, texcoords[i].y);
|
||||
rlVertex2f(points[i].x + center.x, points[i].y + center.y);
|
||||
|
||||
rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y);
|
||||
rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y);
|
||||
|
||||
rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y);
|
||||
rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y);
|
||||
}
|
||||
rlEnd();
|
||||
|
||||
rlSetTexture(0);
|
||||
}
|
||||
|
||||
// Get color with alpha applied, alpha goes from 0.0f to 1.0f
|
||||
Color Fade(Color color, float alpha)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite)
|
|||
}
|
||||
|
||||
// Export data to code (.h), returns true on success
|
||||
bool ExportDataAsCode(const char *data, unsigned int size, const char *fileName)
|
||||
bool ExportDataAsCode(const unsigned char *data, unsigned int size, const char *fileName)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue