Merge branch 'raysan5:master' into master

This commit is contained in:
Luiz Pestana 2021-07-30 22:12:33 -03:00 committed by GitHub
commit 45f27a1d20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 1024 additions and 802 deletions

View File

@ -8,7 +8,7 @@ Defines | ALL_CAPS | `#define PLATFORM_DESKTOP`
Macros | ALL_CAPS | `#define MIN(a,b) (((a)<(b))?(a):(b))` Macros | ALL_CAPS | `#define MIN(a,b) (((a)<(b))?(a):(b))`
Variables | lowerCase | `int screenWidth = 0;`, `float targetFrameTime = 0.016f;` Variables | lowerCase | `int screenWidth = 0;`, `float targetFrameTime = 0.016f;`
Local variables | lowerCase | `Vector2 playerPosition = { 0 };` Local variables | lowerCase | `Vector2 playerPosition = { 0 };`
Global variables | lowerCase | `bool fullscreen = false;` Global variables | lowerCase | `bool windowReady = false;`
Constants | lowerCase | `const int maxValue = 8;` Constants | lowerCase | `const int maxValue = 8;`
Pointers | MyType *pointer | `Texture2D *array = NULL;` Pointers | MyType *pointer | `Texture2D *array = NULL;`
float values | always x.xf | `float gravity = 10.0f` float values | always x.xf | `float gravity = 10.0f`

View File

@ -214,7 +214,7 @@ endif
# -std=gnu99 defines C language mode (GNU C from 1999 revision) # -std=gnu99 defines C language mode (GNU C from 1999 revision)
# -Wno-missing-braces ignore invalid warning (GCC bug 53119) # -Wno-missing-braces ignore invalid warning (GCC bug 53119)
# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -Wunused-result
ifeq ($(BUILD_MODE),DEBUG) ifeq ($(BUILD_MODE),DEBUG)
CFLAGS += -g CFLAGS += -g

View File

@ -11,6 +11,7 @@
#include "raylib.h" #include "raylib.h"
#include "rlgl.h" #include "rlgl.h"
#include "raymath.h"
#if defined(PLATFORM_DESKTOP) #if defined(PLATFORM_DESKTOP)
#define GLSL_VERSION 330 #define GLSL_VERSION 330

View File

@ -12,7 +12,7 @@
#include "raylib.h" #include "raylib.h"
#define RNET_IMPLEMENTATION #define RNET_IMPLEMENTATION
#include "rnet.h" #include "extras/rnet.h"
float elapsed = 0.0f; float elapsed = 0.0f;
float delay = 1.0f; float delay = 1.0f;

View File

@ -12,7 +12,7 @@
#include "raylib.h" #include "raylib.h"
#define RNET_IMPLEMENTATION #define RNET_IMPLEMENTATION
#include "rnet.h" #include "extras/rnet.h"
int main(void) int main(void)
{ {

View File

@ -12,7 +12,7 @@
#include "raylib.h" #include "raylib.h"
#define RNET_IMPLEMENTATION #define RNET_IMPLEMENTATION
#include "rnet.h" #include "extras/rnet.h"
int main(void) int main(void)
{ {

View File

@ -12,7 +12,7 @@
#include "raylib.h" #include "raylib.h"
#define RNET_IMPLEMENTATION #define RNET_IMPLEMENTATION
#include "rnet.h" #include "extras/rnet.h"
int main(void) int main(void)
{ {

View File

@ -12,7 +12,7 @@
#include "raylib.h" #include "raylib.h"
#define RNET_IMPLEMENTATION #define RNET_IMPLEMENTATION
#include "rnet.h" #include "extras/rnet.h"
#include <assert.h> #include <assert.h>

View File

@ -12,7 +12,7 @@
#include "raylib.h" #include "raylib.h"
#define RNET_IMPLEMENTATION #define RNET_IMPLEMENTATION
#include "rnet.h" #include "extras/rnet.h"
int main(void) int main(void)
{ {

View File

@ -12,7 +12,7 @@
#include "raylib.h" #include "raylib.h"
#define RNET_IMPLEMENTATION #define RNET_IMPLEMENTATION
#include "rnet.h" #include "extras/rnet.h"
int main(void) int main(void)
{ {

View File

@ -49,9 +49,10 @@
********************************************************************************************/ ********************************************************************************************/
#define RLGL_IMPLEMENTATION #define RLGL_IMPLEMENTATION
#define RLGL_STANDALONE #include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
#define RLGL_SUPPORT_TRACELOG
#include "rlgl.h" // OpenGL 1.1 immediate-mode style coding #define RAYMATH_STATIC_INLINE
#include "raymath.h" // Vector2, Vector3, Quaternion and Matrix functionality
#if defined(__EMSCRIPTEN__) #if defined(__EMSCRIPTEN__)
#define GLFW_INCLUDE_ES2 #define GLFW_INCLUDE_ES2
@ -65,6 +66,9 @@
#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo) #define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo)
#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray #define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray
//----------------------------------------------------------------------------------
// Structures Definition
//----------------------------------------------------------------------------------
// Color, 4 components, R8G8B8A8 (32bit) // Color, 4 components, R8G8B8A8 (32bit)
typedef struct Color { typedef struct Color {
unsigned char r; // Color red value unsigned char r; // Color red value
@ -94,6 +98,12 @@ static void DrawCube(Vector3 position, float width, float height, float length,
static void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); static void DrawCubeWires(Vector3 position, float width, float height, float length, Color color);
static void DrawRectangleV(Vector2 position, Vector2 size, Color color); static void DrawRectangleV(Vector2 position, Vector2 size, Color color);
// NOTE: We used raymath to get this functionality but it can be implemented here
//static Matrix MatrixIdentity(void);
//static Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far);
//static Matrix MatrixPerspective(double fovy, double aspect, double near, double far);
//static Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Main Entry point // Main Entry point
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View File

@ -77,7 +77,7 @@ int main(void)
// Try reloading updated shader // Try reloading updated shader
Shader updatedShader = LoadShader(0, TextFormat(fragShaderFileName, GLSL_VERSION)); Shader updatedShader = LoadShader(0, TextFormat(fragShaderFileName, GLSL_VERSION));
if (updatedShader.id != rlGetShaderDefault().id) // It was correctly loaded if (updatedShader.id != rlGetShaderIdDefault()) // It was correctly loaded
{ {
UnloadShader(shader); UnloadShader(shader);
shader = updatedShader; shader = updatedShader;

View File

@ -70,6 +70,10 @@
#define MAX_LINE_LENGTH 512 // Maximum length of one line (including comments) #define MAX_LINE_LENGTH 512 // Maximum length of one line (including comments)
#define MAX_STRUCT_LINE_LENGTH 2048 // Maximum length of one struct (multiple lines) #define MAX_STRUCT_LINE_LENGTH 2048 // Maximum length of one struct (multiple lines)
#define MAX_FUNCTION_PARAMETERS 12 // Maximum number of function parameters
#define MAX_STRUCT_FIELDS 32 // Maximum number of struct fields
#define MAX_ENUM_VALUES 512 // Maximum number of enum values
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -79,9 +83,9 @@ typedef struct FunctionInfo {
char desc[128]; // Function description (comment at the end) char desc[128]; // Function description (comment at the end)
char retType[32]; // Return value type char retType[32]; // Return value type
int paramCount; // Number of function parameters int paramCount; // Number of function parameters
char paramType[12][32]; // Parameters type (max: 12 parameters) char paramType[MAX_FUNCTION_PARAMETERS][32]; // Parameters type
char paramName[12][32]; // Parameters name (max: 12 parameters) char paramName[MAX_FUNCTION_PARAMETERS][32]; // Parameters name
char paramDesc[12][8]; // Parameters description (max: 12 parameters) char paramDesc[MAX_FUNCTION_PARAMETERS][8]; // Parameters description
} FunctionInfo; } FunctionInfo;
// Struct info data // Struct info data
@ -89,9 +93,9 @@ typedef struct StructInfo {
char name[64]; // Struct name char name[64]; // Struct name
char desc[64]; // Struct type description char desc[64]; // Struct type description
int fieldCount; // Number of fields in the struct int fieldCount; // Number of fields in the struct
char fieldType[16][32]; // Field type (max: 16 fields) char fieldType[MAX_STRUCT_FIELDS][64]; // Field type
char fieldName[16][32]; // Field name (max: 16 fields) char fieldName[MAX_STRUCT_FIELDS][64]; // Field name
char fieldDesc[16][128]; // Field description (max: 16 fields) char fieldDesc[MAX_STRUCT_FIELDS][128]; // Field description
} StructInfo; } StructInfo;
// Enum info data // Enum info data
@ -99,9 +103,9 @@ typedef struct EnumInfo {
char name[64]; // Enum name char name[64]; // Enum name
char desc[64]; // Enum description char desc[64]; // Enum description
int valueCount; // Number of values in enumerator int valueCount; // Number of values in enumerator
char valueName[128][64]; // Value name definition (max: 128 values) char valueName[MAX_ENUM_VALUES][64]; // Value name definition
int valueInteger[128]; // Value integer (max: 128 values) int valueInteger[MAX_ENUM_VALUES]; // Value integer
char valueDesc[128][64]; // Value description (max: 128 values) char valueDesc[MAX_ENUM_VALUES][64]; // Value description
} EnumInfo; } EnumInfo;
// Output format for parsed data // Output format for parsed data
@ -116,6 +120,7 @@ static int enumCount = 0;
static FunctionInfo *funcs = NULL; static FunctionInfo *funcs = NULL;
static StructInfo *structs = NULL; static StructInfo *structs = NULL;
static EnumInfo *enums = NULL; static EnumInfo *enums = NULL;
static char apiDefine[32] = "RLAPI\0";
// Command line variables // Command line variables
static char inFileName[512] = { 0 }; // Input file name (required in case of provided through CLI) static char inFileName[512] = { 0 }; // Input file name (required in case of provided through CLI)
@ -171,8 +176,8 @@ int main(int argc, char* argv[])
// Read function lines // Read function lines
for (int i = 0; i < linesCount; i++) for (int i = 0; i < linesCount; i++)
{ {
// Read function line (starting with "RLAPI") // Read function line (starting with `define`, i.e. for raylib.h "RLAPI")
if (IsTextEqual(lines[i], "RLAPI", 5)) if (IsTextEqual(lines[i], apiDefine, TextLength(apiDefine)))
{ {
// Keep a pointer to the function line // Keep a pointer to the function line
funcLines[funcCount] = lines[i]; funcLines[funcCount] = lines[i];
@ -217,12 +222,6 @@ int main(int argc, char* argv[])
j++; j++;
} }
while (buffer[i + j] != '}')
{
structLines[structCount][j] = buffer[i + j];
j++;
}
while (buffer[i + j] != '\n') while (buffer[i + j] != '\n')
{ {
structLines[structCount][j] = buffer[i + j]; structLines[structCount][j] = buffer[i + j];
@ -238,7 +237,7 @@ int main(int argc, char* argv[])
// Read enum lines // Read enum lines
for (int i = 0; i < linesCount; i++) for (int i = 0; i < linesCount; i++)
{ {
// Read function line (starting with "RLAPI") // Read enum line
if (IsTextEqual(lines[i], "typedef enum {", 14)) if (IsTextEqual(lines[i], "typedef enum {", 14))
{ {
// Keep the line position in the array of lines, // Keep the line position in the array of lines,
@ -335,7 +334,7 @@ int main(int argc, char* argv[])
{ {
// TODO: Get enum description from lines[enumLines[i] - 1] // TODO: Get enum description from lines[enumLines[i] - 1]
for (int j = 1; j < 256; j++) // Maximum number of lines following enum first line for (int j = 1; j < MAX_ENUM_VALUES*2; j++) // Maximum number of lines following enum first line
{ {
char *linePtr = lines[enumLines[i] + j]; char *linePtr = lines[enumLines[i] + j];
@ -428,8 +427,9 @@ int main(int argc, char* argv[])
// At this point we have function return type and function name // At this point we have function return type and function name
char funcRetTypeName[128] = { 0 }; char funcRetTypeName[128] = { 0 };
int funcRetTypeNameLen = c - 6; // Substract "RLAPI " int dc = TextLength(apiDefine) + 1;
MemoryCopy(funcRetTypeName, &funcLines[i][6], funcRetTypeNameLen); int funcRetTypeNameLen = c - dc; // Substract `define` ("RLAPI " for raylib.h)
MemoryCopy(funcRetTypeName, &funcLines[i][dc], funcRetTypeNameLen);
GetDataTypeAndName(funcRetTypeName, funcRetTypeNameLen, funcs[i].retType, funcs[i].name); GetDataTypeAndName(funcRetTypeName, funcRetTypeNameLen, funcs[i].retType, funcs[i].name);
break; break;
@ -525,7 +525,7 @@ static void ShowCommandLineInfo(void)
printf("//////////////////////////////////////////////////////////////////////////////////\n\n"); printf("//////////////////////////////////////////////////////////////////////////////////\n\n");
printf("USAGE:\n\n"); printf("USAGE:\n\n");
printf(" > raylib_parser [--help] [--input <filename.h>] [--output <filename.ext>] [--format <type>]\n"); printf(" > raylib_parser [--help] [--input <filename.h>] [--output <filename.ext>] [--format <type>] [--define <DEF>]\n");
printf("\nOPTIONS:\n\n"); printf("\nOPTIONS:\n\n");
printf(" -h, --help : Show tool version and command line usage help\n\n"); printf(" -h, --help : Show tool version and command line usage help\n\n");
@ -536,12 +536,16 @@ static void ShowCommandLineInfo(void)
printf(" NOTE: If not specified, defaults to: raylib_api.txt\n\n"); printf(" NOTE: If not specified, defaults to: raylib_api.txt\n\n");
printf(" -f, --format <type> : Define output format for parser data.\n"); printf(" -f, --format <type> : Define output format for parser data.\n");
printf(" Supported types: DEFAULT, JSON, XML\n\n"); printf(" Supported types: DEFAULT, JSON, XML\n\n");
printf(" -d, --define <DEF> : Define functions define (i.e. RLAPI for raylib.h, RMDEF for raymath.h, etc\n");
printf(" NOTE: If not specified, defaults to: RLAPI\n\n");
printf("\nEXAMPLES:\n\n"); printf("\nEXAMPLES:\n\n");
printf(" > raylib_parser --input raylib.h --output api.json\n"); printf(" > raylib_parser --input raylib.h --output api.json\n");
printf(" Process <raylib.h> to generate <api.json>\n\n"); printf(" Process <raylib.h> to generate <api.json>\n\n");
printf(" > raylib_parser --output raylib_data.info --format XML\n"); printf(" > raylib_parser --output raylib_data.info --format XML\n");
printf(" Process <raylib.h> to generate <raylib_data.info> as XML text data\n\n"); printf(" Process <raylib.h> to generate <raylib_data.info> as XML text data\n\n");
printf(" > raylib_parser --input raymath.h --output raymath_data.info --format XML\n");
printf(" Process <raymath.h> to generate <raymath_data.info> as XML text data\n\n");
} }
// Process command line arguments // Process command line arguments
@ -583,6 +587,16 @@ static void ProcessCommandLine(int argc, char *argv[])
} }
else printf("WARNING: No format parameters provided\n"); else printf("WARNING: No format parameters provided\n");
} }
else if (IsTextEqual(argv[i], "-d", 2) || IsTextEqual(argv[i], "--define", 8))
{
if (((i + 1) < argc) && (argv[i + 1][0] != '-'))
{
MemoryCopy(apiDefine, argv[i + 1], TextLength(argv[i + 1])); // Read functions define
apiDefine[TextLength(argv[i + 1])] = '\0';
i++;
}
else printf("WARNING: No define key provided\n");
}
} }
} }

View File

@ -313,6 +313,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\src\camera.h" /> <ClInclude Include="..\..\..\src\camera.h" />
<ClInclude Include="..\..\..\src\config.h" />
<ClInclude Include="..\..\..\src\external\glad.h" /> <ClInclude Include="..\..\..\src\external\glad.h" />
<ClInclude Include="..\..\..\src\external\jar_mod.h" /> <ClInclude Include="..\..\..\src\external\jar_mod.h" />
<ClInclude Include="..\..\..\src\external\jar_xm.h" /> <ClInclude Include="..\..\..\src\external\jar_xm.h" />

View File

@ -110,22 +110,22 @@
// Default shader vertex attribute names to set location points // Default shader vertex attribute names to set location points
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience // NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
#define DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0 #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
#define DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1 #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
#define DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2 #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
#define DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3 #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
#define DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4 #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
#define DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5 #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
#define DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
#define DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
#define DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix #define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
#define DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix #define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
#define DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView)) #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
#define DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color) #define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
#define DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0) #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
#define DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1) #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
#define DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2) #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------

View File

@ -124,19 +124,14 @@
#include "config.h" // Defines module configuration flags #include "config.h" // Defines module configuration flags
#endif #endif
#include "utils.h" // TRACELOG macros #include "utils.h" // Required for: TRACELOG() macros
#if (defined(__linux__) || defined(PLATFORM_WEB)) && _POSIX_C_SOURCE < 199309L #define RLGL_IMPLEMENTATION
#undef _POSIX_C_SOURCE #include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
#define _POSIX_C_SOURCE 199309L // Required for: CLOCK_MONOTONIC if compiled with c99 without gnu ext.
#endif
#define RAYMATH_IMPLEMENTATION // Define external out-of-line implementation #define RAYMATH_IMPLEMENTATION // Define external out-of-line implementation
#include "raymath.h" // Vector3, Quaternion and Matrix functionality #include "raymath.h" // Vector3, Quaternion and Matrix functionality
#define RLGL_IMPLEMENTATION
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
#if defined(SUPPORT_GESTURES_SYSTEM) #if defined(SUPPORT_GESTURES_SYSTEM)
#define GESTURES_IMPLEMENTATION #define GESTURES_IMPLEMENTATION
#include "gestures.h" // Gestures detection functionality #include "gestures.h" // Gestures detection functionality
@ -164,6 +159,11 @@
#include "external/sdefl.h" // Deflate (RFC 1951) compressor #include "external/sdefl.h" // Deflate (RFC 1951) compressor
#endif #endif
#if (defined(__linux__) || defined(PLATFORM_WEB)) && _POSIX_C_SOURCE < 199309L
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199309L // Required for: CLOCK_MONOTONIC if compiled with c99 without gnu ext.
#endif
#include <stdlib.h> // Required for: srand(), rand(), atexit() #include <stdlib.h> // Required for: srand(), rand(), atexit()
#include <stdio.h> // Required for: sprintf() [Used in OpenURL()] #include <stdio.h> // Required for: sprintf() [Used in OpenURL()]
#include <string.h> // Required for: strrchr(), strcmp(), strlen() #include <string.h> // Required for: strrchr(), strcmp(), strlen()
@ -643,6 +643,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
#endif #endif
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData); static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData);
static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData); static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData);
static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *e, void *userData); static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *e, void *userData);
@ -818,8 +819,10 @@ void InitWindow(int width, int height, const char *title)
// NOTE: We setup a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering // NOTE: We setup a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 }); SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 });
#else #else
// Set default internal texture (1px white) and rectangle to be used for shapes drawing // Set default texture and rectangle to be used for shapes drawing
SetShapesTexture(rlGetTextureDefault(), (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
Texture2D texture = { rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
SetShapesTexture(texture, (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f });
#endif #endif
#if defined(PLATFORM_DESKTOP) #if defined(PLATFORM_DESKTOP)
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
@ -854,6 +857,9 @@ void InitWindow(int width, int height, const char *title)
//emscripten_set_keypress_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback); //emscripten_set_keypress_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback);
//emscripten_set_keydown_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback); //emscripten_set_keydown_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback);
// Support mouse events
emscripten_set_click_callback("#canvas", NULL, 1, EmscriptenMouseCallback);
// Support touch events // Support touch events
emscripten_set_touchstart_callback("#canvas", NULL, 1, EmscriptenTouchCallback); emscripten_set_touchstart_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
emscripten_set_touchend_callback("#canvas", NULL, 1, EmscriptenTouchCallback); emscripten_set_touchend_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
@ -2171,13 +2177,13 @@ void EndTextureMode(void)
// Begin custom shader mode // Begin custom shader mode
void BeginShaderMode(Shader shader) void BeginShaderMode(Shader shader)
{ {
rlSetShader(shader); rlSetShader(shader.id, shader.locs);
} }
// End custom shader mode (returns to default shader) // End custom shader mode (returns to default shader)
void EndShaderMode(void) void EndShaderMode(void)
{ {
rlSetShader(rlGetShaderDefault()); rlSetShader(rlGetShaderIdDefault(), rlGetShaderLocsDefault());
} }
// Begin blending mode (alpha, additive, multiplied, subtract, custom) // Begin blending mode (alpha, additive, multiplied, subtract, custom)
@ -2348,25 +2354,25 @@ RLAPI Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
// NOTE: If any location is not found, loc point becomes -1 // NOTE: If any location is not found, loc point becomes -1
// Get handles to GLSL input attibute locations // Get handles to GLSL input attibute locations
shader.locs[SHADER_LOC_VERTEX_POSITION] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_POSITION); shader.locs[SHADER_LOC_VERTEX_POSITION] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
shader.locs[SHADER_LOC_VERTEX_TEXCOORD01] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD); shader.locs[SHADER_LOC_VERTEX_TEXCOORD01] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2); shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
shader.locs[SHADER_LOC_VERTEX_NORMAL] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_NORMAL); shader.locs[SHADER_LOC_VERTEX_NORMAL] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
shader.locs[SHADER_LOC_VERTEX_TANGENT] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TANGENT); shader.locs[SHADER_LOC_VERTEX_TANGENT] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_COLOR); shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
// Get handles to GLSL uniform locations (vertex shader) // Get handles to GLSL uniform locations (vertex shader)
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_MVP); shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP);
shader.locs[SHADER_LOC_MATRIX_VIEW] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_VIEW); shader.locs[SHADER_LOC_MATRIX_VIEW] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW);
shader.locs[SHADER_LOC_MATRIX_PROJECTION] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_PROJECTION); shader.locs[SHADER_LOC_MATRIX_PROJECTION] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION);
shader.locs[SHADER_LOC_MATRIX_MODEL] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_MODEL); shader.locs[SHADER_LOC_MATRIX_MODEL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL);
shader.locs[SHADER_LOC_MATRIX_NORMAL] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_NORMAL); shader.locs[SHADER_LOC_MATRIX_NORMAL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL);
// Get handles to GLSL uniform locations (fragment shader) // Get handles to GLSL uniform locations (fragment shader)
shader.locs[SHADER_LOC_COLOR_DIFFUSE] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_COLOR); shader.locs[SHADER_LOC_COLOR_DIFFUSE] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR);
shader.locs[SHADER_LOC_MAP_DIFFUSE] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0); // SHADER_LOC_MAP_ALBEDO shader.locs[SHADER_LOC_MAP_DIFFUSE] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0); // SHADER_LOC_MAP_ALBEDO
shader.locs[SHADER_LOC_MAP_SPECULAR] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1); // SHADER_LOC_MAP_METALNESS shader.locs[SHADER_LOC_MAP_SPECULAR] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1); // SHADER_LOC_MAP_METALNESS
shader.locs[SHADER_LOC_MAP_NORMAL] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2); shader.locs[SHADER_LOC_MAP_NORMAL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2);
} }
return shader; return shader;
@ -2375,7 +2381,7 @@ RLAPI Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
// Unload shader from GPU memory (VRAM) // Unload shader from GPU memory (VRAM)
void UnloadShader(Shader shader) void UnloadShader(Shader shader)
{ {
if (shader.id != rlGetShaderDefault().id) if (shader.id != rlGetShaderIdDefault())
{ {
rlUnloadShaderProgram(shader.id); rlUnloadShaderProgram(shader.id);
RL_FREE(shader.locs); RL_FREE(shader.locs);
@ -5568,6 +5574,13 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
#endif #endif
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
// Register mouse input events
static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
{
// This is only for registering mouse click events with emscripten and doesn't need to do anything
return 0;
}
// Register touch input events // Register touch input events
static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData) static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
{ {

View File

@ -43,23 +43,15 @@
#include "config.h" // Defines module configuration flags #include "config.h" // Defines module configuration flags
#endif #endif
#include "utils.h" // Required for: LoadFileData(), LoadFileText(), SaveFileText() #include "utils.h" // Required for: TRACELOG(), LoadFileData(), LoadFileText(), SaveFileText()
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
#include "raymath.h" // Required for: Vector3, Quaternion and Matrix functionality
#include <stdio.h> // Required for: sprintf() #include <stdio.h> // Required for: sprintf()
#include <stdlib.h> // Required for: malloc(), free() #include <stdlib.h> // Required for: malloc(), free()
#include <string.h> // Required for: memcmp(), strlen() #include <string.h> // Required for: memcmp(), strlen()
#include <math.h> // Required for: sinf(), cosf(), sqrtf(), fabsf() #include <math.h> // Required for: sinf(), cosf(), sqrtf(), fabsf()
#if defined(_WIN32)
#include <direct.h> // Required for: _chdir() [Used in LoadOBJ()]
#define CHDIR _chdir
#else
#include <unistd.h> // Required for: chdir() (POSIX) [Used in LoadOBJ()]
#define CHDIR chdir
#endif
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
#if defined(SUPPORT_FILEFORMAT_OBJ) || defined(SUPPORT_FILEFORMAT_MTL) #if defined(SUPPORT_FILEFORMAT_OBJ) || defined(SUPPORT_FILEFORMAT_MTL)
#define TINYOBJ_MALLOC RL_MALLOC #define TINYOBJ_MALLOC RL_MALLOC
#define TINYOBJ_CALLOC RL_CALLOC #define TINYOBJ_CALLOC RL_CALLOC
@ -89,6 +81,14 @@
#include "external/par_shapes.h" // Shapes 3d parametric generation #include "external/par_shapes.h" // Shapes 3d parametric generation
#endif #endif
#if defined(_WIN32)
#include <direct.h> // Required for: _chdir() [Used in LoadOBJ()]
#define CHDIR _chdir
#else
#include <unistd.h> // Required for: chdir() (POSIX) [Used in LoadOBJ()]
#define CHDIR chdir
#endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Defines and Macros // Defines and Macros
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -1371,7 +1371,11 @@ Material *LoadMaterials(const char *fileName, int *materialCount)
// Set materials shader to default (DIFFUSE, SPECULAR, NORMAL) // Set materials shader to default (DIFFUSE, SPECULAR, NORMAL)
if (materials != NULL) if (materials != NULL)
{ {
for (unsigned int i = 0; i < count; i++) materials[i].shader = rlGetShaderDefault(); for (unsigned int i = 0; i < count; i++)
{
materials[i].shader.id = rlGetShaderIdDefault();
materials[i].shader.locs = rlGetShaderLocsDefault();
}
} }
*materialCount = count; *materialCount = count;
@ -1384,8 +1388,12 @@ Material LoadMaterialDefault(void)
Material material = { 0 }; Material material = { 0 };
material.maps = (MaterialMap *)RL_CALLOC(MAX_MATERIAL_MAPS, sizeof(MaterialMap)); material.maps = (MaterialMap *)RL_CALLOC(MAX_MATERIAL_MAPS, sizeof(MaterialMap));
material.shader = rlGetShaderDefault(); // Using rlgl default shader
material.maps[MATERIAL_MAP_DIFFUSE].texture = rlGetTextureDefault(); // White texture (1x1 pixel) material.shader.id = rlGetShaderIdDefault();
material.shader.locs = rlGetShaderLocsDefault();
// Using rlgl default texture (1x1 pixel, UNCOMPRESSED_R8G8B8A8, 1 mipmap)
material.maps[MATERIAL_MAP_DIFFUSE].texture = (Texture2D){ rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
//material.maps[MATERIAL_MAP_NORMAL].texture; // NOTE: By default, not set //material.maps[MATERIAL_MAP_NORMAL].texture; // NOTE: By default, not set
//material.maps[MATERIAL_MAP_SPECULAR].texture; // NOTE: By default, not set //material.maps[MATERIAL_MAP_SPECULAR].texture; // NOTE: By default, not set
@ -1399,12 +1407,12 @@ Material LoadMaterialDefault(void)
void UnloadMaterial(Material material) void UnloadMaterial(Material material)
{ {
// Unload material shader (avoid unloading default shader, managed by raylib) // Unload material shader (avoid unloading default shader, managed by raylib)
if (material.shader.id != rlGetShaderDefault().id) UnloadShader(material.shader); if (material.shader.id != rlGetShaderIdDefault()) UnloadShader(material.shader);
// Unload loaded texture maps (avoid unloading default texture, managed by raylib) // Unload loaded texture maps (avoid unloading default texture, managed by raylib)
for (int i = 0; i < MAX_MATERIAL_MAPS; i++) for (int i = 0; i < MAX_MATERIAL_MAPS; i++)
{ {
if (material.maps[i].texture.id != rlGetTextureDefault().id) rlUnloadTexture(material.maps[i].texture.id); if (material.maps[i].texture.id != rlGetTextureIdDefault()) rlUnloadTexture(material.maps[i].texture.id);
} }
RL_FREE(material.maps); RL_FREE(material.maps);
@ -3400,10 +3408,11 @@ static Model LoadOBJ(const char *fileName)
// NOTE: Uses default shader, which only supports MATERIAL_MAP_DIFFUSE // NOTE: Uses default shader, which only supports MATERIAL_MAP_DIFFUSE
model.materials[m] = LoadMaterialDefault(); model.materials[m] = LoadMaterialDefault();
model.materials[m].maps[MATERIAL_MAP_DIFFUSE].texture = rlGetTextureDefault(); // Get default texture, in case no texture is defined // Get default texture, in case no texture is defined
// NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
model.materials[m].maps[MATERIAL_MAP_DIFFUSE].texture = (Texture2D){ rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
if (materials[m].diffuse_texname != NULL) model.materials[m].maps[MATERIAL_MAP_DIFFUSE].texture = LoadTexture(materials[m].diffuse_texname); //char *diffuse_texname; // map_Kd if (materials[m].diffuse_texname != NULL) model.materials[m].maps[MATERIAL_MAP_DIFFUSE].texture = LoadTexture(materials[m].diffuse_texname); //char *diffuse_texname; // map_Kd
else model.materials[m].maps[MATERIAL_MAP_DIFFUSE].texture = rlGetTextureDefault();
model.materials[m].maps[MATERIAL_MAP_DIFFUSE].color = (Color){ (unsigned char)(materials[m].diffuse[0]*255.0f), (unsigned char)(materials[m].diffuse[1]*255.0f), (unsigned char)(materials[m].diffuse[2]*255.0f), 255 }; //float diffuse[3]; model.materials[m].maps[MATERIAL_MAP_DIFFUSE].color = (Color){ (unsigned char)(materials[m].diffuse[0]*255.0f), (unsigned char)(materials[m].diffuse[1]*255.0f), (unsigned char)(materials[m].diffuse[2]*255.0f), 255 }; //float diffuse[3];
model.materials[m].maps[MATERIAL_MAP_DIFFUSE].value = 0.0f; model.materials[m].maps[MATERIAL_MAP_DIFFUSE].value = 0.0f;

View File

@ -70,7 +70,6 @@
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() #include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
#else #else
#include "raylib.h" // Declares module functions #include "raylib.h" // Declares module functions
// Check if config flags have been externally provided on compilation line // Check if config flags have been externally provided on compilation line
#if !defined(EXTERNAL_CONFIG_FLAGS) #if !defined(EXTERNAL_CONFIG_FLAGS)
#include "config.h" // Defines module configuration flags #include "config.h" // Defines module configuration flags
@ -173,7 +172,7 @@ typedef struct tagBITMAPINFOHEADER {
#if defined(RAUDIO_STANDALONE) #if defined(RAUDIO_STANDALONE)
#include <string.h> // Required for: strcmp() [Used in IsFileExtension()] #include <string.h> // Required for: strcmp() [Used in IsFileExtension()]
#if !defined(TRACELOG) #ifndef TRACELOG
#define TRACELOG(level, ...) (void)0 #define TRACELOG(level, ...) (void)0
#endif #endif

View File

@ -22,7 +22,7 @@
* *
* NOTES: * NOTES:
* One default Font is loaded on InitWindow()->LoadFontDefault() [core, text] * One default Font is loaded on InitWindow()->LoadFontDefault() [core, text]
* One default Texture2D is loaded on rlglInit() [rlgl] (OpenGL 3.3 or ES2) * One default Texture2D is loaded on rlglInit(), 1x1 white pixel R8G8B8A8 [rlgl] (OpenGL 3.3 or ES2)
* One default Shader is loaded on rlglInit()->rlLoadShaderDefault() [rlgl] (OpenGL 3.3 or ES2) * One default Shader is loaded on rlglInit()->rlLoadShaderDefault() [rlgl] (OpenGL 3.3 or ES2)
* One default RenderBatch is loaded on rlglInit()->rlLoadRenderBatch() [rlgl] (OpenGL 3.3 or ES2) * One default RenderBatch is loaded on rlglInit()->rlLoadRenderBatch() [rlgl] (OpenGL 3.3 or ES2)
* *
@ -128,6 +128,16 @@
#define CLITERAL(type) (type) #define CLITERAL(type) (type)
#endif #endif
// NOTE: We set some defines with some data types declared by raylib
// Other modules (raymath, rlgl) also require some of those types, so,
// to be able to use those other modules as standalone (not depending on raylib)
// this defines are very useful for internal check and avoid type (re)definitions
#define RL_VECTOR2_TYPE
#define RL_VECTOR3_TYPE
#define RL_VECTOR4_TYPE
#define RL_QUATERNION_TYPE
#define RL_MATRIX_TYPE
// Some Basic Colors // Some Basic Colors
// NOTE: Custom raylib color palette for amazing visuals on WHITE background // NOTE: Custom raylib color palette for amazing visuals on WHITE background
#define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray #define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray
@ -1315,6 +1325,7 @@ RLAPI void UnloadFont(Font font);
RLAPI void DrawFPS(int posX, int posY); // Draw current FPS RLAPI void DrawFPS(int posX, int posY); // Draw current FPS
RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
//RLAPI void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint);
RLAPI void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint); // Draw text using font inside rectangle limits RLAPI void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint); // Draw text using font inside rectangle limits
RLAPI void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, Color selectTint, Color selectBackTint); // Draw text using font inside rectangle limits with support for text selection RLAPI void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, Color selectTint, Color selectBackTint); // Draw text using font inside rectangle limits with support for text selection
RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint); // Draw one character (codepoint) RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint); // Draw one character (codepoint)

View File

@ -1,6 +1,6 @@
/********************************************************************************************** /**********************************************************************************************
* *
* raymath v1.2 - Math functions to work with Vector3, Matrix and Quaternions * raymath v1.3 - Math functions to work with Vector3, Matrix and Quaternions
* *
* CONFIGURATION: * CONFIGURATION:
* *
@ -9,14 +9,10 @@
* If not defined, the library is in header only mode and can be included in other headers * 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. * or source files without problems. But only ONE file should hold the implementation.
* *
* #define RAYMATH_HEADER_ONLY * #define RAYMATH_STATIC_INLINE
* Define static inline functions code, so #include header suffices for use. * Define static inline functions code, so #include header suffices for use.
* This may use up lots of memory. * This may use up lots of memory.
* *
* #define RAYMATH_STANDALONE
* Avoid raylib.h header inclusion in this file.
* Vector3 and Matrix data types are defined internally in raymath module.
*
* *
* LICENSE: zlib/libpng * LICENSE: zlib/libpng
* *
@ -42,15 +38,8 @@
#ifndef RAYMATH_H #ifndef RAYMATH_H
#define RAYMATH_H #define RAYMATH_H
//#define RAYMATH_STANDALONE // NOTE: To use raymath as standalone lib, just uncomment this line #if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_STATIC_INLINE)
//#define RAYMATH_HEADER_ONLY // NOTE: To compile functions as static inline, uncomment this line #error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_STATIC_INLINE is contradictory"
#ifndef RAYMATH_STANDALONE
#include "raylib.h" // Required for: Vector3, Matrix structs definition
#endif
#if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_HEADER_ONLY)
#error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_HEADER_ONLY is contradictory"
#endif #endif
#if defined(RAYMATH_IMPLEMENTATION) #if defined(RAYMATH_IMPLEMENTATION)
@ -61,7 +50,7 @@
#else #else
#define RMDEF extern inline // Provide external definition #define RMDEF extern inline // Provide external definition
#endif #endif
#elif defined(RAYMATH_HEADER_ONLY) #elif defined(RAYMATH_STATIC_INLINE)
#define RMDEF static inline // Functions may be inlined, no external out-of-line definition #define RMDEF static inline // Functions may be inlined, no external out-of-line definition
#else #else
#if defined(__TINYC__) #if defined(__TINYC__)
@ -100,20 +89,26 @@
// Types and Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(RAYMATH_STANDALONE) #if !defined(RL_VECTOR2_TYPE)
// Vector2 type // Vector2 type
typedef struct Vector2 { typedef struct Vector2 {
float x; float x;
float y; float y;
} Vector2; } Vector2;
#define RL_VECTOR2_TYPE
#endif
#if !defined(RL_VECTOR3_TYPE)
// Vector3 type // Vector3 type
typedef struct Vector3 { typedef struct Vector3 {
float x; float x;
float y; float y;
float z; float z;
} Vector3; } Vector3;
#define RL_VECTOR3_TYPE
#endif
#if !defined(RL_VECTOR4_TYPE)
// Vector4 type // Vector4 type
typedef struct Vector4 { typedef struct Vector4 {
float x; float x;
@ -121,22 +116,34 @@
float z; float z;
float w; float w;
} Vector4; } Vector4;
#define RL_VECTOR4_TYPE
#endif
#if !defined(RL_QUATERNION_TYPE)
// Quaternion type // Quaternion type
typedef Vector4 Quaternion; typedef Vector4 Quaternion;
#define RL_QUATERNION_TYPE
#endif
#if !defined(RL_MATRIX_TYPE)
// Matrix type (OpenGL style 4x4 - right handed, column major) // Matrix type (OpenGL style 4x4 - right handed, column major)
typedef struct Matrix { typedef struct Matrix {
float m0, m4, m8, m12; float m0, m4, m8, m12; // Matrix first row (4 components)
float m1, m5, m9, m13; float m1, m5, m9, m13; // Matrix second row (4 components)
float m2, m6, m10, m14; float m2, m6, m10, m14; // Matrix third row (4 components)
float m3, m7, m11, m15; float m3, m7, m11, m15; // Matrix fourth row (4 components)
} Matrix; } Matrix;
#define RL_MATRIX_TYPE
#endif #endif
// NOTE: Helper types to be used instead of array return types for *ToFloat functions // NOTE: Helper types to be used instead of array return types for *ToFloat functions
typedef struct float3 { float v[3]; } float3; typedef struct float3 {
typedef struct float16 { float v[16]; } float16; float v[3];
} float3;
typedef struct float16 {
float v[16];
} float16;
#include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), fminf(), fmaxf(), fabs() #include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), fminf(), fmaxf(), fabs()
@ -483,14 +490,14 @@ RMDEF Vector3 Vector3Normalize(Vector3 v)
{ {
Vector3 result = v; Vector3 result = v;
float length, ilength; float length, inverseLength;
length = Vector3Length(v); length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
if (length == 0.0f) length = 1.0f; if (length == 0.0f) length = 1.0f;
ilength = 1.0f/length; inverseLength = 1.0f/length;
result.x *= ilength; result.x *= inverseLength;
result.y *= ilength; result.y *= inverseLength;
result.z *= ilength; result.z *= inverseLength;
return result; return result;
} }
@ -1424,8 +1431,9 @@ RMDEF Matrix QuaternionToMatrix(Quaternion q)
RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle) RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
{ {
Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f }; Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
float axisLength = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z);
if (Vector3Length(axis) != 0.0f) if (axisLength != 0.0f)
{ {
angle *= 0.5f; angle *= 0.5f;

1271
src/rlgl.h

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,7 @@
#include "config.h" // Defines module configuration flags #include "config.h" // Defines module configuration flags
#endif #endif
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2 #include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
#include <math.h> // Required for: sinf(), asinf(), cosf(), acosf(), sqrtf(), fabsf() #include <math.h> // Required for: sinf(), asinf(), cosf(), acosf(), sqrtf(), fabsf()

View File

@ -64,17 +64,14 @@
#include "config.h" // Defines module configuration flags #include "config.h" // Defines module configuration flags
#endif #endif
#include "utils.h" // Required for: TRACELOG() and fopen() Android mapping
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2
#include <stdlib.h> // Required for: malloc(), free() #include <stdlib.h> // Required for: malloc(), free()
#include <string.h> // Required for: strlen() [Used in ImageTextEx()] #include <string.h> // Required for: strlen() [Used in ImageTextEx()]
#include <math.h> // Required for: fabsf() #include <math.h> // Required for: fabsf()
#include <stdio.h> // Required for: sprintf() [Used in ExportImageAsCode()] #include <stdio.h> // Required for: sprintf() [Used in ExportImageAsCode()]
#include "utils.h" // Required for: fopen() Android mapping
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2
// Required for: rlLoadTexture() rlUnloadTexture(),
// rlGenerateMipmaps(), some funcs for DrawTexturePro()
// Support only desired texture formats on stb_image // Support only desired texture formats on stb_image
#if !defined(SUPPORT_FILEFORMAT_BMP) #if !defined(SUPPORT_FILEFORMAT_BMP)
#define STBI_NO_BMP #define STBI_NO_BMP
@ -331,6 +328,8 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
int comp = 0; int comp = 0;
image.data = stbi_load_from_memory(fileData, dataSize, &image.width, &image.height, &comp, 0); image.data = stbi_load_from_memory(fileData, dataSize, &image.width, &image.height, &comp, 0);
if (image.data != NULL)
{
image.mipmaps = 1; image.mipmaps = 1;
if (comp == 1) image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE; if (comp == 1) image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
@ -338,6 +337,7 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
else if (comp == 3) image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8; else if (comp == 3) image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8;
else if (comp == 4) image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; else if (comp == 4) image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
} }
}
#endif #endif
} }
#if defined(SUPPORT_FILEFORMAT_HDR) #if defined(SUPPORT_FILEFORMAT_HDR)
@ -380,7 +380,8 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
#endif #endif
else TRACELOG(LOG_WARNING, "IMAGE: Data format not supported"); else TRACELOG(LOG_WARNING, "IMAGE: Data format not supported");
TRACELOG(LOG_INFO, "IMAGE: Data loaded successfully (%ix%i | %s | %i mipmaps)", image.width, image.height, rlGetPixelFormatName(image.format), image.mipmaps); if (image.data != NULL) TRACELOG(LOG_INFO, "IMAGE: Data loaded successfully (%ix%i | %s | %i mipmaps)", image.width, image.height, rlGetPixelFormatName(image.format), image.mipmaps);
else TRACELOG(LOG_WARNING, "IMAGE: Failed to load image data");
return image; return image;
} }
@ -393,7 +394,7 @@ Image LoadImageFromTexture(Texture2D texture)
if (texture.format < PIXELFORMAT_COMPRESSED_DXT1_RGB) if (texture.format < PIXELFORMAT_COMPRESSED_DXT1_RGB)
{ {
image.data = rlReadTexturePixels(texture); image.data = rlReadTexturePixels(texture.id, texture.width, texture.height, texture.format);
if (image.data != NULL) if (image.data != NULL)
{ {
@ -2344,7 +2345,7 @@ void ImageDrawPixel(Image *dst, int x, int y, Color color)
unsigned char r = (unsigned char)(round(coln.x*31.0f)); unsigned char r = (unsigned char)(round(coln.x*31.0f));
unsigned char g = (unsigned char)(round(coln.y*31.0f)); unsigned char g = (unsigned char)(round(coln.y*31.0f));
unsigned char b = (unsigned char)(round(coln.z*31.0f)); unsigned char b = (unsigned char)(round(coln.z*31.0f));
unsigned char a = (coln.w > ((float)PIXELFORMAT_UNCOMPRESSED_R5G5B5A1_ALPHA_THRESHOLD/255.0f))? 1 : 0;; unsigned char a = (coln.w > ((float)PIXELFORMAT_UNCOMPRESSED_R5G5B5A1_ALPHA_THRESHOLD/255.0f))? 1 : 0;
((unsigned short *)dst->data)[y*dst->width + x] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a; ((unsigned short *)dst->data)[y*dst->width + x] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a;
@ -2930,7 +2931,7 @@ void GenTextureMipmaps(Texture2D *texture)
{ {
// NOTE: NPOT textures support check inside function // NOTE: NPOT textures support check inside function
// On WebGL (OpenGL ES 2.0) NPOT textures support is limited // On WebGL (OpenGL ES 2.0) NPOT textures support is limited
rlGenerateMipmaps(texture); rlGenTextureMipmaps(texture->id, texture->width, texture->height, texture->format, &texture->mipmaps);
} }
// Set texture scaling filter mode // Set texture scaling filter mode
@ -3806,7 +3807,7 @@ void SetPixelColor(void *dstPtr, Color color, int format)
unsigned char r = (unsigned char)(round(coln.x*31.0f)); unsigned char r = (unsigned char)(round(coln.x*31.0f));
unsigned char g = (unsigned char)(round(coln.y*31.0f)); unsigned char g = (unsigned char)(round(coln.y*31.0f));
unsigned char b = (unsigned char)(round(coln.z*31.0f)); unsigned char b = (unsigned char)(round(coln.z*31.0f));
unsigned char a = (coln.w > ((float)PIXELFORMAT_UNCOMPRESSED_R5G5B5A1_ALPHA_THRESHOLD/255.0f))? 1 : 0;; unsigned char a = (coln.w > ((float)PIXELFORMAT_UNCOMPRESSED_R5G5B5A1_ALPHA_THRESHOLD/255.0f))? 1 : 0;
((unsigned short *)dstPtr)[0] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a; ((unsigned short *)dstPtr)[0] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a;