aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--raylib/config.h5
-rw-r--r--raylib/raymath.h20
-rw-r--r--raylib/rcamera.h28
-rw-r--r--raylib/rcore.c13
-rw-r--r--raylib/rgestures.h38
-rw-r--r--raylib/rtext.c29
6 files changed, 86 insertions, 47 deletions
diff --git a/raylib/config.h b/raylib/config.h
index 0af7226..c59e57d 100644
--- a/raylib/config.h
+++ b/raylib/config.h
@@ -181,6 +181,11 @@
// If not defined, still some functions are supported: TextLength(), TextFormat()
#define SUPPORT_TEXT_MANIPULATION 1
+// On font atlas image generation [GenImageFontAtlas()], add a 3x3 pixels white rectangle
+// at the bottom-right corner of the atlas. It can be useful to for shapes drawing, to allow
+// drawing text and shapes with a single draw call [SetShapesTexture()].
+#define SUPPORT_FONT_ATLAS_WHITE_REC 1
+
// rtext: Configuration values
//------------------------------------------------------------------------------------
#define MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers used on some functions:
diff --git a/raylib/raymath.h b/raylib/raymath.h
index d7ec1d2..9281691 100644
--- a/raylib/raymath.h
+++ b/raylib/raymath.h
@@ -1509,11 +1509,11 @@ RMAPI Matrix MatrixFrustum(double left, double right, double bottom, double top,
// Get perspective projection matrix
// NOTE: Fovy angle must be provided in radians
-RMAPI Matrix MatrixPerspective(double fovy, double aspect, double near, double far)
+RMAPI Matrix MatrixPerspective(double fovY, double aspect, double nearPlane, double farPlane)
{
Matrix result = { 0 };
- double top = near*tan(fovy*0.5);
+ double top = nearPlane*tan(fovY*0.5);
double bottom = -top;
double right = top*aspect;
double left = -right;
@@ -1521,27 +1521,27 @@ RMAPI Matrix MatrixPerspective(double fovy, double aspect, double near, double f
// MatrixFrustum(-right, right, -top, top, near, far);
float rl = (float)(right - left);
float tb = (float)(top - bottom);
- float fn = (float)(far - near);
+ float fn = (float)(farPlane - nearPlane);
- result.m0 = ((float)near*2.0f)/rl;
- result.m5 = ((float)near*2.0f)/tb;
+ result.m0 = ((float)nearPlane*2.0f)/rl;
+ result.m5 = ((float)nearPlane*2.0f)/tb;
result.m8 = ((float)right + (float)left)/rl;
result.m9 = ((float)top + (float)bottom)/tb;
- result.m10 = -((float)far + (float)near)/fn;
+ result.m10 = -((float)farPlane + (float)nearPlane)/fn;
result.m11 = -1.0f;
- result.m14 = -((float)far*(float)near*2.0f)/fn;
+ result.m14 = -((float)farPlane*(float)nearPlane*2.0f)/fn;
return result;
}
// Get orthographic projection matrix
-RMAPI Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far)
+RMAPI Matrix MatrixOrtho(double left, double right, double bottom, double top, double nearPlane, double farPlane)
{
Matrix result = { 0 };
float rl = (float)(right - left);
float tb = (float)(top - bottom);
- float fn = (float)(far - near);
+ float fn = (float)(farPlane - nearPlane);
result.m0 = 2.0f/rl;
result.m1 = 0.0f;
@@ -1557,7 +1557,7 @@ RMAPI Matrix MatrixOrtho(double left, double right, double bottom, double top, d
result.m11 = 0.0f;
result.m12 = -((float)left + (float)right)/rl;
result.m13 = -((float)top + (float)bottom)/tb;
- result.m14 = -((float)far + (float)near)/fn;
+ result.m14 = -((float)farPlane + (float)nearPlane)/fn;
result.m15 = 1.0f;
return result;
diff --git a/raylib/rcamera.h b/raylib/rcamera.h
index 2a20d58..c538268 100644
--- a/raylib/rcamera.h
+++ b/raylib/rcamera.h
@@ -3,12 +3,12 @@
* rcamera - Basic camera system with support for multiple camera modes
*
* CONFIGURATION:
-* #define CAMERA_IMPLEMENTATION
+* #define RCAMERA_IMPLEMENTATION
* Generates the implementation of the library into the included file.
* If not defined, the library is in header only mode and can be included in other headers
* or source files without problems. But only ONE file should hold the implementation.
*
-* #define CAMERA_STANDALONE
+* #define RCAMERA_STANDALONE
* If defined, the library can be used as standalone as a camera system but some
* functions must be redefined to manage inputs accordingly.
*
@@ -50,7 +50,7 @@
#define RLAPI // Functions defined as 'extern' by default (implicit specifiers)
#endif
-#if defined(CAMERA_STANDALONE)
+#if defined(RCAMERA_STANDALONE)
#define CAMERA_CULL_DISTANCE_NEAR 0.01
#define CAMERA_CULL_DISTANCE_FAR 1000.0
#else
@@ -60,9 +60,9 @@
//----------------------------------------------------------------------------------
// Types and Structures Definition
-// NOTE: Below types are required for CAMERA_STANDALONE usage
+// NOTE: Below types are required for standalone usage
//----------------------------------------------------------------------------------
-#if defined(CAMERA_STANDALONE)
+#if defined(RCAMERA_STANDALONE)
// Vector2, 2 components
typedef struct Vector2 {
float x; // Vector x component
@@ -76,6 +76,14 @@
float z; // Vector z component
} Vector3;
+ // Matrix, 4x4 components, column major, OpenGL style, right-handed
+ typedef struct Matrix {
+ float m0, m4, m8, m12; // Matrix first row (4 components)
+ float m1, m5, m9, m13; // Matrix second row (4 components)
+ float m2, m6, m10, m14; // Matrix third row (4 components)
+ float m3, m7, m11, m15; // Matrix fourth row (4 components)
+ } Matrix;
+
// Camera type, defines a camera position/orientation in 3d space
typedef struct Camera3D {
Vector3 position; // Camera position
@@ -138,7 +146,7 @@ RLAPI Matrix GetCameraProjectionMatrix(Camera* camera, float aspect);
}
#endif
-#endif // CAMERA_H
+#endif // RCAMERA_H
/***********************************************************************************
@@ -147,7 +155,7 @@ RLAPI Matrix GetCameraProjectionMatrix(Camera* camera, float aspect);
*
************************************************************************************/
-#if defined(CAMERA_IMPLEMENTATION)
+#if defined(RCAMERA_IMPLEMENTATION)
#include "raymath.h" // Required for vector maths:
// Vector3Add()
@@ -417,7 +425,7 @@ Matrix GetCameraProjectionMatrix(Camera *camera, float aspect)
return MatrixIdentity();
}
-#ifndef CAMERA_STANDALONE
+#if !defined(RCAMERA_STANDALONE)
// Update camera position for selected mode
// Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM
void UpdateCamera(Camera *camera, int mode)
@@ -483,7 +491,7 @@ void UpdateCamera(Camera *camera, int mode)
if (IsKeyPressed(KEY_KP_ADD)) CameraMoveToTarget(camera, -2.0f);
}
}
-#endif // !CAMERA_STANDALONE
+#endif // !RCAMERA_STANDALONE
// Update camera movement, movement/rotation values should be provided by user
void UpdateCameraPro(Camera *camera, Vector3 movement, Vector3 rotation, float zoom)
@@ -516,4 +524,4 @@ void UpdateCameraPro(Camera *camera, Vector3 movement, Vector3 rotation, float z
CameraMoveToTarget(camera, zoom);
}
-#endif // CAMERA_IMPLEMENTATION
+#endif // RCAMERA_IMPLEMENTATION
diff --git a/raylib/rcore.c b/raylib/rcore.c
index 6ef25c0..45495bb 100644
--- a/raylib/rcore.c
+++ b/raylib/rcore.c
@@ -124,12 +124,12 @@
#include "raymath.h" // Vector3, Quaternion and Matrix functionality
#if defined(SUPPORT_GESTURES_SYSTEM)
- #define GESTURES_IMPLEMENTATION
+ #define RGESTURES_IMPLEMENTATION
#include "rgestures.h" // Gestures detection functionality
#endif
#if defined(SUPPORT_CAMERA_SYSTEM)
- #define CAMERA_IMPLEMENTATION
+ #define RCAMERA_IMPLEMENTATION
#include "rcamera.h" // Camera system functionality
#endif
@@ -5593,8 +5593,14 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
+#if defined(PLATFORM_WEB)
+ // Prevent calling ProcessGestureEvent() when Emscripten is present and there's a touch gesture, so EmscriptenTouchCallback() can handle it itself
+ if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent);
+#else
ProcessGestureEvent(gestureEvent);
#endif
+
+#endif
}
// GLFW3 Cursor Position Callback, runs on mouse move
@@ -6139,6 +6145,9 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
// Gesture data is sent to gestures system for processing
ProcessGestureEvent(gestureEvent);
+
+ // Reset the pointCount for web, if it was the last Touch End event
+ if (eventType == EMSCRIPTEN_EVENT_TOUCHEND && CORE.Input.Touch.pointCount == 1) CORE.Input.Touch.pointCount = 0;
#endif
return 1; // The event was consumed by the callback handler
diff --git a/raylib/rgestures.h b/raylib/rgestures.h
index 35cd7a6..78dde76 100644
--- a/raylib/rgestures.h
+++ b/raylib/rgestures.h
@@ -3,12 +3,12 @@
* rgestures - Gestures system, gestures processing based on input events (touch/mouse)
*
* CONFIGURATION:
-* #define GESTURES_IMPLEMENTATION
+* #define RGESTURES_IMPLEMENTATION
* Generates the implementation of the library into the included file.
* If not defined, the library is in header only mode and can be included in other headers
* or source files without problems. But only ONE file should hold the implementation.
*
-* #define GESTURES_STANDALONE
+* #define RGESTURES_STANDALONE
* If defined, the library can be used as standalone to process gesture events with
* no external dependencies.
*
@@ -56,7 +56,7 @@
//----------------------------------------------------------------------------------
// Types and Structures Definition
-// NOTE: Below types are required for GESTURES_STANDALONE usage
+// NOTE: Below types are required for standalone usage
//----------------------------------------------------------------------------------
// Boolean type
#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
@@ -73,7 +73,7 @@ typedef struct Vector2 {
} Vector2;
#endif
-#if defined(GESTURES_STANDALONE)
+#if defined(RGESTURES_STANDALONE)
// Gestures type
// NOTE: It could be used as flags to enable only some gestures
typedef enum {
@@ -122,12 +122,12 @@ extern "C" { // Prevents name mangling of functions
void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures
void UpdateGestures(void); // Update gestures detected (must be called every frame)
-#if defined(GESTURES_STANDALONE)
+#if defined(RGESTURES_STANDALONE)
void SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags
bool IsGestureDetected(int gesture); // Check if a gesture have been detected
int GetGestureDetected(void); // Get latest detected gesture
-float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds
+float GetGestureHoldDuration(void); // Get gesture hold time in seconds
Vector2 GetGestureDragVector(void); // Get gesture drag vector
float GetGestureDragAngle(void); // Get gesture drag angle
Vector2 GetGesturePinchVector(void); // Get gesture pinch delta
@@ -138,17 +138,17 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
}
#endif
-#endif // GESTURES_H
+#endif // RGESTURES_H
/***********************************************************************************
*
-* GESTURES IMPLEMENTATION
+* RGESTURES IMPLEMENTATION
*
************************************************************************************/
-#if defined(GESTURES_IMPLEMENTATION)
+#if defined(RGESTURES_IMPLEMENTATION)
-#if defined(GESTURES_STANDALONE)
+#if defined(RGESTURES_STANDALONE)
#if defined(_WIN32)
#if defined(__cplusplus)
extern "C" { // Prevents name mangling of functions
@@ -181,8 +181,8 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
#define FORCE_TO_SWIPE 0.0005f // Swipe force, measured in normalized screen units/time
#define MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f)
#define MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f)
-#define TAP_TIMEOUT 300 // Tap minimum time, measured in milliseconds
-#define PINCH_TIMEOUT 300 // Pinch minimum time, measured in milliseconds
+#define TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds
+#define PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds
#define DOUBLETAP_RANGE 0.03f // DoubleTap range, measured in normalized screen units (0.0f to 1.0f)
//----------------------------------------------------------------------------------
@@ -209,7 +209,7 @@ typedef struct {
} Touch;
struct {
bool resetRequired; // HOLD reset to get first touch point again
- double timeDuration; // HOLD duration in milliseconds
+ double timeDuration; // HOLD duration in seconds
} Hold;
struct {
Vector2 vector; // DRAG vector (between initial and current position)
@@ -522,12 +522,12 @@ static float rgVector2Distance(Vector2 v1, Vector2 v2)
return result;
}
-// Time measure returned are milliseconds
+// Time measure returned are seconds
static double rgGetCurrentTime(void)
{
double time = 0;
-#if !defined(GESTURES_STANDALONE)
+#if !defined(RGESTURES_STANDALONE)
time = GetTime();
#else
#if defined(_WIN32)
@@ -536,7 +536,7 @@ static double rgGetCurrentTime(void)
QueryPerformanceFrequency(&clockFrequency); // BE CAREFUL: Costly operation!
QueryPerformanceCounter(&currentTime);
- time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds
+ time = (double)currentTime/clockFrequency; // Time in seconds
#endif
#if defined(__linux__)
@@ -545,7 +545,7 @@ static double rgGetCurrentTime(void)
clock_gettime(CLOCK_MONOTONIC, &now);
unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds
- time = ((double)nowTime/1000000.0); // Time in miliseconds
+ time = ((double)nowTime*1e-9); // Time in seconds
#endif
#if defined(__APPLE__)
@@ -561,11 +561,11 @@ static double rgGetCurrentTime(void)
mach_port_deallocate(mach_task_self(), cclock);
unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds
- time = ((double)nowTime/1000000.0); // Time in miliseconds
+ time = ((double)nowTime*1e-9); // Time in seconds
#endif
#endif
return time;
}
-#endif // GESTURES_IMPLEMENTATION
+#endif // RGESTURES_IMPLEMENTATION
diff --git a/raylib/rtext.c b/raylib/rtext.c
index e7bea9a..a7d9903 100644
--- a/raylib/rtext.c
+++ b/raylib/rtext.c
@@ -6,14 +6,19 @@
* #define SUPPORT_MODULE_RTEXT
* rtext module is included in the build
*
+* #define SUPPORT_DEFAULT_FONT
+* Load default raylib font on initialization to be used by DrawText() and MeasureText().
+* If no default font loaded, DrawTextEx() and MeasureTextEx() are required.
+*
* #define SUPPORT_FILEFORMAT_FNT
* #define SUPPORT_FILEFORMAT_TTF
* Selected desired fileformats to be supported for loading. Some of those formats are
* supported by default, to remove support, just comment unrequired #define in this module
*
-* #define SUPPORT_DEFAULT_FONT
-* Load default raylib font on initialization to be used by DrawText() and MeasureText().
-* If no default font loaded, DrawTextEx() and MeasureTextEx() are required.
+* #define SUPPORT_FONT_ATLAS_WHITE_REC
+* On font atlas image generation [GenImageFontAtlas()], add a 3x3 pixels white rectangle
+* at the bottom-right corner of the atlas. It can be useful to for shapes drawing, to allow
+* drawing text and shapes with a single draw call [SetShapesTexture()].
*
* #define TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH
* TextSplit() function static buffer max size
@@ -734,7 +739,6 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC
}
#endif
-
atlas.data = (unsigned char *)RL_CALLOC(1, atlas.width*atlas.height); // Create a bitmap to store characters (8 bpp)
atlas.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
atlas.mipmaps = 1;
@@ -839,7 +843,20 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC
RL_FREE(nodes);
RL_FREE(context);
}
-
+
+#if defined(SUPPORT_FONT_ATLAS_WHITE_REC)
+ // Add a 3x3 white rectangle at the bottom-right corner of the generated atlas,
+ // useful to use as the white texture to draw shapes with raylib, using this rectangle
+ // shapes and text can be backed into a single draw call: SetShapesTexture()
+ for (int i = 0, k = atlas.width*atlas.height - 1; i < 3; i++)
+ {
+ ((unsigned char *)atlas.data)[k - 0] = 255;
+ ((unsigned char *)atlas.data)[k - 1] = 255;
+ ((unsigned char *)atlas.data)[k - 2] = 255;
+ k -= atlas.width;
+ }
+#endif
+
// Convert image data from GRAYSCALE to GRAY_ALPHA
unsigned char *dataGrayAlpha = (unsigned char *)RL_MALLOC(atlas.width*atlas.height*sizeof(unsigned char)*2); // Two channels
@@ -1244,7 +1261,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
if (tempTextWidth < textWidth) tempTextWidth = textWidth;
byteCounter = 0;
textWidth = 0;
-
+
// NOTE: Line spacing is a global variable, use SetTextLineSpacing() to setup
textHeight += (float)textLineSpacing;
}