Merge branch 'master' into drm_gamepad_polling
This commit is contained in:
commit
35159abd66
18 changed files with 4754 additions and 1376 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# Setup the project and settings
|
||||
project(raylib C)
|
||||
set(PROJECT_VERSION 4.5.0)
|
||||
set(API_VERSION 450)
|
||||
set(PROJECT_VERSION 5.0.0)
|
||||
set(API_VERSION 500)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(JoinPaths)
|
||||
|
|
@ -62,12 +62,10 @@ if (NOT BUILD_SHARED_LIBS)
|
|||
add_library(raylib_static ALIAS raylib)
|
||||
else()
|
||||
MESSAGE(STATUS "Building raylib shared library")
|
||||
if (WIN32)
|
||||
target_compile_definitions(raylib
|
||||
PRIVATE $<BUILD_INTERFACE:BUILD_LIBTYPE_SHARED>
|
||||
INTERFACE $<INSTALL_INTERFACE:USE_LIBTYPE_SHARED>
|
||||
)
|
||||
endif ()
|
||||
target_compile_definitions(raylib
|
||||
PRIVATE $<BUILD_INTERFACE:BUILD_LIBTYPE_SHARED>
|
||||
INTERFACE $<INSTALL_INTERFACE:USE_LIBTYPE_SHARED>
|
||||
)
|
||||
endif()
|
||||
|
||||
if (${PLATFORM} MATCHES "Web")
|
||||
|
|
@ -84,6 +82,11 @@ if (WITH_PIC OR BUILD_SHARED_LIBS)
|
|||
set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif ()
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
# Hide raylib's symbols by default so RLAPI can expose them
|
||||
set_property(TARGET raylib PROPERTY C_VISIBILITY_PRESET hidden)
|
||||
endif ()
|
||||
|
||||
target_link_libraries(raylib "${LIBS_PRIVATE}")
|
||||
|
||||
# Sets some compile time definitions for the pre-processor
|
||||
|
|
|
|||
18
src/Makefile
18
src/Makefile
|
|
@ -114,7 +114,7 @@ HOST_PLATFORM_OS ?= WINDOWS
|
|||
PLATFORM_OS ?= WINDOWS
|
||||
|
||||
# Determine PLATFORM_OS when required
|
||||
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_DESKTOP_SDL PLATFORM_WEB))
|
||||
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_DESKTOP_SDL PLATFORM_WEB PLATFORM_ANDROID))
|
||||
# No uname.exe on MinGW!, but OS=Windows_NT on Windows!
|
||||
# ifeq ($(UNAME),Msys) -> Windows
|
||||
ifeq ($(OS),Windows_NT)
|
||||
|
|
@ -189,8 +189,12 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
|||
ANDROID_NDK ?= C:/android-ndk
|
||||
ANDROID_TOOLCHAIN = $(ANDROID_NDK)/toolchains/llvm/prebuilt/windows-x86_64
|
||||
else
|
||||
ANDROID_NDK ?= /usr/lib/android/ndk
|
||||
ANDROID_TOOLCHAIN = $(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64
|
||||
ANDROID_NDK ?= /usr/lib/android/ndk
|
||||
ifeq ($(PLATFORM_OS), OSX)
|
||||
ANDROID_TOOLCHAIN = $(ANDROID_NDK)/toolchains/llvm/prebuilt/darwin-x86_64
|
||||
else
|
||||
ANDROID_TOOLCHAIN = $(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64
|
||||
endif
|
||||
endif
|
||||
|
||||
# NOTE: Sysroot can also be reference from $(ANDROID_NDK)/sysroot
|
||||
|
|
@ -376,7 +380,7 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
|||
# -Werror=format-security
|
||||
CFLAGS += -Wa,--noexecstack -Wformat -no-canonical-prefixes
|
||||
# Preprocessor macro definitions
|
||||
CFLAGS += -D__ANDROID__ -DPLATFORM_ANDROID -D__ANDROID_API__=$(ANDROID_API_VERSION) -DMAL_NO_OSS
|
||||
CFLAGS += -D__ANDROID__ -DPLATFORM_ANDROID -D__ANDROID_API__=$(ANDROID_API_VERSION)
|
||||
endif
|
||||
|
||||
# Define required compilation flags for raylib SHARED lib
|
||||
|
|
@ -385,7 +389,13 @@ ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
|||
# BE CAREFUL: It seems that for gcc -fpic is not the same as -fPIC
|
||||
# MinGW32 just doesn't need -fPIC, it shows warnings
|
||||
CFLAGS += -fPIC -DBUILD_LIBTYPE_SHARED
|
||||
|
||||
# hide all symbols by default, so RLAPI can expose them
|
||||
ifeq ($(PLATFORM_OS),$(filter $(PLATFORM_OS), LINUX BSD OSX))
|
||||
CFLAGS += -fvisibility=hidden
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DRM)
|
||||
# without EGL_NO_X11 eglplatform.h tears Xlib.h in which tears X.h in
|
||||
# which contains a conflicting type Font
|
||||
|
|
|
|||
5
src/external/rprand.h
vendored
5
src/external/rprand.h
vendored
|
|
@ -200,8 +200,7 @@ int *rprand_load_sequence(unsigned int count, int min, int max)
|
|||
|
||||
for (unsigned int i = 0; i < count;)
|
||||
{
|
||||
value = ((int)rprand_xoshiro()%(abs(max - min) + 1)) + min;
|
||||
value_is_dup = false;
|
||||
value = ((unsigned int)rprand_xoshiro()%(abs(max - min) + 1)) + min;
|
||||
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
|
|
@ -217,6 +216,8 @@ int *rprand_load_sequence(unsigned int count, int min, int max)
|
|||
sequence[i] = value;
|
||||
i++;
|
||||
}
|
||||
|
||||
value_is_dup = false;
|
||||
}
|
||||
|
||||
return sequence;
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
|
|||
static void CharCallback(GLFWwindow *window, unsigned int key); // GLFW3 Char Key Callback, runs on key pressed (get char value)
|
||||
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
|
||||
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move
|
||||
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Srolling Callback, runs on mouse wheel
|
||||
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Scrolling Callback, runs on mouse wheel
|
||||
static void CursorEnterCallback(GLFWwindow *window, int enter); // GLFW3 Cursor Enter Callback, cursor enters client area
|
||||
static void JoystickCallback(int jid, int event); // GLFW3 Joystick Connected/Disconnected Callback
|
||||
|
||||
|
|
@ -1137,7 +1137,7 @@ void PollInputEvents(void)
|
|||
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
|
||||
|
||||
// Map touch position to mouse position for convenience
|
||||
// WARNING: If the target desktop device supports touch screen, this behavious should be reviewed!
|
||||
// WARNING: If the target desktop device supports touch screen, this behaviour should be reviewed!
|
||||
// TODO: GLFW does not support multi-touch input just yet
|
||||
// https://www.codeproject.com/Articles/668404/Programming-for-Multi-Touch
|
||||
// https://docs.microsoft.com/en-us/windows/win32/wintouch/getting-started-with-multi-touch-messages
|
||||
|
|
@ -1739,7 +1739,8 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
|
|||
// WARNING: GLFW could only return GLFW_PRESS (1) or GLFW_RELEASE (0) for now,
|
||||
// but future releases may add more actions (i.e. GLFW_REPEAT)
|
||||
CORE.Input.Mouse.currentButtonState[button] = action;
|
||||
|
||||
CORE.Input.Touch.currentTouchState[button] = action;
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
|
||||
// Process mouse events as touches to be able to use mouse-gestures
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
|
|
|||
|
|
@ -48,8 +48,14 @@
|
|||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#include "SDL.h" // SDL base library (window/rendered, input, timming... functionality)
|
||||
#include "SDL_opengl.h" // SDL OpenGL functionality (if required, instead of internal renderer)
|
||||
#include "SDL.h" // SDL base library (window/rendered, input, timing... functionality)
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// It seems it does not need to be included to work
|
||||
//#include "SDL_opengles2.h"
|
||||
#else
|
||||
#include "SDL_opengl.h" // SDL OpenGL functionality (if required, instead of internal renderer)
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
|
|
@ -493,9 +499,9 @@ void SetWindowIcon(Image image)
|
|||
bmask = 0x001F, amask = 0;
|
||||
depth = 16, pitch = image.width * 2;
|
||||
break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8:
|
||||
rmask = 0xFF0000, gmask = 0x00FF00;
|
||||
bmask = 0x0000FF, amask = 0;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8: // Uses BGR for 24-bit
|
||||
rmask = 0x0000FF, gmask = 0x00FF00;
|
||||
bmask = 0xFF0000, amask = 0;
|
||||
depth = 24, pitch = image.width * 3;
|
||||
break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
|
||||
|
|
@ -592,7 +598,7 @@ void SetWindowMonitor(int monitor)
|
|||
// NOTE:
|
||||
// 1. SDL started supporting moving exclusive fullscreen windows between displays on SDL3,
|
||||
// see commit https://github.com/libsdl-org/SDL/commit/3f5ef7dd422057edbcf3e736107e34be4b75d9ba
|
||||
// 2. A workround for SDL2 is leaving fullscreen, moving the window, then entering full screen again.
|
||||
// 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 int screenWidth = CORE.Window.screen.width;
|
||||
|
|
@ -611,7 +617,7 @@ void SetWindowMonitor(int monitor)
|
|||
// ending up positioned partly outside the target display.
|
||||
// 2. The workaround for that is, previously to moving the window,
|
||||
// setting the window size to the target display size, so they match.
|
||||
// 3. It was't done here because we can't assume changing the window size automatically
|
||||
// 3. It wasn't done here because we can't assume changing the window size automatically
|
||||
// is acceptable behavior by the user.
|
||||
SDL_SetWindowPosition(platform.window, usableBounds.x, usableBounds.y);
|
||||
CORE.Window.position.x = usableBounds.x;
|
||||
|
|
@ -935,6 +941,8 @@ int SetGamepadMappings(const char *mappings)
|
|||
// Set mouse position XY
|
||||
void SetMousePosition(int x, int y)
|
||||
{
|
||||
SDL_WarpMouseInWindow(platform.window, x, y);
|
||||
|
||||
CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y };
|
||||
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
|
||||
}
|
||||
|
|
@ -961,9 +969,6 @@ void PollInputEvents(void)
|
|||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||
|
||||
// Reset key repeats
|
||||
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.keyRepeatInFrame[i] = 0;
|
||||
|
||||
// Reset mouse wheel
|
||||
CORE.Input.Mouse.currentWheelMove.x = 0;
|
||||
CORE.Input.Mouse.currentWheelMove.y = 0;
|
||||
|
|
@ -991,7 +996,7 @@ void PollInputEvents(void)
|
|||
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
||||
|
||||
int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
|
||||
bool gestureUpdate = false; // Flag to note gestures require to update
|
||||
bool realTouch = false; // Flag to differentiate real touch gestures from mouse ones
|
||||
|
||||
// Register previous keys states
|
||||
// NOTE: Android supports up to 260 keys
|
||||
|
|
@ -1004,7 +1009,7 @@ void PollInputEvents(void)
|
|||
// Register previous mouse states
|
||||
for (int i = 0; i < MAX_MOUSE_BUTTONS; i++) CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
|
||||
|
||||
// Poll input events for current plaform
|
||||
// Poll input events for current platform
|
||||
//-----------------------------------------------------------------------------
|
||||
/*
|
||||
// WARNING: Indexes into this array are obtained by using SDL_Scancode values, not SDL_Keycode values
|
||||
|
|
@ -1089,6 +1094,8 @@ void PollInputEvents(void)
|
|||
KeyboardKey key = ConvertScancodeToKey(event.key.keysym.scancode);
|
||||
if (key != KEY_NULL) CORE.Input.Keyboard.currentKeyState[key] = 1;
|
||||
|
||||
if (event.key.repeat) CORE.Input.Keyboard.keyRepeatInFrame[key] = 1;
|
||||
|
||||
// TODO: Put exitKey verification outside the switch?
|
||||
if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey])
|
||||
{
|
||||
|
|
@ -1102,6 +1109,25 @@ void PollInputEvents(void)
|
|||
if (key != KEY_NULL) CORE.Input.Keyboard.currentKeyState[key] = 0;
|
||||
} break;
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
{
|
||||
// Check if there is space available in the key queue
|
||||
if (CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE)
|
||||
{
|
||||
// Add character to the queue
|
||||
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = event.text.text[0];
|
||||
CORE.Input.Keyboard.keyPressedQueueCount++;
|
||||
}
|
||||
|
||||
// Check if there is space available in the queue
|
||||
if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE)
|
||||
{
|
||||
// Add character to the queue
|
||||
CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = event.text.text[0];
|
||||
CORE.Input.Keyboard.charPressedQueueCount++;
|
||||
}
|
||||
} break;
|
||||
|
||||
// Check mouse events
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
{
|
||||
|
|
@ -1112,9 +1138,9 @@ void PollInputEvents(void)
|
|||
else if (btn == 1) btn = 2;
|
||||
|
||||
CORE.Input.Mouse.currentButtonState[btn] = 1;
|
||||
CORE.Input.Touch.currentTouchState[btn] = 1;
|
||||
|
||||
touchAction = 1;
|
||||
gestureUpdate = true;
|
||||
} break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
|
|
@ -1125,9 +1151,9 @@ void PollInputEvents(void)
|
|||
else if (btn == 1) btn = 2;
|
||||
|
||||
CORE.Input.Mouse.currentButtonState[btn] = 0;
|
||||
CORE.Input.Touch.currentTouchState[btn] = 0;
|
||||
|
||||
touchAction = 0;
|
||||
gestureUpdate = true;
|
||||
} break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
{
|
||||
|
|
@ -1150,7 +1176,38 @@ void PollInputEvents(void)
|
|||
|
||||
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
||||
touchAction = 2;
|
||||
gestureUpdate = true;
|
||||
} break;
|
||||
|
||||
// Check touch events
|
||||
// NOTE: These cases need to be reviewed on a real touch screen
|
||||
case SDL_FINGERDOWN:
|
||||
{
|
||||
const int touchId = (int)event.tfinger.fingerId;
|
||||
CORE.Input.Touch.currentTouchState[touchId] = 1;
|
||||
CORE.Input.Touch.position[touchId].x = event.tfinger.x * CORE.Window.screen.width;
|
||||
CORE.Input.Touch.position[touchId].y = event.tfinger.y * CORE.Window.screen.height;
|
||||
|
||||
touchAction = 1;
|
||||
realTouch = true;
|
||||
} break;
|
||||
case SDL_FINGERUP:
|
||||
{
|
||||
const int touchId = (int)event.tfinger.fingerId;
|
||||
CORE.Input.Touch.currentTouchState[touchId] = 0;
|
||||
CORE.Input.Touch.position[touchId].x = event.tfinger.x * CORE.Window.screen.width;
|
||||
CORE.Input.Touch.position[touchId].y = event.tfinger.y * CORE.Window.screen.height;
|
||||
|
||||
touchAction = 0;
|
||||
realTouch = true;
|
||||
} break;
|
||||
case SDL_FINGERMOTION:
|
||||
{
|
||||
const int touchId = (int)event.tfinger.fingerId;
|
||||
CORE.Input.Touch.position[touchId].x = event.tfinger.x * CORE.Window.screen.width;
|
||||
CORE.Input.Touch.position[touchId].y = event.tfinger.y * CORE.Window.screen.height;
|
||||
|
||||
touchAction = 2;
|
||||
realTouch = true;
|
||||
} break;
|
||||
|
||||
// Check gamepad events
|
||||
|
|
@ -1175,7 +1232,7 @@ void PollInputEvents(void)
|
|||
}
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
if (gestureUpdate)
|
||||
if (touchAction > -1)
|
||||
{
|
||||
// Process mouse events as touches to be able to use mouse-gestures
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
|
@ -1190,7 +1247,7 @@ void PollInputEvents(void)
|
|||
gestureEvent.pointCount = 1;
|
||||
|
||||
// Register touch points position, only one point registered
|
||||
if (touchAction == 2) gestureEvent.position[0] = CORE.Input.Touch.position[0];
|
||||
if (touchAction == 2 || realTouch) gestureEvent.position[0] = CORE.Input.Touch.position[0];
|
||||
else gestureEvent.position[0] = GetMousePosition();
|
||||
|
||||
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
|
||||
|
|
@ -1199,6 +1256,8 @@ void PollInputEvents(void)
|
|||
|
||||
// Gesture data is sent to gestures-system for processing
|
||||
ProcessGestureEvent(gestureEvent);
|
||||
|
||||
touchAction = -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1310,7 +1369,7 @@ int InitPlatform(void)
|
|||
// Init OpenGL context
|
||||
platform.glContext = SDL_GL_CreateContext(platform.window);
|
||||
|
||||
// Check window and glContext have been initialized succesfully
|
||||
// Check window and glContext have been initialized successfully
|
||||
if ((platform.window != NULL) && (platform.glContext != NULL))
|
||||
{
|
||||
CORE.Window.ready = true;
|
||||
|
|
@ -1351,10 +1410,15 @@ int InitPlatform(void)
|
|||
//if (platform.gamepadgamepad == NULL) TRACELOG(LOG_WARNING, "PLATFORM: Unable to open game controller [ERROR: %s]", SDL_GetError());
|
||||
}
|
||||
|
||||
// Disable mouse events being interpreted as touch events
|
||||
// NOTE: This is wanted because there are SDL_FINGER* events available which provide unique data
|
||||
// Due to the way PollInputEvents() and rgestures.h are currently implemented, setting this won't break SUPPORT_MOUSE_GESTURES
|
||||
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
|
||||
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// Initialize timming system
|
||||
// Initialize timing system
|
||||
//----------------------------------------------------------------------------
|
||||
// NOTE: No need to call InitTimer(), let SDL manage it internally
|
||||
CORE.Time.previous = GetTime(); // Get time as double
|
||||
|
|
|
|||
|
|
@ -545,9 +545,6 @@ void PollInputEvents(void)
|
|||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||
|
||||
// Reset key repeats
|
||||
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.keyRepeatInFrame[i] = 0;
|
||||
|
||||
// Reset last gamepad button/axis registered state
|
||||
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
|
||||
//CORE.Input.Gamepad.axisCount = 0;
|
||||
|
|
@ -573,6 +570,7 @@ void PollInputEvents(void)
|
|||
{
|
||||
CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
|
||||
CORE.Input.Mouse.currentButtonState[i] = platform.currentButtonStateEvdev[i];
|
||||
CORE.Input.Touch.currentTouchState[i] = platform.currentButtonStateEvdev[i];
|
||||
}
|
||||
|
||||
// Register gamepads buttons events
|
||||
|
|
@ -603,7 +601,6 @@ void PollInputEvents(void)
|
|||
struct input_event event = { 0 };
|
||||
|
||||
int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
|
||||
bool gestureUpdate = false; // Flag to note gestures require to update
|
||||
|
||||
// Try to read data from the mouse/touch/gesture and only continue if successful
|
||||
while (read(fd, &event, sizeof(event)) == (int)sizeof(event))
|
||||
|
|
@ -622,7 +619,6 @@ void PollInputEvents(void)
|
|||
CORE.Input.Touch.position[0].x = CORE.Input.Mouse.currentPosition.x;
|
||||
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
if (event.code == REL_Y)
|
||||
|
|
@ -636,7 +632,6 @@ void PollInputEvents(void)
|
|||
CORE.Input.Touch.position[0].y = CORE.Input.Mouse.currentPosition.y;
|
||||
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
if (event.code == REL_WHEEL) platform.eventWheelMove.y += event.value;
|
||||
|
|
@ -652,7 +647,6 @@ void PollInputEvents(void)
|
|||
CORE.Input.Touch.position[0].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; // Scale according to absRange
|
||||
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
if (event.code == ABS_Y)
|
||||
|
|
@ -661,7 +655,6 @@ void PollInputEvents(void)
|
|||
CORE.Input.Touch.position[0].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; // Scale according to absRange
|
||||
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
// Multitouch movement
|
||||
|
|
@ -697,7 +690,6 @@ void PollInputEvents(void)
|
|||
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 0;
|
||||
|
||||
touchAction = 0; // TOUCH_ACTION_UP
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
if (event.value && !previousMouseLeftButtonState)
|
||||
|
|
@ -705,7 +697,6 @@ void PollInputEvents(void)
|
|||
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 1;
|
||||
|
||||
touchAction = 1; // TOUCH_ACTION_DOWN
|
||||
gestureUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -721,7 +712,6 @@ void PollInputEvents(void)
|
|||
|
||||
if (event.value > 0) touchAction = 1; // TOUCH_ACTION_DOWN
|
||||
else touchAction = 0; // TOUCH_ACTION_UP
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
if (event.code == BTN_RIGHT) platform.currentButtonStateEvdev[MOUSE_BUTTON_RIGHT] = event.value;
|
||||
|
|
@ -750,7 +740,7 @@ void PollInputEvents(void)
|
|||
}
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
if (gestureUpdate)
|
||||
if (touchAction > -1)
|
||||
{
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
|
|
@ -765,7 +755,7 @@ void PollInputEvents(void)
|
|||
|
||||
ProcessGestureEvent(gestureEvent);
|
||||
|
||||
gestureUpdate = false;
|
||||
touchAction = -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1696,6 +1686,7 @@ static void PollKeyboardEvents(void)
|
|||
// Event interface: 'value' is the value the event carries. Either a relative change for EV_REL,
|
||||
// absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat
|
||||
CORE.Input.Keyboard.currentKeyState[keycode] = (event.value >= 1)? 1 : 0;
|
||||
CORE.Input.Keyboard.keyRepeatInFrame[keycode] = (event.value == 2)? 1 : 0;
|
||||
if (event.value >= 1)
|
||||
{
|
||||
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode; // Register last key pressed
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ void PollInputEvents(void)
|
|||
CORE.Input.Keyboard.keyRepeatInFrame[i] = 0;
|
||||
}
|
||||
|
||||
// TODO: Poll input events for current plaform
|
||||
// TODO: Poll input events for current platform
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -561,13 +561,13 @@ int InitPlatform(void)
|
|||
|
||||
// TODO: Initialize input events system
|
||||
// It could imply keyboard, mouse, gamepad, touch...
|
||||
// Depending on the platform libraries/SDK it could use a callbacks mechanims
|
||||
// Depending on the platform libraries/SDK it could use a callback mechanism
|
||||
// For system events and inputs evens polling on a per-frame basis, use PollInputEvents()
|
||||
//----------------------------------------------------------------------------
|
||||
// ...
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// TODO: Initialize timming system
|
||||
// TODO: Initialize timing system
|
||||
//----------------------------------------------------------------------------
|
||||
InitTimer();
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@
|
|||
//----------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
GLFWwindow *handle; // GLFW window handle (graphic device)
|
||||
bool ourFullscreen; // Internal var to filter our handling of fullscreen vs the user handling of fullscreen
|
||||
} PlatformData;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -140,6 +141,37 @@ bool WindowShouldClose(void)
|
|||
// Toggle fullscreen mode
|
||||
void ToggleFullscreen(void)
|
||||
{
|
||||
platform.ourFullscreen = true;
|
||||
bool enterFullscreen = false;
|
||||
|
||||
const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
|
||||
if (wasFullscreen)
|
||||
{
|
||||
EM_ASM(document.exitFullscreen(););
|
||||
|
||||
if (CORE.Window.flags & FLAG_FULLSCREEN_MODE) enterFullscreen = false;
|
||||
else enterFullscreen = true;
|
||||
|
||||
CORE.Window.fullscreen = false;
|
||||
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;
|
||||
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
|
||||
}
|
||||
else enterFullscreen = true;
|
||||
|
||||
if (enterFullscreen)
|
||||
{
|
||||
// NOTE: The setTimeouts handle the browser mode change delay
|
||||
EM_ASM(
|
||||
setTimeout(function()
|
||||
{
|
||||
Module.requestFullscreen(false, false);
|
||||
}, 100);
|
||||
);
|
||||
CORE.Window.fullscreen = true;
|
||||
CORE.Window.flags |= FLAG_FULLSCREEN_MODE;
|
||||
}
|
||||
|
||||
// NOTE: Old notes below:
|
||||
/*
|
||||
EM_ASM
|
||||
(
|
||||
|
|
@ -204,14 +236,44 @@ void ToggleFullscreen(void)
|
|||
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;
|
||||
}
|
||||
*/
|
||||
|
||||
CORE.Window.fullscreen = !CORE.Window.fullscreen; // Toggle fullscreen flag
|
||||
}
|
||||
|
||||
// Toggle borderless windowed mode
|
||||
void ToggleBorderlessWindowed(void)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ToggleBorderlessWindowed() not available on target platform");
|
||||
platform.ourFullscreen = true;
|
||||
bool enterBorderless = false;
|
||||
|
||||
const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
|
||||
if (wasFullscreen)
|
||||
{
|
||||
EM_ASM(document.exitFullscreen(););
|
||||
|
||||
if (CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) enterBorderless = false;
|
||||
else enterBorderless = true;
|
||||
|
||||
CORE.Window.fullscreen = false;
|
||||
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;
|
||||
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
|
||||
}
|
||||
else enterBorderless = true;
|
||||
|
||||
if (enterBorderless)
|
||||
{
|
||||
// NOTE: 1. The setTimeouts handle the browser mode change delay
|
||||
// 2. The style unset handles the possibility of a width="value%" like on the default shell.html file
|
||||
EM_ASM(
|
||||
setTimeout(function()
|
||||
{
|
||||
Module.requestFullscreen(false, true);
|
||||
setTimeout(function()
|
||||
{
|
||||
canvas.style.width="unset";
|
||||
}, 100);
|
||||
}, 100);
|
||||
);
|
||||
CORE.Window.flags |= FLAG_BORDERLESS_WINDOWED_MODE;
|
||||
}
|
||||
}
|
||||
|
||||
// Set window state: maximized, if resizable
|
||||
|
|
@ -235,13 +297,215 @@ void RestoreWindow(void)
|
|||
// Set window configuration state using flags
|
||||
void SetWindowState(unsigned int flags)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState() not available on target platform");
|
||||
// Check previous state and requested state to apply required changes
|
||||
// NOTE: In most cases the functions already change the flags internally
|
||||
|
||||
// State change: FLAG_VSYNC_HINT
|
||||
if ((flags & FLAG_VSYNC_HINT) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_VSYNC_HINT) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_BORDERLESS_WINDOWED_MODE
|
||||
if (((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) != (flags & FLAG_BORDERLESS_WINDOWED_MODE)) && ((flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0))
|
||||
{
|
||||
ToggleBorderlessWindowed(); // NOTE: Window state flag updated inside function
|
||||
}
|
||||
|
||||
// State change: FLAG_FULLSCREEN_MODE
|
||||
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) != (flags & FLAG_FULLSCREEN_MODE))
|
||||
{
|
||||
ToggleFullscreen(); // NOTE: Window state flag updated inside function
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_RESIZABLE
|
||||
if (((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) != (flags & FLAG_WINDOW_RESIZABLE)) && ((flags & FLAG_WINDOW_RESIZABLE) > 0))
|
||||
{
|
||||
glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_TRUE);
|
||||
CORE.Window.flags |= FLAG_WINDOW_RESIZABLE;
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_UNDECORATED
|
||||
if ((flags & FLAG_WINDOW_UNDECORATED) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_UNDECORATED) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_HIDDEN
|
||||
if ((flags & FLAG_WINDOW_HIDDEN) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_HIDDEN) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_MINIMIZED
|
||||
if ((flags & FLAG_WINDOW_MINIMIZED) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_MINIMIZED) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_MAXIMIZED
|
||||
if ((flags & FLAG_WINDOW_MAXIMIZED) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_MAXIMIZED) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_UNFOCUSED
|
||||
if ((flags & FLAG_WINDOW_UNFOCUSED) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_UNFOCUSED) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_TOPMOST
|
||||
if ((flags & FLAG_WINDOW_TOPMOST) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_TOPMOST) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_ALWAYS_RUN
|
||||
if ((flags & FLAG_WINDOW_ALWAYS_RUN) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_ALWAYS_RUN) not available on target platform");
|
||||
}
|
||||
|
||||
// The following states can not be changed after window creation
|
||||
// NOTE: Review for PLATFORM_WEB
|
||||
|
||||
// State change: FLAG_WINDOW_TRANSPARENT
|
||||
if ((flags & FLAG_WINDOW_TRANSPARENT) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_TRANSPARENT) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_HIGHDPI
|
||||
if ((flags & FLAG_WINDOW_HIGHDPI) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_HIGHDPI) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_MOUSE_PASSTHROUGH
|
||||
if ((flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_MOUSE_PASSTHROUGH) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_MSAA_4X_HINT
|
||||
if ((flags & FLAG_MSAA_4X_HINT) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_MSAA_4X_HINT) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_INTERLACED_HINT
|
||||
if ((flags & FLAG_INTERLACED_HINT) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_INTERLACED_HINT) not available on target platform");
|
||||
}
|
||||
}
|
||||
|
||||
// Clear window configuration state flags
|
||||
void ClearWindowState(unsigned int flags)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState() not available on target platform");
|
||||
// Check previous state and requested state to apply required changes
|
||||
// NOTE: In most cases the functions already change the flags internally
|
||||
|
||||
// State change: FLAG_VSYNC_HINT
|
||||
if ((flags & FLAG_VSYNC_HINT) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_VSYNC_HINT) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_BORDERLESS_WINDOWED_MODE
|
||||
if (((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0) && ((flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0))
|
||||
{
|
||||
ToggleBorderlessWindowed(); // NOTE: Window state flag updated inside function
|
||||
}
|
||||
|
||||
// State change: FLAG_FULLSCREEN_MODE
|
||||
if (((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) && ((flags & FLAG_FULLSCREEN_MODE) > 0))
|
||||
{
|
||||
ToggleFullscreen(); // NOTE: Window state flag updated inside function
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_RESIZABLE
|
||||
if (((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) > 0) && ((flags & FLAG_WINDOW_RESIZABLE) > 0))
|
||||
{
|
||||
glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_FALSE);
|
||||
CORE.Window.flags &= ~FLAG_WINDOW_RESIZABLE;
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_HIDDEN
|
||||
if ((flags & FLAG_WINDOW_HIDDEN) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_HIDDEN) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_MINIMIZED
|
||||
if ((flags & FLAG_WINDOW_MINIMIZED) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_MINIMIZED) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_MAXIMIZED
|
||||
if ((flags & FLAG_WINDOW_MAXIMIZED) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_MAXIMIZED) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_UNDECORATED
|
||||
if ((flags & FLAG_WINDOW_UNDECORATED) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_UNDECORATED) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_UNFOCUSED
|
||||
if ((flags & FLAG_WINDOW_UNFOCUSED) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_UNFOCUSED) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_TOPMOST
|
||||
if ((flags & FLAG_WINDOW_TOPMOST) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_TOPMOST) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_ALWAYS_RUN
|
||||
if ((flags & FLAG_WINDOW_ALWAYS_RUN) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_ALWAYS_RUN) not available on target platform");
|
||||
}
|
||||
|
||||
// The following states can not be changed after window creation
|
||||
// NOTE: Review for PLATFORM_WEB
|
||||
|
||||
// State change: FLAG_WINDOW_TRANSPARENT
|
||||
if ((flags & FLAG_WINDOW_TRANSPARENT) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_TRANSPARENT) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_HIGHDPI
|
||||
if ((flags & FLAG_WINDOW_HIGHDPI) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_HIGHDPI) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_WINDOW_MOUSE_PASSTHROUGH
|
||||
if ((flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_MOUSE_PASSTHROUGH) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_MSAA_4X_HINT
|
||||
if ((flags & FLAG_MSAA_4X_HINT) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_MSAA_4X_HINT) not available on target platform");
|
||||
}
|
||||
|
||||
// State change: FLAG_INTERLACED_HINT
|
||||
if ((flags & FLAG_INTERLACED_HINT) > 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_INTERLACED_HINT) not available on target platform");
|
||||
}
|
||||
}
|
||||
|
||||
// Set icon for window
|
||||
|
|
@ -344,15 +608,19 @@ Vector2 GetMonitorPosition(int monitor)
|
|||
// Get selected monitor width (currently used by monitor)
|
||||
int GetMonitorWidth(int monitor)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GetMonitorWidth() not implemented on target platform");
|
||||
return 0;
|
||||
// NOTE: Returned value is limited to the current monitor where the browser window is located
|
||||
int width = 0;
|
||||
width = EM_ASM_INT( { return screen.width; }, 0);
|
||||
return width;
|
||||
}
|
||||
|
||||
// Get selected monitor height (currently used by monitor)
|
||||
int GetMonitorHeight(int monitor)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GetMonitorHeight() not implemented on target platform");
|
||||
return 0;
|
||||
// NOTE: Returned value is limited to the current monitor where the browser window is located
|
||||
int height = 0;
|
||||
height = EM_ASM_INT( { return screen.height; }, 0);
|
||||
return height;
|
||||
}
|
||||
|
||||
// Get selected monitor physical width in millimetres
|
||||
|
|
@ -386,8 +654,11 @@ const char *GetMonitorName(int monitor)
|
|||
// Get window position XY on monitor
|
||||
Vector2 GetWindowPosition(void)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "GetWindowPosition() not implemented on target platform");
|
||||
return (Vector2){ 0, 0 };
|
||||
// NOTE: Returned position is relative to the current monitor where the browser window is located
|
||||
Vector2 position = { 0, 0 };
|
||||
position.x = (float)EM_ASM_INT( { return window.screenX; }, 0);
|
||||
position.y = (float)EM_ASM_INT( { return window.screenY; }, 0);
|
||||
return position;
|
||||
}
|
||||
|
||||
// Get window scale DPI factor for current monitor
|
||||
|
|
@ -664,7 +935,7 @@ void PollInputEvents(void)
|
|||
|
||||
// TODO: This code does not seem to do anything??
|
||||
//if (CORE.Window.eventWaiting) glfwWaitEvents(); // Wait for in input events before continue (drawing is paused)
|
||||
//else glfwPollEvents(); // Poll input events: keyboard/mouse/window events (callbacks) --> WARNING: Where is key input reseted?
|
||||
//else glfwPollEvents(); // Poll input events: keyboard/mouse/window events (callbacks) --> WARNING: Where is key input reset?
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -716,8 +987,13 @@ int InitPlatform(void)
|
|||
if ((CORE.Window.flags & FLAG_WINDOW_TOPMOST) > 0) glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
|
||||
else glfwWindowHint(GLFW_FLOATING, GLFW_FALSE);
|
||||
|
||||
// NOTE: Some GLFW flags are not supported on HTML5
|
||||
// e.g.: GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_SCALE_TO_MONITOR, GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_MOUSE_PASSTHROUGH
|
||||
// NOTE: Some GLFW flags are not supported on HTML5
|
||||
// e.g.: GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_MOUSE_PASSTHROUGH
|
||||
|
||||
// Scale content area based on the monitor content scale where window is placed on
|
||||
// NOTE: This feature requires emscripten 3.1.51
|
||||
//if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
|
||||
//else glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE);
|
||||
|
||||
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
|
||||
{
|
||||
|
|
@ -775,6 +1051,9 @@ int InitPlatform(void)
|
|||
CORE.Window.display.width = CORE.Window.screen.width;
|
||||
CORE.Window.display.height = CORE.Window.screen.height;
|
||||
|
||||
// Init fullscreen toggle required var:
|
||||
platform.ourFullscreen = false;
|
||||
|
||||
if (CORE.Window.fullscreen)
|
||||
{
|
||||
// remember center for switchinging from fullscreen to window
|
||||
|
|
@ -908,7 +1187,7 @@ int InitPlatform(void)
|
|||
// Initialize input events callbacks
|
||||
//----------------------------------------------------------------------------
|
||||
// Setup callback functions for the DOM events
|
||||
emscripten_set_fullscreenchange_callback("#canvas", NULL, 1, EmscriptenFullscreenChangeCallback);
|
||||
emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenFullscreenChangeCallback);
|
||||
|
||||
// WARNING: Below resize code was breaking fullscreen mode for sample games and examples, it needs review
|
||||
// Check fullscreen change events(note this is done on the window since most browsers don't support this on #canvas)
|
||||
|
|
@ -937,7 +1216,7 @@ int InitPlatform(void)
|
|||
emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback);
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// Initialize timming system
|
||||
// Initialize timing system
|
||||
//----------------------------------------------------------------------------
|
||||
InitTimer();
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
@ -1093,6 +1372,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
|
|||
// WARNING: GLFW could only return GLFW_PRESS (1) or GLFW_RELEASE (0) for now,
|
||||
// but future releases may add more actions (i.e. GLFW_REPEAT)
|
||||
CORE.Input.Mouse.currentButtonState[button] = action;
|
||||
CORE.Input.Touch.currentTouchState[button] = action;
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
|
||||
// Process mouse events as touches to be able to use mouse-gestures
|
||||
|
|
@ -1171,7 +1451,19 @@ static void CursorEnterCallback(GLFWwindow *window, int enter)
|
|||
// Register fullscreen change events
|
||||
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData)
|
||||
{
|
||||
// TODO: Implement EmscriptenFullscreenChangeCallback()?
|
||||
// NOTE: 1. Reset the fullscreen flags if the user left fullscreen manually by pressing the Escape key
|
||||
// 2. Which is a necessary safeguard because that case will bypass the toggles CORE.Window.flags resets
|
||||
if (platform.ourFullscreen) platform.ourFullscreen = false;
|
||||
else
|
||||
{
|
||||
const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
|
||||
if (!wasFullscreen)
|
||||
{
|
||||
CORE.Window.fullscreen = false;
|
||||
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;
|
||||
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
|
||||
}
|
||||
}
|
||||
|
||||
return 1; // The event was consumed by the callback handler
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,6 +167,10 @@ typedef struct tagBITMAPINFOHEADER {
|
|||
#define MA_NO_WAV
|
||||
#define MA_NO_FLAC
|
||||
#define MA_NO_MP3
|
||||
#define MA_NO_RESOURCE_MANAGER
|
||||
#define MA_NO_NODE_GRAPH
|
||||
#define MA_NO_ENGINE
|
||||
#define MA_NO_GENERATION
|
||||
|
||||
// Threading model: Default: [0] COINIT_MULTITHREADED: COM calls objects on any thread (free threading)
|
||||
#define MA_COINIT_VALUE 2 // [2] COINIT_APARTMENTTHREADED: Each object has its own thread (apartment model)
|
||||
|
|
|
|||
25
src/raylib.h
25
src/raylib.h
|
|
@ -1,6 +1,6 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib v5.0 - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
|
||||
* raylib v5.1-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
|
||||
|
|
@ -82,21 +82,26 @@
|
|||
#include <stdarg.h> // Required for: va_list - Only used by TraceLogCallback
|
||||
|
||||
#define RAYLIB_VERSION_MAJOR 5
|
||||
#define RAYLIB_VERSION_MINOR 0
|
||||
#define RAYLIB_VERSION_MINOR 1
|
||||
#define RAYLIB_VERSION_PATCH 0
|
||||
#define RAYLIB_VERSION "5.0"
|
||||
#define RAYLIB_VERSION "5.1-dev"
|
||||
|
||||
// Function specifiers in case library is build/used as a shared library (Windows)
|
||||
// Function specifiers in case library is build/used as a shared library
|
||||
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
||||
// NOTE: visibility("default") attribute makes symbols "visible" when compiled with -fvisibility=hidden
|
||||
#if defined(_WIN32)
|
||||
#if defined(__TINYC__)
|
||||
#define __declspec(x) __attribute__((x))
|
||||
#endif
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#if defined(__TINYC__)
|
||||
#define __declspec(x) __attribute__((x))
|
||||
#endif
|
||||
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||
#elif defined(USE_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||
#endif
|
||||
#else
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __attribute__((visibility("default"))) // We are building as a Unix shared library (.so/.dylib)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef RLAPI
|
||||
|
|
@ -479,7 +484,6 @@ typedef struct VrDeviceInfo {
|
|||
int vResolution; // Vertical resolution in pixels
|
||||
float hScreenSize; // Horizontal size in meters
|
||||
float vScreenSize; // Vertical size in meters
|
||||
float vScreenCenter; // Screen center in meters
|
||||
float eyeToScreenDistance; // Distance between eye and display in meters
|
||||
float lensSeparationDistance; // Lens separation distance in meters
|
||||
float interpupillaryDistance; // IPD (distance between pupils) in meters
|
||||
|
|
@ -1329,6 +1333,7 @@ RLAPI void ImageAlphaClear(Image *image, Color color, float threshold);
|
|||
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 ImageKernelConvolution(Image *image, float* kernel, int kernelSize); // Apply Custom Square image convolution kernel
|
||||
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
|
||||
|
|
@ -1475,6 +1480,7 @@ RLAPI const char *TextToUpper(const char *text); // Get upp
|
|||
RLAPI const char *TextToLower(const char *text); // Get lower case version of provided string
|
||||
RLAPI const char *TextToPascal(const char *text); // Get Pascal case notation version of provided string
|
||||
RLAPI int TextToInteger(const char *text); // Get integer value from text (negative values not supported)
|
||||
RLAPI float TextToFloat(const char *text); // Get float value from text (negative values not supported)
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Basic 3d Shapes Drawing Functions (Module: models)
|
||||
|
|
@ -1530,9 +1536,10 @@ RLAPI void UpdateMeshBuffer(Mesh mesh, int index, const void *data, int dataSize
|
|||
RLAPI void UnloadMesh(Mesh mesh); // Unload mesh data from CPU and GPU
|
||||
RLAPI void DrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform
|
||||
RLAPI void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, int instances); // Draw multiple mesh instances with material and different transforms
|
||||
RLAPI bool ExportMesh(Mesh mesh, const char *fileName); // Export mesh data to file, returns true on success
|
||||
RLAPI BoundingBox GetMeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits
|
||||
RLAPI void GenMeshTangents(Mesh *mesh); // Compute mesh tangents
|
||||
RLAPI bool ExportMesh(Mesh mesh, const char *fileName); // Export mesh data to file, returns true on success
|
||||
RLAPI bool ExportMeshAsCode(Mesh mesh, const char *fileName); // Export mesh as code file (.h) defining multiple arrays of vertex attributes
|
||||
|
||||
// Mesh generation functions
|
||||
RLAPI Mesh GenMeshPoly(int sides, float radius); // Generate polygonal mesh
|
||||
|
|
|
|||
|
|
@ -59,7 +59,9 @@
|
|||
// Function specifiers definition
|
||||
#if defined(RAYMATH_IMPLEMENTATION)
|
||||
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll).
|
||||
#define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll)
|
||||
#elif defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RMAPI __attribute__((visibility("default"))) // We are building raylib as a Unix shared library (.so/.dylib)
|
||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||
#define RMAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -449,7 +449,7 @@ void UpdateCamera(Camera *camera, int mode)
|
|||
|
||||
bool moveInWorldPlane = ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON));
|
||||
bool rotateAroundTarget = ((mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL));
|
||||
bool lockView = ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL));
|
||||
bool lockView = ((mode == CAMERA_FREE) || (mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL));
|
||||
bool rotateUp = false;
|
||||
|
||||
if (mode == CAMERA_ORBITAL)
|
||||
|
|
@ -471,31 +471,30 @@ void UpdateCamera(Camera *camera, int mode)
|
|||
if (IsKeyDown(KEY_E)) CameraRoll(camera, CAMERA_ROTATION_SPEED);
|
||||
|
||||
// Camera movement
|
||||
if (!IsGamepadAvailable(0))
|
||||
// Camera pan (for CAMERA_FREE)
|
||||
if ((mode == CAMERA_FREE) && (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)))
|
||||
{
|
||||
// Camera pan (for CAMERA_FREE)
|
||||
if ((mode == CAMERA_FREE) && (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)))
|
||||
{
|
||||
const Vector2 mouseDelta = GetMouseDelta();
|
||||
if (mouseDelta.x > 0.0f) CameraMoveRight(camera, CAMERA_PAN_SPEED, moveInWorldPlane);
|
||||
if (mouseDelta.x < 0.0f) CameraMoveRight(camera, -CAMERA_PAN_SPEED, moveInWorldPlane);
|
||||
if (mouseDelta.y > 0.0f) CameraMoveUp(camera, -CAMERA_PAN_SPEED);
|
||||
if (mouseDelta.y < 0.0f) CameraMoveUp(camera, CAMERA_PAN_SPEED);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Mouse support
|
||||
CameraYaw(camera, -mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
||||
CameraPitch(camera, -mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
||||
}
|
||||
|
||||
// Keyboard support
|
||||
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
const Vector2 mouseDelta = GetMouseDelta();
|
||||
if (mouseDelta.x > 0.0f) CameraMoveRight(camera, CAMERA_PAN_SPEED, moveInWorldPlane);
|
||||
if (mouseDelta.x < 0.0f) CameraMoveRight(camera, -CAMERA_PAN_SPEED, moveInWorldPlane);
|
||||
if (mouseDelta.y > 0.0f) CameraMoveUp(camera, -CAMERA_PAN_SPEED);
|
||||
if (mouseDelta.y < 0.0f) CameraMoveUp(camera, CAMERA_PAN_SPEED);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Mouse support
|
||||
CameraYaw(camera, -mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
||||
CameraPitch(camera, -mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
||||
}
|
||||
|
||||
// Keyboard support
|
||||
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
|
||||
// Gamepad movement
|
||||
if (IsGamepadAvailable(0))
|
||||
{
|
||||
// Gamepad controller support
|
||||
CameraYaw(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) * 2)*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
||||
|
|
|
|||
11
src/rcore.c
11
src/rcore.c
|
|
@ -1192,8 +1192,8 @@ VrStereoConfig LoadVrStereoConfig(VrDeviceInfo device)
|
|||
// NOTE: Camera movement might seem more natural if we model the head.
|
||||
// Our axis of rotation is the base of our head, so we might want to add
|
||||
// some y (base of head to eye level) and -z (center of head to eye protrusion) to the camera positions.
|
||||
config.viewOffset[0] = MatrixTranslate(-device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
|
||||
config.viewOffset[1] = MatrixTranslate(device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
|
||||
config.viewOffset[0] = MatrixTranslate(device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
|
||||
config.viewOffset[1] = MatrixTranslate(-device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
|
||||
|
||||
// Compute eyes Viewports
|
||||
/*
|
||||
|
|
@ -2623,8 +2623,9 @@ void PlayAutomationEvent(AutomationEvent event)
|
|||
{
|
||||
CORE.Input.Gamepad.axisState[event.params[0]][event.params[1]] = ((float)event.params[2]/32768.0f);
|
||||
} break;
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
case INPUT_GESTURE: GESTURES.current = event.params[0]; break; // param[0]: gesture (enum Gesture) -> rgestures.h: GESTURES.current
|
||||
|
||||
#endif
|
||||
// Window event
|
||||
case WINDOW_CLOSE: CORE.Window.shouldClose = true; break;
|
||||
case WINDOW_MAXIMIZE: MaximizeWindow(); break;
|
||||
|
|
@ -2632,11 +2633,13 @@ void PlayAutomationEvent(AutomationEvent event)
|
|||
case WINDOW_RESIZE: SetWindowSize(event.params[0], event.params[1]); break;
|
||||
|
||||
// Custom event
|
||||
#if defined(SUPPORT_SCREEN_CAPTURE)
|
||||
case ACTION_TAKE_SCREENSHOT:
|
||||
{
|
||||
TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter));
|
||||
screenshotCounter++;
|
||||
} break;
|
||||
#endif
|
||||
case ACTION_SETTARGETFPS: SetTargetFPS(event.params[0]); break;
|
||||
default: break;
|
||||
}
|
||||
|
|
@ -3507,6 +3510,7 @@ static void RecordAutomationEvent(void)
|
|||
}
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
// Gestures input currentEventList->events recording
|
||||
//-------------------------------------------------------------------------------------
|
||||
if (GESTURES.current != GESTURE_NONE)
|
||||
|
|
@ -3524,6 +3528,7 @@ static void RecordAutomationEvent(void)
|
|||
if (currentEventList->count == currentEventList->capacity) return; // Security check
|
||||
}
|
||||
//-------------------------------------------------------------------------------------
|
||||
#endif
|
||||
|
||||
// Window events recording
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
|
|
|||
132
src/rlgl.h
132
src/rlgl.h
|
|
@ -1,6 +1,6 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* rlgl v4.5 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
||||
* rlgl v5.0 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0)
|
||||
|
|
@ -109,16 +109,18 @@
|
|||
|
||||
#define RLGL_VERSION "4.5"
|
||||
|
||||
// Function specifiers in case library is build/used as a shared library (Windows)
|
||||
// Function specifiers in case library is build/used as a shared library
|
||||
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
||||
#if defined(_WIN32)
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||
#elif defined(USE_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||
#endif
|
||||
// NOTE: visibility(default) attribute makes symbols "visible" when compiled with -fvisibility=hidden
|
||||
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||
#elif defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RLAPI __attribute__((visibility("default"))) // We are building he library as a Unix shared library (.so/.dylib)
|
||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||
#endif
|
||||
|
||||
|
||||
// Function specifiers definition
|
||||
#ifndef RLAPI
|
||||
#define RLAPI // Functions defined as 'extern' by default (implicit specifiers)
|
||||
|
|
@ -555,14 +557,14 @@ typedef enum {
|
|||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
RLAPI void rlMatrixMode(int mode); // Choose the current matrix to be transformed
|
||||
RLAPI void rlPushMatrix(void); // Push the current matrix to stack
|
||||
RLAPI void rlPopMatrix(void); // Pop latest inserted matrix from stack
|
||||
RLAPI void rlLoadIdentity(void); // Reset current matrix to identity matrix
|
||||
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(const float *matf); // Multiply the current matrix by another matrix
|
||||
RLAPI void rlMatrixMode(int mode); // Choose the current matrix to be transformed
|
||||
RLAPI void rlPushMatrix(void); // Push the current matrix to stack
|
||||
RLAPI void rlPopMatrix(void); // Pop latest inserted matrix from stack
|
||||
RLAPI void rlLoadIdentity(void); // Reset current matrix to identity matrix
|
||||
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(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
|
||||
|
|
@ -570,15 +572,15 @@ RLAPI void rlViewport(int x, int y, int width, int height); // Set the viewport
|
|||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Vertex level operations
|
||||
//------------------------------------------------------------------------------------
|
||||
RLAPI void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
|
||||
RLAPI void rlEnd(void); // Finish vertex providing
|
||||
RLAPI void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
|
||||
RLAPI void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
|
||||
RLAPI void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
|
||||
RLAPI void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
|
||||
RLAPI void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
|
||||
RLAPI void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Define one vertex (color) - 4 byte
|
||||
RLAPI void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
|
||||
RLAPI void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
|
||||
RLAPI void rlEnd(void); // Finish vertex providing
|
||||
RLAPI void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
|
||||
RLAPI void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
|
||||
RLAPI void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
|
||||
RLAPI void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
|
||||
RLAPI void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
|
||||
RLAPI void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Define one vertex (color) - 4 byte
|
||||
RLAPI void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
|
||||
RLAPI void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
|
@ -592,13 +594,13 @@ RLAPI bool rlEnableVertexArray(unsigned int vaoId); // Enable vertex array (
|
|||
RLAPI void rlDisableVertexArray(void); // Disable vertex array (VAO, if supported)
|
||||
RLAPI void rlEnableVertexBuffer(unsigned int id); // Enable vertex buffer (VBO)
|
||||
RLAPI void rlDisableVertexBuffer(void); // Disable vertex buffer (VBO)
|
||||
RLAPI void rlEnableVertexBufferElement(unsigned int id);// Enable vertex buffer element (VBO element)
|
||||
RLAPI void rlEnableVertexBufferElement(unsigned int id); // Enable vertex buffer element (VBO element)
|
||||
RLAPI void rlDisableVertexBufferElement(void); // Disable vertex buffer element (VBO element)
|
||||
RLAPI void rlEnableVertexAttribute(unsigned int index); // Enable vertex attribute index
|
||||
RLAPI void rlDisableVertexAttribute(unsigned int index);// Disable vertex attribute index
|
||||
RLAPI void rlDisableVertexAttribute(unsigned int index); // Disable vertex attribute index
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
|
||||
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
|
||||
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
|
||||
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
|
||||
#endif
|
||||
|
||||
// Textures state
|
||||
|
|
@ -621,7 +623,7 @@ RLAPI void rlActiveDrawBuffers(int count); // Activate multiple dra
|
|||
RLAPI void rlBlitFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight, int bufferMask); // Blit active framebuffer to main framebuffer
|
||||
|
||||
// General render state
|
||||
RLAPI void rlEnableColorBlend(void); // Enable color blending
|
||||
RLAPI void rlEnableColorBlend(void); // Enable color blending
|
||||
RLAPI void rlDisableColorBlend(void); // Disable color blending
|
||||
RLAPI void rlEnableDepthTest(void); // Enable depth test
|
||||
RLAPI void rlDisableDepthTest(void); // Disable depth test
|
||||
|
|
@ -634,7 +636,7 @@ 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
|
||||
RLAPI void rlEnableWireMode(void); // Enable wire mode
|
||||
RLAPI void rlEnablePointMode(void); // Enable point mode
|
||||
RLAPI void rlEnablePointMode(void); // Enable point mode
|
||||
RLAPI void rlDisableWireMode(void); // Disable wire mode ( and point ) maybe rename
|
||||
RLAPI void rlSetLineWidth(float width); // Set the line drawing width
|
||||
RLAPI float rlGetLineWidth(void); // Get the line drawing width
|
||||
|
|
@ -671,48 +673,48 @@ RLAPI int *rlGetShaderLocsDefault(void); // Get default shader lo
|
|||
// Render batch management
|
||||
// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
|
||||
// but this render batch API is exposed in case of custom batches are required
|
||||
RLAPI rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
|
||||
RLAPI void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system
|
||||
RLAPI void rlDrawRenderBatch(rlRenderBatch *batch); // Draw render batch data (Update->Draw->Reset)
|
||||
RLAPI void rlSetRenderBatchActive(rlRenderBatch *batch); // Set the active render batch for rlgl (NULL for default internal)
|
||||
RLAPI void rlDrawRenderBatchActive(void); // Update and draw internal render batch
|
||||
RLAPI bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex
|
||||
RLAPI rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
|
||||
RLAPI void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system
|
||||
RLAPI void rlDrawRenderBatch(rlRenderBatch *batch); // Draw render batch data (Update->Draw->Reset)
|
||||
RLAPI void rlSetRenderBatchActive(rlRenderBatch *batch); // Set the active render batch for rlgl (NULL for default internal)
|
||||
RLAPI void rlDrawRenderBatchActive(void); // Update and draw internal render batch
|
||||
RLAPI bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex
|
||||
|
||||
RLAPI void rlSetTexture(unsigned int id); // Set current texture for render batch and check buffers limits
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Vertex buffers management
|
||||
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
|
||||
RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic); // Load a vertex buffer attribute
|
||||
RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic); // Load a new attributes element buffer
|
||||
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset); // Update GPU buffer with new data
|
||||
RLAPI void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset); // Update vertex buffer elements with new data
|
||||
RLAPI void rlUnloadVertexArray(unsigned int vaoId);
|
||||
RLAPI void rlUnloadVertexBuffer(unsigned int vboId);
|
||||
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer);
|
||||
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor);
|
||||
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value
|
||||
RLAPI void rlDrawVertexArray(int offset, int count);
|
||||
RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer);
|
||||
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances);
|
||||
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances);
|
||||
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
|
||||
RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic); // Load a vertex buffer object
|
||||
RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic); // Load vertex buffer elements object
|
||||
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset); // Update vertex buffer object data on GPU buffer
|
||||
RLAPI void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset); // Update vertex buffer elements data on GPU buffer
|
||||
RLAPI void rlUnloadVertexArray(unsigned int vaoId); // Unload vertex array (vao)
|
||||
RLAPI void rlUnloadVertexBuffer(unsigned int vboId); // Unload vertex buffer object
|
||||
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer); // Set vertex attribute data configuration
|
||||
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor); // Set vertex attribute data divisor
|
||||
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value, when attribute to provided
|
||||
RLAPI void rlDrawVertexArray(int offset, int count); // Draw vertex array (currently active vao)
|
||||
RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer); // Draw vertex array elements
|
||||
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances); // Draw vertex array (currently active vao) with instancing
|
||||
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances); // Draw vertex array elements with instancing
|
||||
|
||||
// Textures management
|
||||
RLAPI unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
|
||||
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
|
||||
RLAPI unsigned int rlLoadTextureCubemap(const void *data, int size, int format); // Load texture cubemap
|
||||
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update GPU texture with new data
|
||||
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
|
||||
RLAPI unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount); // Load texture data
|
||||
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
|
||||
RLAPI unsigned int rlLoadTextureCubemap(const void *data, int size, int format); // Load texture cubemap data
|
||||
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update texture with new data on GPU
|
||||
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
|
||||
RLAPI const char *rlGetPixelFormatName(unsigned int format); // Get name string for pixel format
|
||||
RLAPI void rlUnloadTexture(unsigned int id); // Unload texture from GPU memory
|
||||
RLAPI void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps); // Generate mipmap data for selected texture
|
||||
RLAPI void *rlReadTexturePixels(unsigned int id, int width, int height, int format); // Read texture pixel data
|
||||
RLAPI void *rlReadTexturePixels(unsigned int id, int width, int height, int format); // Read texture pixel data
|
||||
RLAPI unsigned char *rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
||||
|
||||
// Framebuffer management (fbo)
|
||||
RLAPI unsigned int rlLoadFramebuffer(int width, int height); // Load an empty framebuffer
|
||||
RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
|
||||
RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
|
||||
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
||||
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
||||
|
||||
|
|
@ -723,14 +725,14 @@ RLAPI unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fSha
|
|||
RLAPI void rlUnloadShaderProgram(unsigned int id); // Unload shader program
|
||||
RLAPI int rlGetLocationUniform(unsigned int shaderId, const char *uniformName); // Get shader location uniform
|
||||
RLAPI int rlGetLocationAttrib(unsigned int shaderId, const char *attribName); // Get shader location attribute
|
||||
RLAPI void rlSetUniform(int locIndex, const void *value, int uniformType, int count); // Set shader value uniform
|
||||
RLAPI void rlSetUniform(int locIndex, const void *value, int uniformType, int count); // Set shader value uniform
|
||||
RLAPI void rlSetUniformMatrix(int locIndex, Matrix mat); // Set shader value matrix
|
||||
RLAPI void rlSetUniformSampler(int locIndex, unsigned int textureId); // Set shader value sampler
|
||||
RLAPI void rlSetShader(unsigned int id, int *locs); // Set shader currently active (id and locations)
|
||||
|
||||
// Compute shader management
|
||||
RLAPI unsigned int rlLoadComputeShaderProgram(unsigned int shaderId); // Load compute shader program
|
||||
RLAPI void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pipeline)
|
||||
RLAPI void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pipeline)
|
||||
|
||||
// Shader buffer storage object management (ssbo)
|
||||
RLAPI unsigned int rlLoadShaderBuffer(unsigned int size, const void *data, int usageHint); // Load shader storage buffer object (SSBO)
|
||||
|
|
@ -773,6 +775,12 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||
|
||||
#if defined(RLGL_IMPLEMENTATION)
|
||||
|
||||
// Expose OpenGL functions from glad in raylib
|
||||
#if defined(BUILD_LIBTYPE_SHARED)
|
||||
#define GLAD_API_CALL_EXPORT
|
||||
#define GLAD_API_CALL_EXPORT_BUILD
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenGL/gl.h> // OpenGL 1.1 library for OSX
|
||||
|
|
@ -3787,6 +3795,10 @@ unsigned int rlLoadVertexArray(void)
|
|||
void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// NOTE: Data type could be: GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT
|
||||
// Additional types (depends on OpenGL version or extensions):
|
||||
// - GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE, GL_FIXED,
|
||||
// - GL_INT_2_10_10_10_REV, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_10F_11F_11F_REV
|
||||
glVertexAttribPointer(index, compSize, type, normalized, stride, pointer);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
125
src/rmodels.c
125
src/rmodels.c
|
|
@ -1850,6 +1850,104 @@ bool ExportMesh(Mesh mesh, const char *fileName)
|
|||
return success;
|
||||
}
|
||||
|
||||
// Export mesh as code file (.h) defining multiple arrays of vertex attributes
|
||||
bool ExportMeshAsCode(Mesh mesh, const char *fileName)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
#ifndef TEXT_BYTES_PER_LINE
|
||||
#define TEXT_BYTES_PER_LINE 20
|
||||
#endif
|
||||
|
||||
// NOTE: Text data buffer size is fixed to 64MB
|
||||
char *txtData = (char *)RL_CALLOC(64*1024*1024, sizeof(char)); // 64 MB
|
||||
|
||||
int byteCount = 0;
|
||||
byteCount += sprintf(txtData + byteCount, "////////////////////////////////////////////////////////////////////////////////////////\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// MeshAsCode exporter v1.0 - Mesh vertex data exported as arrays //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// more info and bugs-report: github.com/raysan5/raylib //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// feedback and support: ray[at]raylib.com //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// Copyright (c) 2023 Ramon Santamaria (@raysan5) //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "////////////////////////////////////////////////////////////////////////////////////////\n\n");
|
||||
|
||||
// Get file name from path and convert variable name to uppercase
|
||||
char varFileName[256] = { 0 };
|
||||
strcpy(varFileName, GetFileNameWithoutExt(fileName));
|
||||
for (int i = 0; varFileName[i] != '\0'; i++) if ((varFileName[i] >= 'a') && (varFileName[i] <= 'z')) { varFileName[i] = varFileName[i] - 32; }
|
||||
|
||||
// Add image information
|
||||
byteCount += sprintf(txtData + byteCount, "// Mesh basic information\n");
|
||||
byteCount += sprintf(txtData + byteCount, "#define %s_VERTEX_COUNT %i\n", varFileName, mesh.vertexCount);
|
||||
byteCount += sprintf(txtData + byteCount, "#define %s_TRIANGLE_COUNT %i\n\n", varFileName, mesh.triangleCount);
|
||||
|
||||
// Define vertex attributes data as separate arrays
|
||||
//-----------------------------------------------------------------------------------------
|
||||
if (mesh.vertices != NULL) // Vertex position (XYZ - 3 components per vertex - float)
|
||||
{
|
||||
byteCount += sprintf(txtData + byteCount, "static float %s_VERTEX_DATA[%i] = { ", varFileName, mesh.vertexCount*3);
|
||||
for (int i = 0; i < mesh.vertexCount*3 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.vertices[i]);
|
||||
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.vertices[mesh.vertexCount*3 - 1]);
|
||||
}
|
||||
|
||||
if (mesh.texcoords != NULL) // Vertex texture coordinates (UV - 2 components per vertex - float)
|
||||
{
|
||||
byteCount += sprintf(txtData + byteCount, "static float %s_TEXCOORD_DATA[%i] = { ", varFileName, mesh.vertexCount*2);
|
||||
for (int i = 0; i < mesh.vertexCount*2 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.texcoords[i]);
|
||||
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.texcoords[mesh.vertexCount*2 - 1]);
|
||||
}
|
||||
|
||||
if (mesh.texcoords2 != NULL) // Vertex texture coordinates (UV - 2 components per vertex - float)
|
||||
{
|
||||
byteCount += sprintf(txtData + byteCount, "static float %s_TEXCOORD2_DATA[%i] = { ", varFileName, mesh.vertexCount*2);
|
||||
for (int i = 0; i < mesh.vertexCount*2 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.texcoords2[i]);
|
||||
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.texcoords2[mesh.vertexCount*2 - 1]);
|
||||
}
|
||||
|
||||
if (mesh.normals != NULL) // Vertex normals (XYZ - 3 components per vertex - float)
|
||||
{
|
||||
byteCount += sprintf(txtData + byteCount, "static float %s_NORMAL_DATA[%i] = { ", varFileName, mesh.vertexCount*3);
|
||||
for (int i = 0; i < mesh.vertexCount*3 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.normals[i]);
|
||||
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.normals[mesh.vertexCount*3 - 1]);
|
||||
}
|
||||
|
||||
if (mesh.tangents != NULL) // Vertex tangents (XYZW - 4 components per vertex - float)
|
||||
{
|
||||
byteCount += sprintf(txtData + byteCount, "static float %s_TANGENT_DATA[%i] = { ", varFileName, mesh.vertexCount*4);
|
||||
for (int i = 0; i < mesh.vertexCount*4 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.tangents[i]);
|
||||
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.tangents[mesh.vertexCount*4 - 1]);
|
||||
}
|
||||
|
||||
if (mesh.colors != NULL) // Vertex colors (RGBA - 4 components per vertex - unsigned char)
|
||||
{
|
||||
byteCount += sprintf(txtData + byteCount, "static unsigned char %s_COLOR_DATA[%i] = { ", varFileName, mesh.vertexCount*4);
|
||||
for (int i = 0; i < mesh.vertexCount*4 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), mesh.colors[i]);
|
||||
byteCount += sprintf(txtData + byteCount, "0x%x };\n\n", mesh.colors[mesh.vertexCount*4 - 1]);
|
||||
}
|
||||
|
||||
if (mesh.indices != NULL) // Vertex indices (3 index per triangle - unsigned short)
|
||||
{
|
||||
byteCount += sprintf(txtData + byteCount, "static unsigned short %s_INDEX_DATA[%i] = { ", varFileName, mesh.triangleCount*3);
|
||||
for (int i = 0; i < mesh.triangleCount*3 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%i,\n" : "%i, "), mesh.indices[i]);
|
||||
byteCount += sprintf(txtData + byteCount, "%i };\n", mesh.indices[mesh.triangleCount*3 - 1]);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------
|
||||
|
||||
// NOTE: Text data size exported is determined by '\0' (NULL) character
|
||||
success = SaveFileText(fileName, txtData);
|
||||
|
||||
RL_FREE(txtData);
|
||||
|
||||
//if (success != 0) TRACELOG(LOG_INFO, "FILEIO: [%s] Image as code exported successfully", fileName);
|
||||
//else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to export image as code", fileName);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
#if defined(SUPPORT_FILEFORMAT_OBJ) || defined(SUPPORT_FILEFORMAT_MTL)
|
||||
// Process obj materials
|
||||
static void ProcessMaterialsOBJ(Material *materials, tinyobj_material_t *mats, int materialCount)
|
||||
|
|
@ -5155,16 +5253,29 @@ static Model LoadGLTF(const char *fileName)
|
|||
|
||||
if ((attribute->component_type == cgltf_component_type_r_8u) && (attribute->type == cgltf_type_vec4))
|
||||
{
|
||||
// Init raylib mesh bone ids to copy glTF attribute data
|
||||
// Handle 8-bit unsigned byte, vec4 format
|
||||
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(unsigned char));
|
||||
|
||||
// Load 4 components of unsigned char data type into mesh.boneIds
|
||||
// for cgltf_attribute_type_joints we have:
|
||||
// - data.meshes[0] (256 vertices)
|
||||
// - 256 values, provided as cgltf_type_vec4 of bytes (4 byte per joint, stride 4)
|
||||
LOAD_ATTRIBUTE(attribute, 4, unsigned char, model.meshes[meshIndex].boneIds)
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "MODEL: [%s] Joint attribute data format not supported, use vec4 u8", fileName);
|
||||
else if ((attribute->component_type == cgltf_component_type_r_16u) && (attribute->type == cgltf_type_vec2))
|
||||
{
|
||||
// Handle 16-bit unsigned short, vec2 format
|
||||
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*2, sizeof(unsigned short));
|
||||
LOAD_ATTRIBUTE(attribute, 2, unsigned short, model.meshes[meshIndex].boneIds)
|
||||
}
|
||||
else if ((attribute->component_type == cgltf_component_type_r_32u) && (attribute->type == cgltf_type_vec4))
|
||||
{
|
||||
// Handle 32-bit unsigned int, vec4 format
|
||||
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(unsigned int));
|
||||
LOAD_ATTRIBUTE(attribute, 4, unsigned int, model.meshes[meshIndex].boneIds)
|
||||
}
|
||||
else if ((attribute->component_type == cgltf_component_type_r_32f) && (attribute->type == cgltf_type_vec2))
|
||||
{
|
||||
// Handle 32-bit float, vec2 format
|
||||
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*2, sizeof(float));
|
||||
LOAD_ATTRIBUTE(attribute, 2, float, model.meshes[meshIndex].boneIds)
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "MODEL: [%s] Joint attribute data format not supported", fileName);
|
||||
}
|
||||
else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_weights) // WEIGHTS_n (vec4 / u8, u16, f32)
|
||||
{
|
||||
|
|
|
|||
112
src/rshapes.c
112
src/rshapes.c
|
|
@ -1546,10 +1546,96 @@ void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, fl
|
|||
// Draw spline: linear, minimum 2 points
|
||||
void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
|
||||
{
|
||||
if (pointCount < 2) return;
|
||||
|
||||
#if defined(SUPPORT_SPLINE_MITERS)
|
||||
Vector2 prevNormal = (Vector2){-(points[1].y - points[0].y), (points[1].x - points[0].x)};
|
||||
float prevLength = sqrtf(prevNormal.x*prevNormal.x + prevNormal.y*prevNormal.y);
|
||||
|
||||
if (prevLength > 0.0f)
|
||||
{
|
||||
prevNormal.x /= prevLength;
|
||||
prevNormal.y /= prevLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
prevNormal.x = 0.0f;
|
||||
prevNormal.y = 0.0f;
|
||||
}
|
||||
|
||||
Vector2 prevRadius = { 0.5f*thick*prevNormal.x, 0.5f*thick*prevNormal.y };
|
||||
|
||||
for (int i = 0; i < pointCount - 1; i++)
|
||||
{
|
||||
Vector2 normal = { 0 };
|
||||
|
||||
if (i < pointCount - 2)
|
||||
{
|
||||
normal = (Vector2){-(points[i + 2].y - points[i + 1].y), (points[i + 2].x - points[i + 1].x)};
|
||||
float normalLength = sqrtf(normal.x*normal.x + normal.y*normal.y);
|
||||
|
||||
if (normalLength > 0.0f)
|
||||
{
|
||||
normal.x /= normalLength;
|
||||
normal.y /= normalLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
normal.x = 0.0f;
|
||||
normal.y = 0.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
normal = prevNormal;
|
||||
}
|
||||
|
||||
Vector2 radius = { prevNormal.x + normal.x, prevNormal.y + normal.y };
|
||||
float radiusLength = sqrtf(radius.x*radius.x + radius.y*radius.y);
|
||||
|
||||
if (radiusLength > 0.0f)
|
||||
{
|
||||
radius.x /= radiusLength;
|
||||
radius.y /= radiusLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
radius.x = 0.0f;
|
||||
radius.y = 0.0f;
|
||||
}
|
||||
|
||||
float cosTheta = radius.x*normal.x + radius.y*normal.y;
|
||||
|
||||
if (cosTheta != 0.0f)
|
||||
{
|
||||
radius.x *= (thick*0.5f/cosTheta);
|
||||
radius.y *= (thick*0.5f/cosTheta);
|
||||
}
|
||||
else
|
||||
{
|
||||
radius.x = 0.0f;
|
||||
radius.y = 0.0f;
|
||||
}
|
||||
|
||||
Vector2 strip[4] = {
|
||||
{ points[i].x - prevRadius.x, points[i].y - prevRadius.y },
|
||||
{ points[i].x + prevRadius.x, points[i].y + prevRadius.y },
|
||||
{ points[i + 1].x - radius.x, points[i + 1].y - radius.y },
|
||||
{ points[i + 1].x + radius.x, points[i + 1].y + radius.y }
|
||||
};
|
||||
|
||||
DrawTriangleStrip(strip, 4, color);
|
||||
|
||||
prevRadius = radius;
|
||||
prevNormal = normal;
|
||||
}
|
||||
|
||||
#else // !SUPPORT_SPLINE_MITTERS
|
||||
|
||||
Vector2 delta = { 0 };
|
||||
float length = 0.0f;
|
||||
float scale = 0.0f;
|
||||
|
||||
|
||||
for (int i = 0; i < pointCount - 1; i++)
|
||||
{
|
||||
delta = (Vector2){ points[i + 1].x - points[i].x, points[i + 1].y - points[i].y };
|
||||
|
|
@ -1567,8 +1653,10 @@ void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
|
|||
|
||||
DrawTriangleStrip(strip, 4, color);
|
||||
}
|
||||
#if defined(SUPPORT_SPLINE_SEGMENT_CAPS)
|
||||
#endif
|
||||
|
||||
#if defined(SUPPORT_SPLINE_SEGMENT_CAPS)
|
||||
// TODO: Add spline segment rounded caps at the begin/end of the spline
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -1718,7 +1806,7 @@ void DrawSplineCatmullRom(Vector2 *points, int pointCount, float thick, Color co
|
|||
void DrawSplineBezierQuadratic(Vector2 *points, int pointCount, float thick, Color color)
|
||||
{
|
||||
if (pointCount < 3) return;
|
||||
|
||||
|
||||
for (int i = 0; i < pointCount - 2; i++)
|
||||
{
|
||||
DrawSplineSegmentBezierQuadratic(points[i], points[i + 1], points[i + 2], thick, color);
|
||||
|
|
@ -1729,7 +1817,7 @@ void DrawSplineBezierQuadratic(Vector2 *points, int pointCount, float thick, Col
|
|||
void DrawSplineBezierCubic(Vector2 *points, int pointCount, float thick, Color color)
|
||||
{
|
||||
if (pointCount < 4) return;
|
||||
|
||||
|
||||
for (int i = 0; i < pointCount - 3; i++)
|
||||
{
|
||||
DrawSplineSegmentBezierCubic(points[i], points[i + 1], points[i + 2], points[i + 3], thick, color);
|
||||
|
|
@ -1740,7 +1828,7 @@ void DrawSplineBezierCubic(Vector2 *points, int pointCount, float thick, Color c
|
|||
void DrawSplineSegmentLinear(Vector2 p1, Vector2 p2, float thick, Color color)
|
||||
{
|
||||
// NOTE: For the linear spline we don't use subdivisions, just a single quad
|
||||
|
||||
|
||||
Vector2 delta = { p2.x - p1.x, p2.y - p1.y };
|
||||
float length = sqrtf(delta.x*delta.x + delta.y*delta.y);
|
||||
|
||||
|
|
@ -1768,9 +1856,9 @@ void DrawSplineSegmentBasis(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, floa
|
|||
Vector2 currentPoint = { 0 };
|
||||
Vector2 nextPoint = { 0 };
|
||||
float t = 0.0f;
|
||||
|
||||
|
||||
Vector2 points[2*SPLINE_SEGMENT_DIVISIONS + 2] = { 0 };
|
||||
|
||||
|
||||
float a[4] = { 0 };
|
||||
float b[4] = { 0 };
|
||||
|
||||
|
|
@ -1825,7 +1913,7 @@ void DrawSplineSegmentCatmullRom(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
|
|||
Vector2 currentPoint = p1;
|
||||
Vector2 nextPoint = { 0 };
|
||||
float t = 0.0f;
|
||||
|
||||
|
||||
Vector2 points[2*SPLINE_SEGMENT_DIVISIONS + 2] = { 0 };
|
||||
|
||||
for (int i = 0; i <= SPLINE_SEGMENT_DIVISIONS; i++)
|
||||
|
|
@ -2132,11 +2220,11 @@ bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec)
|
|||
{
|
||||
bool collision = false;
|
||||
|
||||
int recCenterX = (int)(rec.x + rec.width/2.0f);
|
||||
int recCenterY = (int)(rec.y + rec.height/2.0f);
|
||||
float recCenterX = rec.x + rec.width/2.0f;
|
||||
float recCenterY = rec.y + rec.height/2.0f;
|
||||
|
||||
float dx = fabsf(center.x - (float)recCenterX);
|
||||
float dy = fabsf(center.y - (float)recCenterY);
|
||||
float dx = fabsf(center.x - recCenterX);
|
||||
float dy = fabsf(center.y - recCenterY);
|
||||
|
||||
if (dx > (rec.width/2.0f + radius)) { return false; }
|
||||
if (dy > (rec.height/2.0f + radius)) { return false; }
|
||||
|
|
|
|||
246
src/rtext.c
246
src/rtext.c
|
|
@ -604,7 +604,6 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
|
|||
|
||||
// Fill fontChars in case not provided externally
|
||||
// NOTE: By default we fill glyphCount consecutively, starting at 32 (Space)
|
||||
|
||||
if (codepoints == NULL)
|
||||
{
|
||||
codepoints = (int *)RL_MALLOC(codepointCount*sizeof(int));
|
||||
|
|
@ -612,7 +611,7 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
|
|||
genFontChars = true;
|
||||
}
|
||||
|
||||
chars = (GlyphInfo *)RL_MALLOC(codepointCount*sizeof(GlyphInfo));
|
||||
chars = (GlyphInfo *)RL_CALLOC(codepointCount, sizeof(GlyphInfo));
|
||||
|
||||
// NOTE: Using simple packaging, one char after another
|
||||
for (int i = 0; i < codepointCount; i++)
|
||||
|
|
@ -626,54 +625,67 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
|
|||
// stbtt_GetCodepointBitmapBox() -- how big the bitmap must be
|
||||
// stbtt_MakeCodepointBitmap() -- renders into bitmap you provide
|
||||
|
||||
if (type != FONT_SDF) chars[i].image.data = stbtt_GetCodepointBitmap(&fontInfo, scaleFactor, scaleFactor, ch, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY);
|
||||
else if (ch != 32) chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, FONT_SDF_CHAR_PADDING, FONT_SDF_ON_EDGE_VALUE, FONT_SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY);
|
||||
else chars[i].image.data = NULL;
|
||||
// Check if a glyph is available in the font
|
||||
// WARNING: if (index == 0), glyph not found, it could fallback to default .notdef glyph (if defined in font)
|
||||
int index = stbtt_FindGlyphIndex(&fontInfo, ch);
|
||||
|
||||
stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL);
|
||||
chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor);
|
||||
|
||||
// Load characters images
|
||||
chars[i].image.width = chw;
|
||||
chars[i].image.height = chh;
|
||||
chars[i].image.mipmaps = 1;
|
||||
chars[i].image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
|
||||
|
||||
chars[i].offsetY += (int)((float)ascent*scaleFactor);
|
||||
|
||||
// NOTE: We create an empty image for space character, it could be further required for atlas packing
|
||||
if (ch == 32)
|
||||
if (index > 0)
|
||||
{
|
||||
Image imSpace = {
|
||||
.data = RL_CALLOC(chars[i].advanceX*fontSize, 2),
|
||||
.width = chars[i].advanceX,
|
||||
.height = fontSize,
|
||||
.mipmaps = 1,
|
||||
.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE
|
||||
};
|
||||
|
||||
chars[i].image = imSpace;
|
||||
}
|
||||
|
||||
if (type == FONT_BITMAP)
|
||||
{
|
||||
// Aliased bitmap (black & white) font generation, avoiding anti-aliasing
|
||||
// NOTE: For optimum results, bitmap font should be generated at base pixel size
|
||||
for (int p = 0; p < chw*chh; p++)
|
||||
switch (type)
|
||||
{
|
||||
if (((unsigned char *)chars[i].image.data)[p] < FONT_BITMAP_ALPHA_THRESHOLD) ((unsigned char *)chars[i].image.data)[p] = 0;
|
||||
else ((unsigned char *)chars[i].image.data)[p] = 255;
|
||||
case FONT_DEFAULT:
|
||||
case FONT_BITMAP: chars[i].image.data = stbtt_GetCodepointBitmap(&fontInfo, scaleFactor, scaleFactor, ch, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY); break;
|
||||
case FONT_SDF: if (ch != 32) chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, FONT_SDF_CHAR_PADDING, FONT_SDF_ON_EDGE_VALUE, FONT_SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (chars[i].image.data != NULL) // Glyph data has been found in the font
|
||||
{
|
||||
stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL);
|
||||
chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor);
|
||||
|
||||
// Load characters images
|
||||
chars[i].image.width = chw;
|
||||
chars[i].image.height = chh;
|
||||
chars[i].image.mipmaps = 1;
|
||||
chars[i].image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
|
||||
|
||||
chars[i].offsetY += (int)((float)ascent*scaleFactor);
|
||||
}
|
||||
|
||||
// NOTE: We create an empty image for space character,
|
||||
// it could be further required for atlas packing
|
||||
if (ch == 32)
|
||||
{
|
||||
stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL);
|
||||
chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor);
|
||||
|
||||
Image imSpace = {
|
||||
.data = RL_CALLOC(chars[i].advanceX*fontSize, 2),
|
||||
.width = chars[i].advanceX,
|
||||
.height = fontSize,
|
||||
.mipmaps = 1,
|
||||
.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE
|
||||
};
|
||||
|
||||
chars[i].image = imSpace;
|
||||
}
|
||||
|
||||
if (type == FONT_BITMAP)
|
||||
{
|
||||
// Aliased bitmap (black & white) font generation, avoiding anti-aliasing
|
||||
// NOTE: For optimum results, bitmap font should be generated at base pixel size
|
||||
for (int p = 0; p < chw*chh; p++)
|
||||
{
|
||||
if (((unsigned char *)chars[i].image.data)[p] < FONT_BITMAP_ALPHA_THRESHOLD) ((unsigned char *)chars[i].image.data)[p] = 0;
|
||||
else ((unsigned char *)chars[i].image.data)[p] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get bounding box for character (maybe offset to account for chars that dip above or below the line)
|
||||
/*
|
||||
int chX1, chY1, chX2, chY2;
|
||||
stbtt_GetCodepointBitmapBox(&fontInfo, ch, scaleFactor, scaleFactor, &chX1, &chY1, &chX2, &chY2);
|
||||
|
||||
TRACELOGD("FONT: Character box measures: %i, %i, %i, %i", chX1, chY1, chX2 - chX1, chY2 - chY1);
|
||||
TRACELOGD("FONT: Character offsetY: %i", (int)((float)ascent*scaleFactor) + chY1);
|
||||
*/
|
||||
else
|
||||
{
|
||||
// TODO: Use some fallback glyph for codepoints not found in the font
|
||||
}
|
||||
}
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "FONT: Failed to process TTF font data");
|
||||
|
|
@ -1409,6 +1421,28 @@ int TextToInteger(const char *text)
|
|||
return value*sign;
|
||||
}
|
||||
|
||||
float TextToFloat(const char *text)
|
||||
{
|
||||
float value = 0.0f;
|
||||
float sign = 1.0f;
|
||||
|
||||
if ((text[0] == '+') || (text[0] == '-'))
|
||||
{
|
||||
if (text[0] == '-') sign = -1;
|
||||
text++;
|
||||
}
|
||||
int i = 0;
|
||||
for (; ((text[i] >= '0') && (text[i] <= '9')); ++i) value = value*10.0f + (float)(text[i] - '0');
|
||||
if (text[i++] != '.') return value*sign;
|
||||
float divisor = 10.0f;
|
||||
for (; ((text[i] >= '0') && (text[i] <= '9')); ++i)
|
||||
{
|
||||
value += ((float)(text[i] - '0'))/divisor;
|
||||
divisor = divisor*10.0f;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
#if defined(SUPPORT_TEXT_MANIPULATION)
|
||||
// Copy one string to another, returns bytes copied
|
||||
int TextCopy(char *dst, const char *src)
|
||||
|
|
@ -2017,7 +2051,8 @@ static int GetLine(const char *origin, char *buffer, int maxLength)
|
|||
// REQUIRES: strstr(), sscanf(), strrchr(), memcpy()
|
||||
static Font LoadBMFont(const char *fileName)
|
||||
{
|
||||
#define MAX_BUFFER_SIZE 256
|
||||
#define MAX_BUFFER_SIZE 256
|
||||
#define MAX_FONT_IMAGE_PAGES 8
|
||||
|
||||
Font font = { 0 };
|
||||
|
||||
|
|
@ -2029,7 +2064,8 @@ static Font LoadBMFont(const char *fileName)
|
|||
|
||||
int imWidth = 0;
|
||||
int imHeight = 0;
|
||||
char imFileName[129] = { 0 };
|
||||
int pageCount = 1;
|
||||
char imFileName[MAX_FONT_IMAGE_PAGES][129] = { 0 };
|
||||
|
||||
int base = 0; // Useless data
|
||||
int readBytes = 0; // Data bytes read
|
||||
|
|
@ -2048,17 +2084,26 @@ static Font LoadBMFont(const char *fileName)
|
|||
// Read line data
|
||||
readBytes = GetLine(fileTextPtr, buffer, MAX_BUFFER_SIZE);
|
||||
searchPoint = strstr(buffer, "lineHeight");
|
||||
readVars = sscanf(searchPoint, "lineHeight=%i base=%i scaleW=%i scaleH=%i", &fontSize, &base, &imWidth, &imHeight);
|
||||
readVars = sscanf(searchPoint, "lineHeight=%i base=%i scaleW=%i scaleH=%i pages=%i", &fontSize, &base, &imWidth, &imHeight, &pageCount);
|
||||
fileTextPtr += (readBytes + 1);
|
||||
|
||||
if (readVars < 4) { UnloadFileText(fileText); return font; } // Some data not available, file malformed
|
||||
|
||||
if (pageCount > MAX_FONT_IMAGE_PAGES)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "FONT: [%s] Font defines more pages than supported: %i/%i", fileName, pageCount, MAX_FONT_IMAGE_PAGES);
|
||||
pageCount = MAX_FONT_IMAGE_PAGES;
|
||||
}
|
||||
|
||||
readBytes = GetLine(fileTextPtr, buffer, MAX_BUFFER_SIZE);
|
||||
searchPoint = strstr(buffer, "file");
|
||||
readVars = sscanf(searchPoint, "file=\"%128[^\"]\"", imFileName);
|
||||
fileTextPtr += (readBytes + 1);
|
||||
for (int i = 0; i < pageCount; i++)
|
||||
{
|
||||
readBytes = GetLine(fileTextPtr, buffer, MAX_BUFFER_SIZE);
|
||||
searchPoint = strstr(buffer, "file");
|
||||
readVars = sscanf(searchPoint, "file=\"%128[^\"]\"", imFileName[i]);
|
||||
fileTextPtr += (readBytes + 1);
|
||||
|
||||
if (readVars < 1) { UnloadFileText(fileText); return font; } // No fileName read
|
||||
if (readVars < 1) { UnloadFileText(fileText); return font; } // No fileName read
|
||||
}
|
||||
|
||||
readBytes = GetLine(fileTextPtr, buffer, MAX_BUFFER_SIZE);
|
||||
searchPoint = strstr(buffer, "count");
|
||||
|
|
@ -2067,50 +2112,56 @@ static Font LoadBMFont(const char *fileName)
|
|||
|
||||
if (readVars < 1) { UnloadFileText(fileText); return font; } // No glyphCount read
|
||||
|
||||
// Compose correct path using route of .fnt file (fileName) and imFileName
|
||||
char *imPath = NULL;
|
||||
char *lastSlash = NULL;
|
||||
// Load all required images for further compose
|
||||
Image *imFonts = (Image *)RL_CALLOC(pageCount, sizeof(Image)); // Font atlases, multiple images
|
||||
|
||||
lastSlash = strrchr(fileName, '/');
|
||||
if (lastSlash == NULL) lastSlash = strrchr(fileName, '\\');
|
||||
|
||||
if (lastSlash != NULL)
|
||||
for (int i = 0; i < pageCount; i++)
|
||||
{
|
||||
// NOTE: We need some extra space to avoid memory corruption on next allocations!
|
||||
imPath = (char *)RL_CALLOC(TextLength(fileName) - TextLength(lastSlash) + TextLength(imFileName) + 4, 1);
|
||||
memcpy(imPath, fileName, TextLength(fileName) - TextLength(lastSlash) + 1);
|
||||
memcpy(imPath + TextLength(fileName) - TextLength(lastSlash) + 1, imFileName, TextLength(imFileName));
|
||||
}
|
||||
else imPath = imFileName;
|
||||
imFonts[i] = LoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i]));
|
||||
|
||||
TRACELOGD(" > Image loading path: %s", imPath);
|
||||
|
||||
Image imFont = LoadImage(imPath);
|
||||
|
||||
if (imFont.format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)
|
||||
{
|
||||
// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
|
||||
Image imFontAlpha = {
|
||||
.data = RL_CALLOC(imFont.width*imFont.height, 2),
|
||||
.width = imFont.width,
|
||||
.height = imFont.height,
|
||||
.mipmaps = 1,
|
||||
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
|
||||
};
|
||||
|
||||
for (int p = 0, i = 0; p < (imFont.width*imFont.height*2); p += 2, i++)
|
||||
if (imFonts[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)
|
||||
{
|
||||
((unsigned char *)(imFontAlpha.data))[p] = 0xff;
|
||||
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFont.data)[i];
|
||||
}
|
||||
// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
|
||||
Image imFontAlpha = {
|
||||
.data = RL_CALLOC(imFonts[i].width*imFonts[i].height, 2),
|
||||
.width = imFonts[i].width,
|
||||
.height = imFonts[i].height,
|
||||
.mipmaps = 1,
|
||||
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
|
||||
};
|
||||
|
||||
UnloadImage(imFont);
|
||||
imFont = imFontAlpha;
|
||||
for (int p = 0, pi = 0; p < (imFonts[i].width*imFonts[i].height*2); p += 2, pi++)
|
||||
{
|
||||
((unsigned char *)(imFontAlpha.data))[p] = 0xff;
|
||||
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFonts[i].data)[pi];
|
||||
}
|
||||
|
||||
UnloadImage(imFonts[i]);
|
||||
imFonts[i] = imFontAlpha;
|
||||
}
|
||||
}
|
||||
|
||||
font.texture = LoadTextureFromImage(imFont);
|
||||
Image fullFont = imFonts[0];
|
||||
for (int i = 1; i < pageCount; i++) UnloadImage(imFonts[i]);
|
||||
|
||||
if (lastSlash != NULL) RL_FREE(imPath);
|
||||
// If multiple atlas, then merge atlas
|
||||
// NOTE: WARNING: This process could be really slow!
|
||||
if (pageCount > 1)
|
||||
{
|
||||
// Resize font atlas to draw additional images
|
||||
ImageResizeCanvas(&fullFont, imWidth, imHeight*pageCount, 0, 0, BLACK);
|
||||
|
||||
for (int i = 1; i < pageCount; i++)
|
||||
{
|
||||
Rectangle srcRec = { 0.0f, 0.0f, (float)imWidth, (float)imHeight };
|
||||
Rectangle destRec = { 0.0f, (float)imHeight*(float)i, (float)imWidth, (float)imHeight };
|
||||
ImageDraw(&fullFont, imFonts[i], srcRec, destRec, WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
RL_FREE(imFonts);
|
||||
|
||||
font.texture = LoadTextureFromImage(fullFont);
|
||||
|
||||
// Fill font characters info data
|
||||
font.baseSize = fontSize;
|
||||
|
|
@ -2119,19 +2170,19 @@ static Font LoadBMFont(const char *fileName)
|
|||
font.glyphs = (GlyphInfo *)RL_MALLOC(glyphCount*sizeof(GlyphInfo));
|
||||
font.recs = (Rectangle *)RL_MALLOC(glyphCount*sizeof(Rectangle));
|
||||
|
||||
int charId, charX, charY, charWidth, charHeight, charOffsetX, charOffsetY, charAdvanceX;
|
||||
int charId, charX, charY, charWidth, charHeight, charOffsetX, charOffsetY, charAdvanceX, pageID;
|
||||
|
||||
for (int i = 0; i < glyphCount; i++)
|
||||
{
|
||||
readBytes = GetLine(fileTextPtr, buffer, MAX_BUFFER_SIZE);
|
||||
readVars = sscanf(buffer, "char id=%i x=%i y=%i width=%i height=%i xoffset=%i yoffset=%i xadvance=%i",
|
||||
&charId, &charX, &charY, &charWidth, &charHeight, &charOffsetX, &charOffsetY, &charAdvanceX);
|
||||
readVars = sscanf(buffer, "char id=%i x=%i y=%i width=%i height=%i xoffset=%i yoffset=%i xadvance=%i page=%i",
|
||||
&charId, &charX, &charY, &charWidth, &charHeight, &charOffsetX, &charOffsetY, &charAdvanceX, &pageID);
|
||||
fileTextPtr += (readBytes + 1);
|
||||
|
||||
if (readVars == 8) // Make sure all char data has been properly read
|
||||
if (readVars == 9) // Make sure all char data has been properly read
|
||||
{
|
||||
// Get character rectangle in the font atlas texture
|
||||
font.recs[i] = (Rectangle){ (float)charX, (float)charY, (float)charWidth, (float)charHeight };
|
||||
font.recs[i] = (Rectangle){ (float)charX, (float)charY + (float)imHeight*pageID, (float)charWidth, (float)charHeight };
|
||||
|
||||
// Save data properly in sprite font
|
||||
font.glyphs[i].value = charId;
|
||||
|
|
@ -2139,13 +2190,13 @@ static Font LoadBMFont(const char *fileName)
|
|||
font.glyphs[i].offsetY = charOffsetY;
|
||||
font.glyphs[i].advanceX = charAdvanceX;
|
||||
|
||||
// Fill character image data from imFont data
|
||||
font.glyphs[i].image = ImageFromImage(imFont, font.recs[i]);
|
||||
// Fill character image data from full font data
|
||||
font.glyphs[i].image = ImageFromImage(fullFont, font.recs[i]);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "FONT: [%s] Some characters data not correctly provided", fileName);
|
||||
}
|
||||
|
||||
UnloadImage(imFont);
|
||||
UnloadImage(fullFont);
|
||||
UnloadFileText(fileText);
|
||||
|
||||
if (font.texture.id == 0)
|
||||
|
|
@ -2158,6 +2209,7 @@ static Font LoadBMFont(const char *fileName)
|
|||
|
||||
return font;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // SUPPORT_MODULE_RTEXT
|
||||
|
|
|
|||
200
src/rtextures.c
200
src/rtextures.c
|
|
@ -213,14 +213,14 @@
|
|||
#define STBIR_MALLOC(size,c) ((void)(c), RL_MALLOC(size))
|
||||
#define STBIR_FREE(ptr,c) ((void)(c), RL_FREE(ptr))
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
#include "external/stb_image_resize2.h" // Required for: stbir_resize_uint8_linear() [ImageResize()]
|
||||
#include "external/stb_image_resize2.h" // Required for: stbir_resize_uint8_linear() [ImageResize()]
|
||||
|
||||
#if defined(SUPPORT_FILEFORMAT_SVG)
|
||||
#define NANOSVG_IMPLEMENTATION // Expands implementation
|
||||
#include "external/nanosvg.h"
|
||||
#define NANOSVG_IMPLEMENTATION // Expands implementation
|
||||
#include "external/nanosvg.h"
|
||||
|
||||
#define NANOSVGRAST_IMPLEMENTATION
|
||||
#include "external/nanosvgrast.h"
|
||||
#define NANOSVGRAST_IMPLEMENTATION
|
||||
#include "external/nanosvgrast.h"
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -1959,29 +1959,24 @@ void ImageBlurGaussian(Image *image, int blurSize) {
|
|||
float avgG = 0.0f;
|
||||
float avgB = 0.0f;
|
||||
float avgAlpha = 0.0f;
|
||||
int convolutionSize = blurSize+1;
|
||||
int convolutionSize = blurSize;
|
||||
|
||||
for (int i = 0; i < blurSize+1; i++)
|
||||
for (int i = 0; i < blurSize; 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++)
|
||||
for (int x = 0; x < image->width; x++)
|
||||
{
|
||||
if (x-blurSize >= 0)
|
||||
if (x-blurSize-1 >= 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;
|
||||
avgR -= pixelsCopy1[row*image->width + x-blurSize-1].x;
|
||||
avgG -= pixelsCopy1[row*image->width + x-blurSize-1].y;
|
||||
avgB -= pixelsCopy1[row*image->width + x-blurSize-1].z;
|
||||
avgAlpha -= pixelsCopy1[row*image->width + x-blurSize-1].w;
|
||||
convolutionSize--;
|
||||
}
|
||||
|
||||
|
|
@ -1999,7 +1994,7 @@ void ImageBlurGaussian(Image *image, int blurSize) {
|
|||
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++)
|
||||
|
|
@ -2008,9 +2003,9 @@ void ImageBlurGaussian(Image *image, int blurSize) {
|
|||
float avgG = 0.0f;
|
||||
float avgB = 0.0f;
|
||||
float avgAlpha = 0.0f;
|
||||
int convolutionSize = blurSize+1;
|
||||
int convolutionSize = blurSize;
|
||||
|
||||
for (int i = 0; i < blurSize+1; i++)
|
||||
for (int i = 0; i < blurSize; i++)
|
||||
{
|
||||
avgR += pixelsCopy2[i*image->width + col].x;
|
||||
avgG += pixelsCopy2[i*image->width + col].y;
|
||||
|
|
@ -2018,19 +2013,14 @@ void ImageBlurGaussian(Image *image, int blurSize) {
|
|||
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++)
|
||||
for (int y = 0; y < image->height; y++)
|
||||
{
|
||||
if (y-blurSize >= 0)
|
||||
if (y-blurSize-1 >= 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;
|
||||
avgR -= pixelsCopy2[(y-blurSize-1)*image->width + col].x;
|
||||
avgG -= pixelsCopy2[(y-blurSize-1)*image->width + col].y;
|
||||
avgB -= pixelsCopy2[(y-blurSize-1)*image->width + col].z;
|
||||
avgAlpha -= pixelsCopy2[(y-blurSize-1)*image->width + col].w;
|
||||
convolutionSize--;
|
||||
}
|
||||
if (y+blurSize < image->height)
|
||||
|
|
@ -2082,6 +2072,148 @@ void ImageBlurGaussian(Image *image, int blurSize) {
|
|||
ImageFormat(image, format);
|
||||
}
|
||||
|
||||
// The kernel matrix is assumed to be square. Only supply the width of the kernel.
|
||||
void ImageKernelConvolution(Image *image, float* kernel, int kernelSize){
|
||||
|
||||
if ((image->data == NULL) || (image->width == 0) || (image->height == 0) || kernel == NULL) return;
|
||||
|
||||
int kernelWidth = (int)sqrtf((float)kernelSize);
|
||||
if (kernelWidth*kernelWidth != kernelSize)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "IMAGE: Convolution kernel must be square to be applied");
|
||||
return;
|
||||
}
|
||||
|
||||
Color *pixels = LoadImageColors(*image);
|
||||
|
||||
Vector4 *imageCopy2 = RL_MALLOC((image->height)*(image->width)*sizeof(Vector4));
|
||||
Vector4 *temp = RL_MALLOC(kernelSize*sizeof(Vector4));
|
||||
|
||||
|
||||
for(int i = 0; i < kernelSize; i++){
|
||||
temp[i].x = 0.0f;
|
||||
temp[i].y = 0.0f;
|
||||
temp[i].z = 0.0f;
|
||||
temp[i].w = 0.0f;
|
||||
}
|
||||
|
||||
float rRes = 0.0f;
|
||||
float gRes = 0.0f;
|
||||
float bRes = 0.0f;
|
||||
float aRes = 0.0f;
|
||||
|
||||
|
||||
int startRange, endRange;
|
||||
if(kernelWidth % 2 == 0)
|
||||
{
|
||||
startRange = -kernelWidth/2;
|
||||
endRange = kernelWidth/2;
|
||||
} else
|
||||
{
|
||||
startRange = -kernelWidth/2;
|
||||
endRange = kernelWidth/2+1;
|
||||
}
|
||||
for(int x = 0; x < image->height; x++)
|
||||
{
|
||||
for(int y = 0; y < image->width; y++)
|
||||
{
|
||||
|
||||
for(int xk = startRange; xk < endRange; xk++)
|
||||
{
|
||||
for(int yk = startRange; yk < endRange; yk++)
|
||||
{
|
||||
int xkabs = xk + kernelWidth/2;
|
||||
int ykabs = yk + kernelWidth/2;
|
||||
size_t imgindex = image->width * (x+xk) + (y+yk);
|
||||
if(imgindex < 0 || imgindex >= image->width * image->height){
|
||||
temp[kernelWidth * xkabs + ykabs].x = 0.0f;
|
||||
temp[kernelWidth * xkabs + ykabs].y = 0.0f;
|
||||
temp[kernelWidth * xkabs + ykabs].z = 0.0f;
|
||||
temp[kernelWidth * xkabs + ykabs].w = 0.0f;
|
||||
} else {
|
||||
temp[kernelWidth * xkabs + ykabs].x = ((float)pixels[imgindex].r)/255.0f * kernel[kernelWidth * xkabs + ykabs];
|
||||
temp[kernelWidth * xkabs + ykabs].y = ((float)pixels[imgindex].g)/255.0f * kernel[kernelWidth * xkabs + ykabs];
|
||||
temp[kernelWidth * xkabs + ykabs].z = ((float)pixels[imgindex].b)/255.0f * kernel[kernelWidth * xkabs + ykabs];
|
||||
temp[kernelWidth * xkabs + ykabs].w = ((float)pixels[imgindex].a)/255.0f * kernel[kernelWidth * xkabs + ykabs];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < kernelSize; i++)
|
||||
{
|
||||
rRes += temp[i].x;
|
||||
gRes += temp[i].y;
|
||||
bRes += temp[i].z;
|
||||
aRes += temp[i].w;
|
||||
}
|
||||
|
||||
if(rRes < 0.0f)
|
||||
{
|
||||
rRes = 0.0f;
|
||||
}
|
||||
if(gRes < 0.0f)
|
||||
{
|
||||
gRes = 0.0f;
|
||||
}
|
||||
if(bRes < 0.0f)
|
||||
{
|
||||
bRes = 0.0f;
|
||||
}
|
||||
|
||||
if(rRes > 1.0f)
|
||||
{
|
||||
rRes = 1.0f;
|
||||
}
|
||||
if(gRes > 1.0f)
|
||||
{
|
||||
gRes = 1.0f;
|
||||
}
|
||||
if(bRes > 1.0f)
|
||||
{
|
||||
bRes = 1.0f;
|
||||
}
|
||||
|
||||
imageCopy2[image->width * (x) + (y)].x = rRes;
|
||||
imageCopy2[image->width * (x) + (y)].y = gRes;
|
||||
imageCopy2[image->width * (x) + (y)].z = bRes;
|
||||
imageCopy2[image->width * (x) + (y)].w = aRes;
|
||||
|
||||
rRes = 0.0f;
|
||||
gRes = 0.0f;
|
||||
bRes = 0.0f;
|
||||
aRes = 0.0f;
|
||||
|
||||
for(int i = 0; i < kernelSize; i++)
|
||||
{
|
||||
temp[i].x = 0.0f;
|
||||
temp[i].y = 0.0f;
|
||||
temp[i].z = 0.0f;
|
||||
temp[i].w = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < (image->width) * (image->height); i++)
|
||||
{
|
||||
float alpha = (float)imageCopy2[i].w;
|
||||
pixels[i].r = (unsigned char)((imageCopy2[i].x)*255.0f);
|
||||
pixels[i].g = (unsigned char)((imageCopy2[i].y)*255.0f);
|
||||
pixels[i].b = (unsigned char)((imageCopy2[i].z)*255.0f);
|
||||
pixels[i].a = (unsigned char)((alpha)*255.0f);
|
||||
// printf("pixels[%d] = %d", i, pixels[i].r);
|
||||
}
|
||||
|
||||
|
||||
int format = image->format;
|
||||
RL_FREE(image->data);
|
||||
RL_FREE(imageCopy2);
|
||||
RL_FREE(temp);
|
||||
|
||||
image->data = pixels;
|
||||
image->format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
ImageFormat(image, format);
|
||||
}
|
||||
|
||||
// Generate all mipmap levels for a provided image
|
||||
// NOTE 1: Supports POT and NPOT images
|
||||
// NOTE 2: image.data is scaled to include mipmap levels
|
||||
|
|
@ -3564,7 +3696,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
|
|||
// Draw text (default font) within an image (destination)
|
||||
void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color)
|
||||
{
|
||||
#if defined(SUPPORT_MODULE_RTEXT)
|
||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
||||
// Make sure default font is loaded to be used on image text drawing
|
||||
if (GetFontDefault().texture.id == 0) LoadFontDefault();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue