Merge branch 'master' of github.com:raysan5/raylib

This commit is contained in:
Jeffery Myers 2024-07-01 12:02:42 -07:00
commit 95d0826f70
34 changed files with 1055 additions and 652 deletions

1
.gitignore vendored
View file

@ -104,6 +104,7 @@ GRTAGS
GTAGS
# Zig programming language
.zig-cache/
zig-cache/
zig-out/
build/

View file

@ -4,7 +4,9 @@
#
# This file supports building raylib examples for the following platforms:
#
# > PLATFORM_DESKTOP (GLFW backend):
# > PLATFORM_DESKTOP
# - Defaults to PLATFORM_DESKTOP_GLFW
# > PLATFORM_DESKTOP_GFLW (GLFW backend):
# - Windows (Win32, Win64)
# - Linux (X11/Wayland desktop mode)
# - macOS/OSX (x64, arm64)
@ -52,9 +54,15 @@
# Define target platform: PLATFORM_DESKTOP, PLATFORM_DESKTOP_SDL, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB
PLATFORM ?= PLATFORM_DESKTOP
ifeq ($(PLATFORM), PLATFORM_DESKTOP)
TARGET_PLATFORM = PLATFORM_DESKTOP_GLFW
else
TARGET_PLATFORM = $(PLATFORM)
endif
# Define required raylib variables
PROJECT_NAME ?= raylib_examples
RAYLIB_VERSION ?= 5.0.0
RAYLIB_VERSION ?= 5.5.0
RAYLIB_PATH ?= ..
# Define raylib source code path
@ -91,7 +99,7 @@ BUILD_WEB_RESOURCES ?= TRUE
BUILD_WEB_RESOURCES_PATH ?= $(dir $<)resources@resources
# Determine PLATFORM_OS when required
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_DESKTOP_SDL PLATFORM_WEB PLATFORM_DESKTOP_RGFW))
ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW PLATFORM_DESKTOP_SDL PLATFORM_DESKTOP_RGFW PLATFORM_WEB))
# No uname.exe on MinGW!, but OS=Windows_NT on Windows!
# ifeq ($(UNAME),Msys) -> Windows
ifeq ($(OS),Windows_NT)
@ -118,7 +126,7 @@ ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_DESKTOP_SDL PLA
endif
endif
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
UNAMEOS = $(shell uname)
ifeq ($(UNAMEOS),Linux)
PLATFORM_OS = LINUX
@ -127,7 +135,7 @@ endif
# RAYLIB_PATH adjustment for LINUX platform
# TODO: Do we really need this?
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),LINUX)
RAYLIB_PREFIX ?= ..
RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX))
@ -135,14 +143,14 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
endif
# Default path for raylib on Raspberry Pi
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
RAYLIB_PATH ?= /home/pi/raylib
endif
# Define raylib release directory for compiled library
RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
ifeq ($(PLATFORM_OS),WINDOWS)
# Emscripten required variables
EMSDK_PATH ?= C:/emsdk
@ -158,7 +166,7 @@ endif
#------------------------------------------------------------------------------------------------
CC = gcc
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),OSX)
# OSX default compiler
CC = clang
@ -168,7 +176,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
CC = clang
endif
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
# HTML5 emscripten compiler
# WARNING: To compile to HTML5, code must be redesigned
# to use emscripten.h and emscripten_set_main_loop()
@ -179,15 +187,15 @@ endif
#------------------------------------------------------------------------------------------------
MAKE ?= make
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),WINDOWS)
MAKE = mingw32-make
endif
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
MAKE = mingw32-make
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
MAKE = emmake make
endif
@ -206,11 +214,11 @@ CFLAGS = -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -Wunused-result
ifeq ($(BUILD_MODE),DEBUG)
CFLAGS += -g -D_DEBUG
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
CFLAGS += -sASSERTIONS=1 --profiling
endif
else
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
ifeq ($(BUILD_WEB_ASYNCIFY),TRUE)
CFLAGS += -O3
else
@ -227,7 +235,7 @@ endif
# -Wstrict-prototypes warn if a function is declared or defined without specifying the argument types
# -Werror=implicit-function-declaration catch function calls without prior declaration
#CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),LINUX)
ifeq ($(RAYLIB_LIBTYPE),STATIC)
CFLAGS += -D_DEFAULT_SOURCE
@ -238,7 +246,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
endif
endif
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
CFLAGS += -std=gnu99 -DEGL_NO_X11
endif
@ -248,7 +256,7 @@ endif
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
# Define additional directories containing required header files
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),BSD)
INCLUDE_PATHS += -I$(RAYLIB_INCLUDE_PATH)
endif
@ -256,10 +264,10 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
INCLUDE_PATHS += -I$(RAYLIB_INCLUDE_PATH)
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_SDL)
INCLUDE_PATHS += -I$(SDL_INCLUDE_PATH)
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
INCLUDE_PATHS += -I$(RAYLIB_INCLUDE_PATH)
INCLUDE_PATHS += -I/usr/include/libdrm
endif
@ -273,7 +281,7 @@ endif
#------------------------------------------------------------------------------------------------
LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),WINDOWS)
# NOTE: The resource .rc file contains windows executable icon and properties
LDFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data
@ -289,7 +297,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
LDFLAGS += -Lsrc -L$(RAYLIB_LIB_PATH)
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(PLATFORM_OS),WINDOWS)
# NOTE: The resource .rc file contains windows executable icon and properties
LDFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data
@ -300,7 +308,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
endif
LDFLAGS += -L$(SDL_LIBRARY_PATH)
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
# -Os # size optimization
# -O2 # optimization level 2, if used, also set --memory-init-file 0
# -sUSE_GLFW=3 # Use glfw3 library (context/input management)
@ -347,7 +355,7 @@ endif
# Define libraries required on linking: LDLIBS
# NOTE: To link libraries (lib<name>.so or lib<name>.a), use -l<name>
#------------------------------------------------------------------------------------------------
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),WINDOWS)
# Libraries for Windows desktop compilation
# NOTE: WinMM library required to set high-res timer resolution
@ -393,7 +401,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
LDLIBS += -lglfw
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(PLATFORM_OS),WINDOWS)
# Libraries for Windows desktop compilation
LDLIBS = -lraylib -lSDL2 -lSDL2main -lopengl32 -lgdi32
@ -421,7 +429,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
LDLIBS += -latomic
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_RGFW)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_RGFW)
ifeq ($(PLATFORM_OS),WINDOWS)
# Libraries for Windows desktop compilation
LDLIBS = ..\src\libraylib.a -lgdi32 -lwinmm -lopengl32
@ -446,12 +454,12 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP_RGFW)
LDLIBS += -framework Foundation -framework AppKit -framework OpenGL -framework CoreVideo
endif
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
# Libraries for DRM compiling
# NOTE: Required packages: libasound2-dev (ALSA)
LDLIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lgbm -ldrm -ldl -latomic
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
# Libraries for web (HTML5) compiling
LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.a
endif
@ -638,17 +646,17 @@ others: $(OTHERS)
# Generic compilation pattern
# NOTE: Examples must be ready for Android compilation!
%: %.c
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
$(MAKE) -f Makefile.Android PROJECT_NAME=$@ PROJECT_SOURCE_FILES=$<
else ifeq ($(PLATFORM),PLATFORM_WEB)
else ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
$(MAKE) -f Makefile.Web $@
else
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -D$(TARGET_PLATFORM)
endif
# Clean everything
clean:
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),WINDOWS)
del *.o *.exe /s
endif
@ -661,11 +669,11 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
rm -f *.o
endif
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
find . -type f -executable -delete
rm -fv *.o
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
ifeq ($(PLATFORM_OS),WINDOWS)
del *.wasm *.html *.js *.data
else

27
examples/examples.rc Normal file
View file

@ -0,0 +1,27 @@
GLFW_ICON ICON "raylib.ico"
1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
BEGIN
BLOCK "StringFileInfo"
BEGIN
//BLOCK "080904E4" // English UK
BLOCK "040904E4" // English US
BEGIN
VALUE "CompanyName", "raylib technologies"
VALUE "FileDescription", "raylib example"
VALUE "FileVersion", "1.0"
VALUE "InternalName", "raylib-example"
VALUE "LegalCopyright", "(c) 2024 raylib technologies (@raylibtech)"
//VALUE "OriginalFilename", "raylib_app.exe"
VALUE "ProductName", "raylib-example"
VALUE "ProductVersion", "1.0"
END
END
BLOCK "VarFileInfo"
BEGIN
//VALUE "Translation", 0x809, 1252 // English UK
VALUE "Translation", 0x409, 1252 // English US
END
END

View file

@ -49,7 +49,8 @@ int main(void)
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
Model skybox = LoadModelFromMesh(cube);
bool useHDR = true;
// Set this to true to use an HDR Texture, Note that raylib must be built with HDR Support for this to work SUPPORT_FILEFORMAT_HDR
bool useHDR = false;
// Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading
@ -157,8 +158,6 @@ int main(void)
DrawGrid(10, 1.0f);
EndMode3D();
//DrawTextureEx(panorama, (Vector2){ 0, 0 }, 0.0f, 0.5f, WHITE);
if (useHDR) DrawText(TextFormat("Panorama image from hdrihaven.com: %s", GetFileName(skyboxFileName)), 10, GetScreenHeight() - 20, 10, BLACK);
else DrawText(TextFormat(": %s", GetFileName(skyboxFileName)), 10, GetScreenHeight() - 20, 10, BLACK);

BIN
examples/raylib.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

View file

@ -0,0 +1,106 @@
/*******************************************************************************************
*
* raylib [textures] example - Retrive image channel (mask)
*
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
*
* Example originally created with raylib 5.1-dev, last time updated with raylib 5.1-dev
*
* Example contributed by Bruno Cabral (github.com/brccabral) and reviewed by Ramon Santamaria (@raysan5)
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2024-2024 Bruno Cabral (github.com/brccabral) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include <raylib.h>
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - extract channel from image");
Image fudesumiImage = LoadImage("resources/fudesumi.png");
Image imageAlpha = ImageFromChannel(fudesumiImage, 3);
ImageAlphaMask(&imageAlpha, imageAlpha);
Image imageRed = ImageFromChannel(fudesumiImage, 0);
ImageAlphaMask(&imageRed, imageAlpha);
Image imageGreen = ImageFromChannel(fudesumiImage, 1);
ImageAlphaMask(&imageGreen, imageAlpha);
Image imageBlue = ImageFromChannel(fudesumiImage, 2);
ImageAlphaMask(&imageBlue, imageAlpha);
Image backgroundImage = GenImageChecked(screenWidth, screenHeight, screenWidth/20, screenHeight/20, ORANGE, YELLOW);
Texture2D fudesumiTexture = LoadTextureFromImage(fudesumiImage);
Texture2D textureAlpha = LoadTextureFromImage(imageAlpha);
Texture2D textureRed = LoadTextureFromImage(imageRed);
Texture2D textureGreen = LoadTextureFromImage(imageGreen);
Texture2D textureBlue = LoadTextureFromImage(imageBlue);
Texture2D backgroundTexture = LoadTextureFromImage(backgroundImage);
UnloadImage(fudesumiImage);
UnloadImage(imageAlpha);
UnloadImage(imageRed);
UnloadImage(imageGreen);
UnloadImage(imageBlue);
UnloadImage(backgroundImage);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
Rectangle fudesumiRec = {0, 0, fudesumiImage.width, fudesumiImage.height};
Rectangle fudesumiPos = {50, 10, fudesumiImage.width*0.8f, fudesumiImage.height*0.8f};
Rectangle redPos = { 410, 10, fudesumiPos.width / 2, fudesumiPos.height / 2 };
Rectangle greenPos = { 600, 10, fudesumiPos.width / 2, fudesumiPos.height / 2 };
Rectangle bluePos = { 410, 230, fudesumiPos.width / 2, fudesumiPos.height / 2 };
Rectangle alphaPos = { 600, 230, fudesumiPos.width / 2, fudesumiPos.height / 2 };
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
DrawTexture(backgroundTexture, 0, 0, WHITE);
DrawTexturePro(fudesumiTexture, fudesumiRec, fudesumiPos, (Vector2) {0, 0}, 0, WHITE);
DrawTexturePro(textureRed, fudesumiRec, redPos, (Vector2) {0, 0}, 0, RED);
DrawTexturePro(textureGreen, fudesumiRec, greenPos, (Vector2) {0, 0}, 0, GREEN);
DrawTexturePro(textureBlue, fudesumiRec, bluePos, (Vector2) {0, 0}, 0, BLUE);
DrawTexturePro(textureAlpha, fudesumiRec, alphaPos, (Vector2) {0, 0}, 0, WHITE);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(backgroundTexture);
UnloadTexture(fudesumiTexture);
UnloadTexture(textureRed);
UnloadTexture(textureGreen);
UnloadTexture(textureBlue);
UnloadTexture(textureAlpha);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

View file

@ -15,7 +15,7 @@
{
"name": "RAYLIB_VERSION_MINOR",
"type": "INT",
"value": 1,
"value": 5,
"description": ""
},
{
@ -27,7 +27,7 @@
{
"name": "RAYLIB_VERSION",
"type": "STRING",
"value": "5.1-dev",
"value": "5.5",
"description": ""
},
{
@ -7183,6 +7183,21 @@
}
]
},
{
"name": "ImageFromChannel",
"description": "Create an image from a selected channel of another image (GRAYSCALE)",
"returnType": "Image",
"params": [
{
"type": "Image",
"name": "image"
},
{
"type": "int",
"name": "selectedChannel"
}
]
},
{
"name": "ImageText",
"description": "Create an image from text (default font)",

View file

@ -15,7 +15,7 @@ return {
{
name = "RAYLIB_VERSION_MINOR",
type = "INT",
value = 1,
value = 5,
description = ""
},
{
@ -27,7 +27,7 @@ return {
{
name = "RAYLIB_VERSION",
type = "STRING",
value = "5.1-dev",
value = "5.5",
description = ""
},
{
@ -5521,6 +5521,15 @@ return {
{type = "Rectangle", name = "rec"}
}
},
{
name = "ImageFromChannel",
description = "Create an image from a selected channel of another image (GRAYSCALE)",
returnType = "Image",
params = {
{type = "Image", name = "image"},
{type = "int", name = "selectedChannel"}
}
},
{
name = "ImageText",
description = "Create an image from text (default font)",

File diff suppressed because it is too large Load diff

View file

@ -3,9 +3,9 @@
<Defines count="57">
<Define name="RAYLIB_H" type="GUARD" value="" desc="" />
<Define name="RAYLIB_VERSION_MAJOR" type="INT" value="5" desc="" />
<Define name="RAYLIB_VERSION_MINOR" type="INT" value="1" desc="" />
<Define name="RAYLIB_VERSION_MINOR" type="INT" value="5" desc="" />
<Define name="RAYLIB_VERSION_PATCH" type="INT" value="0" desc="" />
<Define name="RAYLIB_VERSION" type="STRING" value="5.1-dev" desc="" />
<Define name="RAYLIB_VERSION" type="STRING" value="5.5" desc="" />
<Define name="__declspec(x)" type="MACRO" value="__attribute__((x))" desc="" />
<Define name="RLAPI" type="UNKNOWN" value="__declspec(dllexport)" desc="We are building the library as a Win32 shared library (.dll)" />
<Define name="PI" type="FLOAT" value="3.14159265358979323846" desc="" />
@ -670,7 +670,7 @@
<Param type="unsigned int" name="frames" desc="" />
</Callback>
</Callbacks>
<Functions count="572">
<Functions count="573">
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
@ -1798,6 +1798,10 @@
<Param type="Image" name="image" desc="" />
<Param type="Rectangle" name="rec" desc="" />
</Function>
<Function name="ImageFromChannel" retType="Image" paramCount="2" desc="Create an image from a selected channel of another image (GRAYSCALE)">
<Param type="Image" name="image" desc="" />
<Param type="int" name="selectedChannel" desc="" />
</Function>
<Function name="ImageText" retType="Image" paramCount="3" desc="Create an image from text (default font)">
<Param type="const char *" name="text" desc="" />
<Param type="int" name="fontSize" desc="" />

View file

@ -5,7 +5,7 @@ project(example)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Dependencies
set(RAYLIB_VERSION 5.0)
set(RAYLIB_VERSION 5.5)
find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED
if (NOT raylib_FOUND) # If there's none, fetch and build raylib
include(FetchContent)

View file

@ -1,7 +1,7 @@
# Setup the project and settings
project(raylib C)
set(PROJECT_VERSION 5.0.0)
set(API_VERSION 500)
set(PROJECT_VERSION 5.5.0)
set(API_VERSION 550)
include(GNUInstallDirs)
include(JoinPaths)

View file

@ -4,7 +4,9 @@
#
# This file supports building raylib library for the following platforms:
#
# > PLATFORM_DESKTOP (GLFW backend):
# > PLATFORM_DESKTOP
# - Defaults to PLATFORM_DESKTOP_GLFW
# > PLATFORM_DESKTOP_GLFW (GLFW backend):
# - Windows (Win32, Win64)
# - Linux (X11/Wayland desktop mode)
# - macOS/OSX (x64, arm64)
@ -55,12 +57,18 @@
# Define required environment variables
#------------------------------------------------------------------------------------------------
# Define target platform: PLATFORM_DESKTOP, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB
# Define target platform
PLATFORM ?= PLATFORM_DESKTOP
ifeq ($(PLATFORM), PLATFORM_DESKTOP)
TARGET_PLATFORM = PLATFORM_DESKTOP_GLFW
else
TARGET_PLATFORM = $(PLATFORM)
endif
# Define required raylib variables
RAYLIB_VERSION = 5.0.0
RAYLIB_API_VERSION = 500
RAYLIB_VERSION = 5.5.0
RAYLIB_API_VERSION = 550
# Define raylib source code path
RAYLIB_SRC_PATH ?= ../src
@ -119,7 +127,7 @@ HOST_PLATFORM_OS ?= WINDOWS
PLATFORM_OS ?= WINDOWS
# Determine PLATFORM_OS when required
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_DESKTOP_SDL PLATFORM_WEB PLATFORM_ANDROID PLATFORM_DESKTOP_RGFW))
ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW PLATFORM_DESKTOP_SDL PLATFORM_DESKTOP_RGFW PLATFORM_WEB PLATFORM_ANDROID))
# No uname.exe on MinGW!, but OS=Windows_NT on Windows!
# ifeq ($(UNAME),Msys) -> Windows
ifeq ($(OS),Windows_NT)
@ -152,7 +160,7 @@ ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_DESKTOP_SDL PLA
endif
endif
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
UNAMEOS = $(shell uname)
ifeq ($(UNAMEOS),Linux)
PLATFORM_OS = LINUX
@ -161,7 +169,7 @@ ifeq ($(PLATFORM),PLATFORM_DRM)
PLATFORM_SHELL = sh
endif
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
ifeq ($(PLATFORM_OS),LINUX)
ifndef PLATFORM_SHELL
PLATFORM_SHELL = sh
@ -169,7 +177,7 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
endif
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
ifeq ($(PLATFORM_OS), WINDOWS)
# Emscripten required variables
EMSDK_PATH ?= C:/emsdk
@ -181,7 +189,7 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
endif
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
# Android architecture
# Starting at 2019 using arm64 is mandatory for published apps,
# Starting on August 2020, minimum required target API is Android 10 (API level 29)
@ -221,7 +229,7 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
endif
# Define raylib graphics api depending on selected platform
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
# By default use OpenGL 3.3 on desktop platforms
GRAPHICS ?= GRAPHICS_API_OPENGL_33
#GRAPHICS = GRAPHICS_API_OPENGL_11 # Uncomment to use OpenGL 1.1
@ -229,28 +237,28 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
#GRAPHICS = GRAPHICS_API_OPENGL_43 # Uncomment to use OpenGL 4.3
#GRAPHICS = GRAPHICS_API_OPENGL_ES2 # Uncomment to use OpenGL ES 2.0 (ANGLE)
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_RGFW)
# By default use OpenGL 3.3 on desktop platforms
GRAPHICS ?= GRAPHICS_API_OPENGL_33
#GRAPHICS = GRAPHICS_API_OPENGL_11 # Uncomment to use OpenGL 1.1
#GRAPHICS = GRAPHICS_API_OPENGL_21 # Uncomment to use OpenGL 2.1
#GRAPHICS = GRAPHICS_API_OPENGL_43 # Uncomment to use OpenGL 4.3
#GRAPHICS = GRAPHICS_API_OPENGL_ES2 # Uncomment to use OpenGL ES 2.0 (ANGLE)
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_SDL)
# By default use OpenGL 3.3 on desktop platform with SDL backend
GRAPHICS ?= GRAPHICS_API_OPENGL_33
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_RGFW)
# By default use OpenGL 3.3 on desktop platforms
GRAPHICS ?= GRAPHICS_API_OPENGL_33
#GRAPHICS = GRAPHICS_API_OPENGL_11 # Uncomment to use OpenGL 1.1
#GRAPHICS = GRAPHICS_API_OPENGL_21 # Uncomment to use OpenGL 2.1
#GRAPHICS = GRAPHICS_API_OPENGL_43 # Uncomment to use OpenGL 4.3
#GRAPHICS = GRAPHICS_API_OPENGL_ES2 # Uncomment to use OpenGL ES 2.0 (ANGLE)
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
# On DRM OpenGL ES 2.0 must be used
GRAPHICS = GRAPHICS_API_OPENGL_ES2
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
# On HTML5 OpenGL ES 2.0 is used, emscripten translates it to WebGL 1.0
GRAPHICS = GRAPHICS_API_OPENGL_ES2
#GRAPHICS = GRAPHICS_API_OPENGL_ES3 # Uncomment to use ES3/WebGL2 (preliminary support).
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
# By default use OpenGL ES 2.0 on Android
GRAPHICS = GRAPHICS_API_OPENGL_ES2
endif
@ -260,7 +268,7 @@ endif
CC = gcc
AR = ar
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),OSX)
# OSX default compiler
CC = clang
@ -271,7 +279,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
CC = clang
endif
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
# Define RPI cross-compiler
#CC = armv6j-hardfloat-linux-gnueabi-gcc
@ -279,12 +287,12 @@ ifeq ($(PLATFORM),PLATFORM_DRM)
AR = $(RPI_TOOLCHAIN)/bin/$(RPI_TOOLCHAIN_NAME)-ar
endif
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
# HTML5 emscripten compiler
CC = emcc
AR = emar
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
# Android toolchain (must be provided for desired architecture and compiler)
ifeq ($(ANDROID_ARCH),arm)
CC = $(ANDROID_TOOLCHAIN)/bin/$(ANDROID_COMPILER_ARCH)-linux-androideabi$(ANDROID_API_VERSION)-clang
@ -316,13 +324,13 @@ endif
# -D_GNU_SOURCE access to lots of nonstandard GNU/Linux extension functions
# -Werror=pointer-arith catch unportable code that does direct arithmetic on void pointers
# -fno-strict-aliasing jar_xm.h does shady stuff (breaks strict aliasing)
CFLAGS = -Wall -D_GNU_SOURCE -D$(PLATFORM) -D$(GRAPHICS) -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing
CFLAGS = -Wall -D_GNU_SOURCE -D$(TARGET_PLATFORM) -D$(GRAPHICS) -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing
ifneq ($(RAYLIB_CONFIG_FLAGS), NONE)
CFLAGS += -DEXTERNAL_CONFIG_FLAGS $(RAYLIB_CONFIG_FLAGS)
endif
ifeq ($(PLATFORM), PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM), PLATFORM_WEB)
# NOTE: When using multi-threading in the user code, it requires -pthread enabled
CFLAGS += -std=gnu99
else
@ -338,13 +346,13 @@ ifeq ($(RAYLIB_BUILD_MODE),DEBUG)
endif
ifeq ($(RAYLIB_BUILD_MODE),RELEASE)
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
CFLAGS += -Os
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
CFLAGS += -O1
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
CFLAGS += -O2
endif
endif
@ -354,10 +362,10 @@ endif
# -Wmissing-prototypes warn if a global function is defined without a previous prototype declaration
# -Wstrict-prototypes warn if a function is declared or defined without specifying the argument types
# -Werror=implicit-function-declaration catch function calls without prior declaration
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
CFLAGS += -Werror=implicit-function-declaration
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
# -Os # size optimization
# -O2 # optimization level 2, if used, also set --memory-init-file 0
# -sUSE_GLFW=3 # Use glfw3 library (context/input management) -> Only for linker!
@ -375,7 +383,7 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
endif
#CFLAGS += -sGL_ENABLE_GET_PROC_ADDRESS
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
# Compiler flags for arquitecture
ifeq ($(ANDROID_ARCH),arm)
CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
@ -411,19 +419,18 @@ ifeq ($(RAYLIB_LIBTYPE),SHARED)
endif
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
# without EGL_NO_X11 eglplatform.h tears Xlib.h in which tears X.h in
# which contains a conflicting type Font
CFLAGS += -DEGL_NO_X11
CFLAGS += -Werror=implicit-function-declaration
endif
# Use Wayland display on Linux desktop
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS), LINUX)
ifeq ($(GLFW_LINUX_ENABLE_X11),TRUE)
CFLAGS += -D_GLFW_X11
endif
ifeq ($(GLFW_LINUX_ENABLE_WAYLAND),TRUE)
CFLAGS += -D_GLFW_WAYLAND
LDFLAGS += $(shell pkg-config wayland-client wayland-cursor wayland-egl xkbcommon --libs)
@ -457,26 +464,26 @@ CFLAGS += $(CUSTOM_CFLAGS)
INCLUDE_PATHS = -I.
# Define additional directories containing required header files
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
INCLUDE_PATHS += -Iexternal/glfw/include
ifeq ($(PLATFORM_OS),BSD)
INCLUDE_PATHS += -I/usr/local/include
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_SDL)
INCLUDE_PATHS += -I$(SDL_INCLUDE_PATH)
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
INCLUDE_PATHS += -Iexternal/glfw/include
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
INCLUDE_PATHS += -I/usr/include/libdrm
ifeq ($(USE_RPI_CROSSCOMPILER), TRUE)
INCLUDE_PATHS += -I$(RPI_TOOLCHAIN_SYSROOT)/usr/include
INCLUDE_PATHS += -I$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/include
endif
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
NATIVE_APP_GLUE = $(ANDROID_NDK)/sources/android/native_app_glue
# Include android_native_app_glue.h
INCLUDE_PATHS += -I$(NATIVE_APP_GLUE)
@ -502,7 +509,7 @@ endif
#------------------------------------------------------------------------------------------------
LDFLAGS = $(CUSTOM_LDFLAGS) -L. -L$(RAYLIB_RELEASE_PATH)
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),WINDOWS)
ifneq ($(CC), tcc)
LDFLAGS += -Wl,--out-implib,$(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME)dll.a
@ -518,17 +525,17 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
LDFLAGS += -Wl,-soname,lib$(RAYLIB_LIB_NAME).$(RAYLIB_API_VERSION).so -Lsrc -L/usr/local/lib
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_SDL)
LDFLAGS += -Wl,-soname,lib$(RAYLIB_LIB_NAME).so.$(RAYLIB_API_VERSION)
LDFLAGS += -L$(SDL_LIBRARY_PATH)
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
LDFLAGS += -Wl,-soname,lib$(RAYLIB_LIB_NAME).so.$(RAYLIB_API_VERSION)
ifeq ($(USE_RPI_CROSSCOMPILER), TRUE)
LDFLAGS += -L$(RPI_TOOLCHAIN_SYSROOT)/opt/vc/lib -L$(RPI_TOOLCHAIN_SYSROOT)/usr/lib
endif
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
LDFLAGS += -Wl,-soname,libraylib.$(RAYLIB_API_VERSION).so -Wl,--exclude-libs,libatomic.a
LDFLAGS += -Wl,--build-id -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings
# Force linking of library module to define symbol
@ -542,7 +549,7 @@ endif
# Define libraries required on linking: LDLIBS
# NOTE: This is only required for dynamic library generation
#------------------------------------------------------------------------------------------------
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),WINDOWS)
ifeq ($(CC), tcc)
LDLIBS = -lopengl32 -lgdi32 -lwinmm -lshell32
@ -570,7 +577,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
LDLIBS = -lglfw
endif
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_SDL)
ifeq ($(PLATFORM_OS),WINDOWS)
LDLIBS = -static-libgcc -lopengl32 -lgdi32
endif
@ -582,16 +589,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP_SDL)
endif
LDLIBS += -lSDL2 -lSDL2main
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
LDLIBS = -lGLESv2 -lEGL -ldrm -lgbm -lpthread -lrt -lm -ldl
ifeq ($(RAYLIB_MODULE_AUDIO),TRUE)
LDLIBS += -latomic
endif
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
LDLIBS = -llog -landroid -lEGL -lGLESv2 -lOpenSLES -lc -lm
endif
ifeq ($(PLATFORM),PLATFORM_DESKTOP_RGFW)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_RGFW)
ifeq ($(PLATFORM_OS),WINDOWS)
# Libraries for Windows desktop compilation
LDLIBS = -lgdi32 -lwinmm -lopengl32
@ -615,6 +613,15 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP_RGFW)
LDLIBS += -lm -framework Foundation -framework AppKit -framework OpenGL -framework CoreVideo
endif
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
LDLIBS = -lGLESv2 -lEGL -ldrm -lgbm -lpthread -lrt -lm -ldl
ifeq ($(RAYLIB_MODULE_AUDIO),TRUE)
LDLIBS += -latomic
endif
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
LDLIBS = -llog -landroid -lEGL -lGLESv2 -lOpenSLES -lc -lm
endif
# Define source code object files required
#------------------------------------------------------------------------------------------------
@ -624,8 +631,7 @@ OBJS = rcore.o \
rtext.o \
utils.o
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(USE_EXTERNAL_GLFW),FALSE)
OBJS += rglfw.o
endif
@ -640,7 +646,7 @@ ifeq ($(RAYLIB_MODULE_RAYGUI),TRUE)
OBJS += raygui.o
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
OBJS += android_native_app_glue.o
endif
@ -652,14 +658,14 @@ all: raylib
# Compile raylib library
# NOTE: Release directory is created if not exist
raylib: $(OBJS)
ifeq ($(PLATFORM),PLATFORM_WEB)
ifeq ($(TARGET_PLATFORM),PLATFORM_WEB)
# Compile raylib libray for web
#$(CC) $(OBJS) -r -o $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).bc
$(AR) rcs $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).a $(OBJS)
@echo "raylib library generated (lib$(RAYLIB_LIB_NAME).a)!"
else
ifeq ($(RAYLIB_LIBTYPE),SHARED)
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_DESKTOP_SDL PLATFORM_DESKTOP_RGFW))
ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW PLATFORM_DESKTOP_SDL PLATFORM_DESKTOP_RGFW))
ifeq ($(PLATFORM_OS),WINDOWS)
# NOTE: Linking with provided resource file
$(CC) -shared -o $(RAYLIB_RELEASE_PATH)/$(RAYLIB_LIB_NAME).dll $(OBJS) $(RAYLIB_RES_FILE) $(LDFLAGS) $(LDLIBS)
@ -688,7 +694,7 @@ else
cd $(RAYLIB_RELEASE_PATH) && ln -fs lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).so lib$(RAYLIB_LIB_NAME).so
endif
endif
ifeq ($(PLATFORM),PLATFORM_DRM)
ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
# Compile raylib shared library version $(RAYLIB_VERSION).
# WARNING: you should type "make clean" before doing this target
$(CC) -shared -o $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).so.$(RAYLIB_VERSION) $(OBJS) $(LDFLAGS) $(LDLIBS)
@ -696,7 +702,7 @@ else
cd $(RAYLIB_RELEASE_PATH) && ln -fsv lib$(RAYLIB_LIB_NAME).so.$(RAYLIB_VERSION) lib$(RAYLIB_LIB_NAME).so.$(RAYLIB_API_VERSION)
cd $(RAYLIB_RELEASE_PATH) && ln -fsv lib$(RAYLIB_LIB_NAME).so.$(RAYLIB_API_VERSION) lib$(RAYLIB_LIB_NAME).so
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
$(CC) -shared -o $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).so $(OBJS) $(LDFLAGS) $(LDLIBS)
@echo "raylib shared library generated (lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).so)!"
# WARNING: symbolic links creation on Windows should be done using mklink command, no ln available
@ -851,7 +857,7 @@ clean: clean_shell_$(PLATFORM_SHELL)
clean_shell_sh:
rm -fv *.o $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).a $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).bc $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).so* raygui.c $(RAYLIB_RELEASE_PATH)/*-protocol.h $(RAYLIB_RELEASE_PATH)/*-protocol-code.h
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
rm -fv $(NATIVE_APP_GLUE)/android_native_app_glue.o
endif

View file

@ -207,15 +207,9 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
const cache_include = std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" }) catch @panic("Out of memory");
defer b.allocator.free(cache_include);
if (comptime builtin.zig_version.minor > 12) {
var dir = std.fs.cwd().openDir(cache_include, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!");
dir.close();
raylib.addIncludePath(b.path(cache_include));
} else {
var dir = std.fs.openDirAbsolute(cache_include, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!");
dir.close();
raylib.addIncludePath(.{ .path = cache_include });
}
var dir = std.fs.openDirAbsolute(cache_include, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!");
dir.close();
raylib.addIncludePath(.{ .cwd_relative = cache_include });
},
else => {
@panic("Unsupported OS");

View file

@ -81,7 +81,7 @@ static PlatformData platform = { 0 }; // Platform specific data
// Local Variables Definition
//----------------------------------------------------------------------------------
#define KEYCODE_MAP_SIZE 162
static const KeyboardKey KeycodeMap[KEYCODE_MAP_SIZE] = {
static const KeyboardKey mapKeycode[KEYCODE_MAP_SIZE] = {
KEY_NULL, // AKEYCODE_UNKNOWN
0, // AKEYCODE_SOFT_LEFT
0, // AKEYCODE_SOFT_RIGHT
@ -660,7 +660,7 @@ void PollInputEvents(void)
CORE.Input.Gamepad.previousButtonState[i][k] = CORE.Input.Gamepad.currentButtonState[i][k];
}
}
// Register previous touch states
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
@ -1133,9 +1133,9 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
CORE.Input.Gamepad.axisState[0][GAMEPAD_AXIS_RIGHT_Y] = AMotionEvent_getAxisValue(
event, AMOTION_EVENT_AXIS_RZ, 0);
CORE.Input.Gamepad.axisState[0][GAMEPAD_AXIS_LEFT_TRIGGER] = AMotionEvent_getAxisValue(
event, AMOTION_EVENT_AXIS_BRAKE, 0) * 2.0f - 1.0f;
event, AMOTION_EVENT_AXIS_BRAKE, 0)*2.0f - 1.0f;
CORE.Input.Gamepad.axisState[0][GAMEPAD_AXIS_RIGHT_TRIGGER] = AMotionEvent_getAxisValue(
event, AMOTION_EVENT_AXIS_GAS, 0) * 2.0f - 1.0f;
event, AMOTION_EVENT_AXIS_GAS, 0)*2.0f - 1.0f;
// dpad is reported as an axis on android
float dpadX = AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_HAT_X, 0);
@ -1201,7 +1201,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
return 1; // Handled gamepad button
}
KeyboardKey key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : KEY_NULL;
KeyboardKey key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE)? mapKeycode[keycode] : KEY_NULL;
if (key != KEY_NULL)
{
// Save current key and its state
@ -1252,10 +1252,10 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
CORE.Input.Touch.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) };
// Normalize CORE.Input.Touch.position[i] for CORE.Window.screen.width and CORE.Window.screen.height
float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x) / (float)CORE.Window.display.width;
float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y) / (float)CORE.Window.display.height;
CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x * widthRatio - (float)CORE.Window.renderOffset.x / 2;
CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y * heightRatio - (float)CORE.Window.renderOffset.y / 2;
float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x)/(float)CORE.Window.display.width;
float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y)/(float)CORE.Window.display.height;
CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x*widthRatio - (float)CORE.Window.renderOffset.x/2;
CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y*heightRatio - (float)CORE.Window.renderOffset.y/2;
}
int32_t action = AMotionEvent_getAction(event);

File diff suppressed because it is too large Load diff

View file

@ -104,9 +104,7 @@ __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int CodePage,
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef struct {
// TODO: Define the platform specific variables required
RGFW_window* window; // Native display device (physical screen connection)
RGFW_window *window; // Native display device (physical screen connection)
} PlatformData;
//----------------------------------------------------------------------------------
@ -114,9 +112,9 @@ typedef struct {
//----------------------------------------------------------------------------------
extern CoreData CORE; // Global CORE state context
static PlatformData platform = { NULL }; // Platform specific
static PlatformData platform = { NULL }; // Platform specific
static const unsigned short RGFWKeyToRayKey[] = {
static const unsigned short keyMappingRGFW[] = {
[RGFW_KEY_NULL] = KEY_NULL,
[RGFW_Quote] = KEY_APOSTROPHE,
[RGFW_Comma] = KEY_COMMA,
@ -157,7 +155,7 @@ static const unsigned short RGFWKeyToRayKey[] = {
[RGFW_SuperL] = KEY_LEFT_SUPER,
#ifndef RGFW_MACOS
[RGFW_ShiftR] = KEY_RIGHT_SHIFT,
[RGFW_AltR] = KEY_RIGHT_ALT,
#endif
[RGFW_Space] = KEY_SPACE,
@ -237,7 +235,7 @@ bool InitGraphicsDevice(void); // Initialize graphics device
// Check if application should close
bool WindowShouldClose(void)
{
{
if (CORE.Window.shouldClose == false)
CORE.Window.shouldClose = RGFW_window_shouldClose(platform.window);
if (CORE.Window.ready) return CORE.Window.shouldClose;
@ -246,7 +244,7 @@ bool WindowShouldClose(void)
// Toggle fullscreen mode
void ToggleFullscreen(void)
{
{
RGFW_window_maximize(platform.window);
ToggleBorderlessWindowed();
}
@ -255,7 +253,7 @@ void ToggleFullscreen(void)
void ToggleBorderlessWindowed(void)
{
CORE.Window.flags & FLAG_WINDOW_UNDECORATED;
if (platform.window != NULL)
TRACELOG(LOG_WARNING, "ToggleBorderlessWindowed() after window creation not available on target platform");
}
@ -430,33 +428,34 @@ void ClearWindowState(unsigned int flags)
// Set icon for window
void SetWindowIcon(Image image)
{
i32 channels = 4;
i32 channels = 4;
switch (image.format) {
switch (image.format)
{
case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE:
case PIXELFORMAT_UNCOMPRESSED_R16: // 16 bpp (1 channel - half float)
case PIXELFORMAT_UNCOMPRESSED_R32: // 32 bpp (1 channel - float)
{
channels = 1;
break;
} break;
case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: // 8*2 bpp (2 channels)
case PIXELFORMAT_UNCOMPRESSED_R5G6B5: // 16 bpp
case PIXELFORMAT_UNCOMPRESSED_R8G8B8: // 24 bpp
case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: // 16 bpp (1 bit alpha)
case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: // 16 bpp (4 bit alpha)
case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: // 32 bpp
{
channels = 2;
break;
} break;
case PIXELFORMAT_UNCOMPRESSED_R32G32B32: // 32*3 bpp (3 channels - float)
case PIXELFORMAT_UNCOMPRESSED_R16G16B16: // 16*3 bpp (3 channels - half float)
case PIXELFORMAT_COMPRESSED_DXT1_RGB: // 4 bpp (no alpha)
case PIXELFORMAT_COMPRESSED_ETC1_RGB: // 4 bpp
case PIXELFORMAT_COMPRESSED_ETC2_RGB: // 4 bpp
case PIXELFORMAT_COMPRESSED_PVRT_RGB: // 4 bpp
{
channels = 3;
break;
} break;
case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: // 32*4 bpp (4 channels - float)
case PIXELFORMAT_UNCOMPRESSED_R16G16B16A16: // 16*4 bpp (4 channels - half float)
case PIXELFORMAT_COMPRESSED_DXT1_RGBA: // 4 bpp (1 bit alpha)
@ -465,10 +464,10 @@ void SetWindowIcon(Image image)
case PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA: // 8 bpp
case PIXELFORMAT_COMPRESSED_PVRT_RGBA: // 4 bpp
case PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA: // 8 bpp
case PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: // 2 bpp
case PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: // 2 bpp
{
channels = 4;
break;
} break;
default: break;
}
@ -537,65 +536,70 @@ void SetWindowFocused(void)
// Get native window handle
void *GetWindowHandle(void)
{
#ifndef RGFW_WINDOWS
return (void*)platform.window->src.window;
#else
#ifndef RGFW_WINDOWS
return (void *)platform.window->src.window;
#else
return platform.window->src.hwnd;
#endif
#endif
}
// Get number of monitors
int GetMonitorCount(void)
{
RGFW_monitor* mons = RGFW_getMonitors();
size_t i;
for (i = 0; i < 6; i++) {
#define MAX_MONITORS_SUPPORTED 6
int count = MAX_MONITORS_SUPPORTED;
RGFW_monitor *mons = RGFW_getMonitors();
for (int i = 0; i < 6; i++)
{
if (!mons[i].rect.x && !mons[i].rect.y && !mons[i].rect.w && mons[i].rect.h)
return i;
{
count = i;
break;
}
}
return 6;
return count;
}
// Get number of monitors
int GetCurrentMonitor(void)
{
RGFW_monitor* mons = RGFW_getMonitors();
int current = 0;
RGFW_monitor *mons = RGFW_getMonitors();
RGFW_monitor mon = RGFW_window_getMonitor(platform.window);
size_t i;
for (i = 0; i < 6; i++) {
if (mons[i].rect.x == mon.rect.x &&
mons[i].rect.y == mon.rect.y)
return i;
for (int i = 0; i < 6; i++)
{
if ((mons[i].rect.x == mon.rect.x) && (mons[i].rect.y == mon.rect.y)) current = i;
}
return 0;
return current;
}
// Get selected monitor position
Vector2 GetMonitorPosition(int monitor)
{
RGFW_monitor* mons = RGFW_getMonitors();
RGFW_monitor *mons = RGFW_getMonitors();
return (Vector2){mons[monitor].rect.x, mons[monitor].rect.y};
return (Vector2){mons[monitor].rect.x, mons[monitor].rect.y};
}
// Get selected monitor width (currently used by monitor)
int GetMonitorWidth(int monitor)
{
RGFW_monitor* mons = RGFW_getMonitors();
RGFW_monitor *mons = RGFW_getMonitors();
return mons[monitor].rect.w;
return mons[monitor].rect.w;
}
// Get selected monitor height (currently used by monitor)
int GetMonitorHeight(int monitor)
{
RGFW_monitor* mons = RGFW_getMonitors();
RGFW_monitor *mons = RGFW_getMonitors();
return mons[monitor].rect.h;
return 0;
return mons[monitor].rect.h;
}
// Get selected monitor physical width in millimetres
@ -603,15 +607,15 @@ int GetMonitorPhysicalWidth(int monitor)
{
RGFW_monitor* mons = RGFW_getMonitors();
return mons[monitor].physW;
return mons[monitor].physW;
}
// Get selected monitor physical height in millimetres
int GetMonitorPhysicalHeight(int monitor)
{
RGFW_monitor* mons = RGFW_getMonitors();
RGFW_monitor *mons = RGFW_getMonitors();
return mons[monitor].physH;
return mons[monitor].physH;
}
// Get selected monitor refresh rate
@ -624,7 +628,7 @@ int GetMonitorRefreshRate(int monitor)
// Get the human-readable, UTF-8 encoded name of the selected monitor
const char *GetMonitorName(int monitor)
{
RGFW_monitor* mons = RGFW_getMonitors();
RGFW_monitor *mons = RGFW_getMonitors();
return mons[monitor].name;
}
@ -640,7 +644,7 @@ Vector2 GetWindowScaleDPI(void)
{
RGFW_monitor monitor = RGFW_window_getMonitor(platform.window);
return (Vector2){((u32)monitor.scaleX) * platform.window->r.w, ((u32) monitor.scaleX) * platform.window->r.h};
return (Vector2){((u32)monitor.scaleX)*platform.window->r.w, ((u32) monitor.scaleX)*platform.window->r.h};
}
// Set clipboard text content
@ -757,7 +761,7 @@ void SetMouseCursor(int cursor)
static KeyboardKey ConvertScancodeToKey(u32 keycode);
// Register all input events
void PollInputEvents(void)
void PollInputEvents(void)
{
#if defined(SUPPORT_GESTURES_SYSTEM)
// NOTE: Gestures update must be called every frame to reset gestures correctly
@ -774,7 +778,7 @@ void PollInputEvents(void)
CORE.Input.Mouse.currentWheelMove.y = 0;
// Register previous mouse position
// Reset last gamepad button/axis registered state
for (int i = 0; (i < 4) && (i < MAX_GAMEPADS); i++)
@ -808,7 +812,7 @@ void PollInputEvents(void)
}
// Register previous mouse states
for (int i = 0; i < MAX_MOUSE_BUTTONS; i++)
for (int i = 0; i < MAX_MOUSE_BUTTONS; i++)
CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
// Poll input events for current platform
@ -818,7 +822,7 @@ void PollInputEvents(void)
#define RGFW_HOLD_MOUSE (1L<<2)
#if defined(RGFW_X11) //|| defined(RGFW_MACOS)
if (platform.window->src.winArgs & RGFW_HOLD_MOUSE)
if (platform.window->src.winArgs & RGFW_HOLD_MOUSE)
{
CORE.Input.Mouse.previousPosition = (Vector2){ 0.0f, 0.0f };
CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f };
@ -831,7 +835,8 @@ void PollInputEvents(void)
while (RGFW_window_checkEvent(platform.window))
{
if (platform.window->event.type >= RGFW_jsButtonPressed && platform.window->event.type <= RGFW_jsAxisMove) {
if ((platform.window->event.type >= RGFW_jsButtonPressed) && (platform.window->event.type <= RGFW_jsAxisMove))
{
if (!CORE.Input.Gamepad.ready[platform.window->event.joystick])
{
CORE.Input.Gamepad.ready[platform.window->event.joystick] = true;
@ -848,11 +853,10 @@ void PollInputEvents(void)
switch (event->type)
{
case RGFW_quit: CORE.Window.shouldClose = true; break;
case RGFW_dnd: // Dropped file
{
size_t i;
for (i = 0; i < event->droppedFilesCount; i++) {
for (int i = 0; i < event->droppedFilesCount; i++)
{
if (CORE.Window.dropFileCount == 0)
{
// When a new file is dropped, we reserve a fixed number of slots for all possible dropped files
@ -862,7 +866,7 @@ void PollInputEvents(void)
CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event->droppedFiles[i]);
CORE.Window.dropFileCount++;
}
else if (CORE.Window.dropFileCount < 1024)
@ -896,8 +900,9 @@ void PollInputEvents(void)
case RGFW_keyPressed:
{
KeyboardKey key = ConvertScancodeToKey(event->keyCode);
if (key != KEY_NULL) {
if (key != KEY_NULL)
{
// If key was up, add it to the key pressed queue
if ((CORE.Input.Keyboard.currentKeyState[key] == 0) && (CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE))
{
@ -923,7 +928,6 @@ void PollInputEvents(void)
CORE.Input.Keyboard.charPressedQueueCount++;
}
} break;
case RGFW_keyReleased:
{
KeyboardKey key = ConvertScancodeToKey(event->keyCode);
@ -933,7 +937,8 @@ void PollInputEvents(void)
// Check mouse events
case RGFW_mouseButtonPressed:
{
if (event->button == RGFW_mouseScrollUp || event->button == RGFW_mouseScrollDown) {
if ((event->button == RGFW_mouseScrollUp) || (event->button == RGFW_mouseScrollDown))
{
CORE.Input.Mouse.currentWheelMove.y = event->scroll;
break;
}
@ -951,11 +956,12 @@ void PollInputEvents(void)
case RGFW_mouseButtonReleased:
{
if (event->button == RGFW_mouseScrollUp || event->button == RGFW_mouseScrollDown) {
if ((event->button == RGFW_mouseScrollUp) || (event->button == RGFW_mouseScrollDown))
{
CORE.Input.Mouse.currentWheelMove.y = event->scroll;
break;
}
int btn = event->button;
if (btn == RGFW_mouseLeft) btn = 1;
else if (btn == RGFW_mouseRight) btn = 2;
@ -968,20 +974,21 @@ void PollInputEvents(void)
} break;
case RGFW_mousePosChanged:
{
if (platform.window->src.winArgs & RGFW_HOLD_MOUSE) {
if (platform.window->src.winArgs & RGFW_HOLD_MOUSE)
{
CORE.Input.Mouse.previousPosition = (Vector2){ 0.0f, 0.0f };
if ((event->point.x - (platform.window->r.w / 2)) * 2)
CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.currentPosition.x;
if ((event->point.y - (platform.window->r.h / 2)) * 2)
if ((event->point.x - (platform.window->r.w/2))*2)
CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.currentPosition.x;
if ((event->point.y - (platform.window->r.h/2))*2)
CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.currentPosition.y;
CORE.Input.Mouse.currentPosition.x = (event->point.x - (platform.window->r.w / 2)) * 2;
CORE.Input.Mouse.currentPosition.y = (event->point.y - (platform.window->r.h / 2)) * 2;
CORE.Input.Mouse.currentPosition.x = (event->point.x - (platform.window->r.w/2))*2;
CORE.Input.Mouse.currentPosition.y = (event->point.y - (platform.window->r.h/2))*2;
}
else {
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
else
{
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
CORE.Input.Mouse.currentPosition.x = (float)event->point.x;
CORE.Input.Mouse.currentPosition.y = (float)event->point.y;
}
@ -989,7 +996,6 @@ void PollInputEvents(void)
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
touchAction = 2;
} break;
case RGFW_jsButtonPressed:
{
int button = -1;
@ -1061,41 +1067,46 @@ void PollInputEvents(void)
case RGFW_jsAxisMove:
{
int axis = -1;
size_t i;
for (i = 0; i < event->axisesCount; i++)
for (int i = 0; i < event->axisesCount; i++)
{
switch(i) {
case 0:
if (abs(event->axis[i].x) > abs(event->axis[i].y)) {
axis = GAMEPAD_AXIS_LEFT_X;
switch(i)
{
case 0:
{
if (abs(event->axis[i].x) > abs(event->axis[i].y))
{
axis = GAMEPAD_AXIS_LEFT_X;
break;
}
axis = GAMEPAD_AXIS_LEFT_Y;
break;
case 1:
if (abs(event->axis[i].x) > abs(event->axis[i].y)) {
axis = GAMEPAD_AXIS_RIGHT_X; break;
} break;
case 1:
{
if (abs(event->axis[i].x) > abs(event->axis[i].y))
{
axis = GAMEPAD_AXIS_RIGHT_X;
break;
}
axis = GAMEPAD_AXIS_RIGHT_Y; break;
axis = GAMEPAD_AXIS_RIGHT_Y;
} break;
case 2: axis = GAMEPAD_AXIS_LEFT_TRIGGER; break;
case 3: axis = GAMEPAD_AXIS_RIGHT_TRIGGER; break;
default: break;
}
#ifdef __linux__
float value = (event->axis[i].x + event->axis[i].y) / (float) 32767;
float value = (event->axis[i].x + event->axis[i].y)/(float)32767;
#else
float value = (event->axis[i].x + -event->axis[i].y) / (float) 32767;
float value = (event->axis[i].x + -event->axis[i].y)/(float)32767;
#endif
CORE.Input.Gamepad.axisState[event->joystick][axis] = value;
// Register button state for triggers in addition to their axes
if ((axis == GAMEPAD_AXIS_LEFT_TRIGGER) || (axis == GAMEPAD_AXIS_RIGHT_TRIGGER))
{
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER) ? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
int pressed = (value > 0.1f);
CORE.Input.Gamepad.currentButtonState[event->joystick][button] = pressed;
if (pressed) CORE.Input.Gamepad.lastButtonPressed = button;
@ -1137,9 +1148,7 @@ void PollInputEvents(void)
#endif
}
if (RGFW_disableCursor && platform.window->event.inFocus)
RGFW_window_mouseHold(platform.window, RGFW_AREA(0, 0));
if (RGFW_disableCursor && platform.window->event.inFocus) RGFW_window_mouseHold(platform.window, RGFW_AREA(0, 0));
//-----------------------------------------------------------------------------
}
@ -1151,15 +1160,7 @@ void PollInputEvents(void)
// Initialize platform: graphics, inputs and more
int InitPlatform(void)
{
// TODO: Initialize graphic device: display/window
// It usually requires setting up the platform display system configuration
// and connexion with the GPU through some system graphic API
// raylib uses OpenGL so, platform should create that kind of connection
// Below example illustrates that process using EGL library
//----------------------------------------------------------------------------
// Initialize RGFW internal global state, only required systems
// Initialize graphic device: display/window and graphic context
//----------------------------------------------------------------------------
unsigned int flags = RGFW_CENTER | RGFW_ALLOW_DND;
// Check window creation flags
@ -1201,14 +1202,14 @@ int InitPlatform(void)
if (CORE.Window.flags & FLAG_VSYNC_HINT)
RGFW_window_swapInterval(platform.window, 1);
RGFW_window_makeCurrent(platform.window);
// Check surface and context activation
if (platform.window != NULL)
{
CORE.Window.ready = true;
CORE.Window.render.width = CORE.Window.screen.width;
CORE.Window.render.height = CORE.Window.screen.height;
CORE.Window.currentFbo.width = CORE.Window.render.width;
@ -1241,7 +1242,7 @@ int InitPlatform(void)
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
// TODO: Load OpenGL extensions
// Load OpenGL extensions
// NOTE: GL procedures address loader is required to load extensions
//----------------------------------------------------------------------------
rlLoadExtensions((void*)RGFW_getProcAddress);
@ -1255,12 +1256,12 @@ int InitPlatform(void)
// ...
//----------------------------------------------------------------------------
// TODO: Initialize timing system
// Initialize timing system
//----------------------------------------------------------------------------
InitTimer();
//----------------------------------------------------------------------------
// TODO: Initialize storage system
// Initialize storage system
//----------------------------------------------------------------------------
CORE.Storage.basePath = GetWorkingDirectory();
//----------------------------------------------------------------------------
@ -1281,14 +1282,12 @@ int InitPlatform(void)
void ClosePlatform(void)
{
RGFW_window_close(platform.window);
// TODO: De-initialize graphics, inputs and more
}
// Keycode mapping
static KeyboardKey ConvertScancodeToKey(u32 keycode)
{
if (keycode > sizeof(keyMappingRGFW)/sizeof(unsigned short)) return 0;
static KeyboardKey ConvertScancodeToKey(u32 keycode) {
if (keycode > sizeof(RGFWKeyToRayKey) / sizeof(unsigned short))
return 0;
return RGFWKeyToRayKey[keycode];
return keyMappingRGFW[keycode];
}
// EOF

View file

@ -80,7 +80,7 @@ static PlatformData platform = { 0 }; // Platform specific data
// Local Variables Definition
//----------------------------------------------------------------------------------
#define SCANCODE_MAPPED_NUM 232
static const KeyboardKey ScancodeToKey[SCANCODE_MAPPED_NUM] = {
static const KeyboardKey mapScancodeToKey[SCANCODE_MAPPED_NUM] = {
KEY_NULL, // SDL_SCANCODE_UNKNOWN
0,
0,
@ -476,9 +476,9 @@ void ClearWindowState(unsigned int flags)
// Set icon for window
void SetWindowIcon(Image image)
{
SDL_Surface* iconSurface = NULL;
SDL_Surface *iconSurface = NULL;
Uint32 rmask, gmask, bmask, amask;
unsigned int rmask = 0, gmask = 0, bmask = 0, amask = 0;
int depth = 0; // Depth in bits
int pitch = 0; // Pixel spacing (pitch) in bytes
@ -492,72 +492,67 @@ void SetWindowIcon(Image image)
case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA:
rmask = 0xFF, gmask = 0xFF00;
bmask = 0, amask = 0;
depth = 16, pitch = image.width * 2;
depth = 16, pitch = image.width*2;
break;
case PIXELFORMAT_UNCOMPRESSED_R5G6B5:
rmask = 0xF800, gmask = 0x07E0;
bmask = 0x001F, amask = 0;
depth = 16, pitch = image.width * 2;
depth = 16, pitch = image.width*2;
break;
case PIXELFORMAT_UNCOMPRESSED_R8G8B8: // Uses BGR for 24-bit
rmask = 0x0000FF, gmask = 0x00FF00;
bmask = 0xFF0000, amask = 0;
depth = 24, pitch = image.width * 3;
depth = 24, pitch = image.width*3;
break;
case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
rmask = 0xF800, gmask = 0x07C0;
bmask = 0x003E, amask = 0x0001;
depth = 16, pitch = image.width * 2;
depth = 16, pitch = image.width*2;
break;
case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4:
rmask = 0xF000, gmask = 0x0F00;
bmask = 0x00F0, amask = 0x000F;
depth = 16, pitch = image.width * 2;
depth = 16, pitch = image.width*2;
break;
case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8:
rmask = 0xFF000000, gmask = 0x00FF0000;
bmask = 0x0000FF00, amask = 0x000000FF;
depth = 32, pitch = image.width * 4;
depth = 32, pitch = image.width*4;
break;
case PIXELFORMAT_UNCOMPRESSED_R32:
rmask = 0xFFFFFFFF, gmask = 0;
bmask = 0, amask = 0;
depth = 32, pitch = image.width * 4;
depth = 32, pitch = image.width*4;
break;
case PIXELFORMAT_UNCOMPRESSED_R32G32B32:
rmask = 0xFFFFFFFF, gmask = 0xFFFFFFFF;
bmask = 0xFFFFFFFF, amask = 0;
depth = 96, pitch = image.width * 12;
depth = 96, pitch = image.width*12;
break;
case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32:
rmask = 0xFFFFFFFF, gmask = 0xFFFFFFFF;
bmask = 0xFFFFFFFF, amask = 0xFFFFFFFF;
depth = 128, pitch = image.width * 16;
depth = 128, pitch = image.width*16;
break;
case PIXELFORMAT_UNCOMPRESSED_R16:
rmask = 0xFFFF, gmask = 0;
bmask = 0, amask = 0;
depth = 16, pitch = image.width * 2;
depth = 16, pitch = image.width*2;
break;
case PIXELFORMAT_UNCOMPRESSED_R16G16B16:
rmask = 0xFFFF, gmask = 0xFFFF;
bmask = 0xFFFF, amask = 0;
depth = 48, pitch = image.width * 6;
depth = 48, pitch = image.width*6;
break;
case PIXELFORMAT_UNCOMPRESSED_R16G16B16A16:
rmask = 0xFFFF, gmask = 0xFFFF;
bmask = 0xFFFF, amask = 0xFFFF;
depth = 64, pitch = image.width * 8;
depth = 64, pitch = image.width*8;
break;
default:
// Compressed formats are not supported
return;
default: return; // Compressed formats are not supported
}
iconSurface = SDL_CreateRGBSurfaceFrom(
image.data, image.width, image.height, depth, pitch,
rmask, gmask, bmask, amask
);
iconSurface = SDL_CreateRGBSurfaceFrom( image.data, image.width, image.height, depth, pitch, rmask, gmask, bmask, amask );
if (iconSurface)
{
@ -599,7 +594,7 @@ void SetWindowMonitor(int monitor)
// 1. SDL started supporting moving exclusive fullscreen windows between displays on SDL3,
// see commit https://github.com/libsdl-org/SDL/commit/3f5ef7dd422057edbcf3e736107e34be4b75d9ba
// 2. A workaround for SDL2 is leaving fullscreen, moving the window, then entering full screen again.
const bool wasFullscreen = ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) ? true : false;
const bool wasFullscreen = ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0)? true : false;
const int screenWidth = CORE.Window.screen.width;
const int screenHeight = CORE.Window.screen.height;
@ -941,11 +936,11 @@ int SetGamepadMappings(const char *mappings)
// Set gamepad vibration
void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor)
{
//Limit input values to between 0.0f and 1.0f
leftMotor = (0.0f > leftMotor) ? 0.0f : leftMotor;
rightMotor = (0.0f > rightMotor) ? 0.0f : rightMotor;
leftMotor = (1.0f < leftMotor) ? 1.0f : leftMotor;
rightMotor = (1.0f < rightMotor) ? 1.0f : rightMotor;
// Limit input values to between 0.0f and 1.0f
leftMotor = (0.0f > leftMotor)? 0.0f : leftMotor;
rightMotor = (0.0f > rightMotor)? 0.0f : rightMotor;
leftMotor = (1.0f < leftMotor)? 1.0f : leftMotor;
rightMotor = (1.0f < rightMotor)? 1.0f : rightMotor;
if (IsGamepadAvailable(gamepad))
{
@ -1132,7 +1127,8 @@ void PollInputEvents(void)
{
KeyboardKey key = ConvertScancodeToKey(event.key.keysym.scancode);
if (key != KEY_NULL) {
if (key != KEY_NULL)
{
// If key was up, add it to the key pressed queue
if ((CORE.Input.Keyboard.currentKeyState[key] == 0) && (CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE))
{
@ -1364,13 +1360,13 @@ void PollInputEvents(void)
if (axis >= 0)
{
// SDL axis value range is -32768 to 32767, we normalize it to RayLib's -1.0 to 1.0f range
float value = event.jaxis.value / (float) 32767;
float value = event.jaxis.value/(float)32767;
CORE.Input.Gamepad.axisState[event.jaxis.which][axis] = value;
// Register button state for triggers in addition to their axes
if ((axis == GAMEPAD_AXIS_LEFT_TRIGGER) || (axis == GAMEPAD_AXIS_RIGHT_TRIGGER))
{
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER) ? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
int pressed = (value > 0.1f);
CORE.Input.Gamepad.currentButtonState[event.jaxis.which][button] = pressed;
if (pressed) CORE.Input.Gamepad.lastButtonPressed = button;
@ -1553,6 +1549,7 @@ int InitPlatform(void)
for (int i = 0; (i < SDL_NumJoysticks()) && (i < MAX_GAMEPADS); i++)
{
platform.gamepad[i] = SDL_JoystickOpen(i);
if (platform.gamepad[i])
{
CORE.Input.Gamepad.ready[i] = true;
@ -1579,13 +1576,15 @@ int InitPlatform(void)
CORE.Time.previous = GetTime(); // Get time as double
#if defined(_WIN32) && defined(SUPPORT_WINMM_HIGHRES_TIMER) && !defined(SUPPORT_BUSY_WAIT_LOOP)
SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "1"); // SDL equivalent of timeBeginPeriod() and timeEndPeriod()
SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "1"); // SDL equivalent of timeBeginPeriod() and timeEndPeriod()
#endif
//----------------------------------------------------------------------------
// Initialize storage system
//----------------------------------------------------------------------------
CORE.Storage.basePath = GetWorkingDirectory(); // Define base path for storage
// Define base path for storage
CORE.Storage.basePath = SDL_GetBasePath(); // Alternative: GetWorkingDirectory();
CHDIR(CORE.Storage.basePath);
//----------------------------------------------------------------------------
TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (SDL): Initialized successfully");
@ -1607,8 +1606,9 @@ static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode)
{
if (sdlScancode >= 0 && sdlScancode < SCANCODE_MAPPED_NUM)
{
return ScancodeToKey[sdlScancode];
return mapScancodeToKey[sdlScancode];
}
return KEY_NULL; // No equivalent key in Raylib
}
// EOF

View file

@ -398,7 +398,7 @@ int GetMonitorWidth(int monitor)
{
width = platform.connector->modes[platform.modeIndex].hdisplay;
}
return width;
}
@ -415,7 +415,7 @@ int GetMonitorHeight(int monitor)
{
height = platform.connector->modes[platform.modeIndex].vdisplay;
}
return height;
}
@ -479,7 +479,7 @@ const char *GetMonitorName(int monitor)
{
name = platform.connector->modes[platform.modeIndex].name;
}
return name;
}
@ -1028,7 +1028,7 @@ int InitPlatform(void)
// If graphic device is no properly initialized, we end program
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE.Window.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE.Window.screen.height / 2);
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2);
// Set some default window flags
CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // false
@ -1136,7 +1136,8 @@ void ClosePlatform(void)
// Close the evdev devices
if (platform.mouseFd != -1) {
if (platform.mouseFd != -1)
{
close(platform.mouseFd);
platform.mouseFd = -1;
}
@ -1613,7 +1614,7 @@ static void PollKeyboardEvents(void)
}
}
TRACELOG(LOG_DEBUG, "INPUT: KEY_%s Keycode(linux): %4i KeyCode(raylib): %4i", (event.value == 0) ? "UP " : "DOWN", event.code, keycode);
TRACELOG(LOG_DEBUG, "INPUT: KEY_%s Keycode(linux): %4i KeyCode(raylib): %4i", (event.value == 0)? "UP " : "DOWN", event.code, keycode);
}
}
}
@ -1640,7 +1641,7 @@ static void PollGamepadEvents(void)
{
short keycodeRaylib = linuxToRaylibMap[event.code];
TRACELOG(LOG_DEBUG, "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i", i, (event.value == 0) ? "UP " : "DOWN", event.code, keycodeRaylib);
TRACELOG(LOG_DEBUG, "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i", i, (event.value == 0)? "UP" : "DOWN", event.code, keycodeRaylib);
if ((keycodeRaylib != 0) && (keycodeRaylib < MAX_GAMEPAD_BUTTONS))
{
@ -1665,7 +1666,7 @@ static void PollGamepadEvents(void)
int range = platform.gamepadAbsAxisRange[i][event.code][1];
// NOTE: Scaling of event.value to get values between -1..1
CORE.Input.Gamepad.axisState[i][axisRaylib] = (2 * (float)(event.value - min) / range) - 1;
CORE.Input.Gamepad.axisState[i][axisRaylib] = (2*(float)(event.value - min)/range) - 1;
}
}
}
@ -1924,9 +1925,7 @@ static int FindNearestConnectorMode(const drmModeConnector *connector, uint widt
const int nearestHeightDiff = abs(platform.connector->modes[nearestIndex].vdisplay - height);
const int nearestFpsDiff = abs(platform.connector->modes[nearestIndex].vrefresh - fps);
if ((widthDiff < nearestWidthDiff) || (heightDiff < nearestHeightDiff) || (fpsDiff < nearestFpsDiff)) {
nearestIndex = i;
}
if ((widthDiff < nearestWidthDiff) || (heightDiff < nearestHeightDiff) || (fpsDiff < nearestFpsDiff)) nearestIndex = i;
}
return nearestIndex;

Some files were not shown because too many files have changed in this diff Show more