Merge branch 'raysan5:master' into master
This commit is contained in:
commit
45f27a1d20
9 changed files with 1024 additions and 802 deletions
30
src/config.h
30
src/config.h
|
|
@ -110,22 +110,22 @@
|
|||
|
||||
// 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
|
||||
#define 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 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 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_POSITION "vertexPosition" // Binded by default to shader location: 0
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
||||
#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 DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
||||
#define DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
||||
#define DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
||||
#define 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 DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
||||
#define 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_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
|
|
|||
69
src/core.c
69
src/core.c
|
|
@ -124,19 +124,14 @@
|
|||
#include "config.h" // Defines module configuration flags
|
||||
#endif
|
||||
|
||||
#include "utils.h" // TRACELOG macros
|
||||
#include "utils.h" // Required for: TRACELOG() macros
|
||||
|
||||
#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
|
||||
#define RLGL_IMPLEMENTATION
|
||||
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||
|
||||
#define RAYMATH_IMPLEMENTATION // Define external out-of-line implementation
|
||||
#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)
|
||||
#define GESTURES_IMPLEMENTATION
|
||||
#include "gestures.h" // Gestures detection functionality
|
||||
|
|
@ -164,6 +159,11 @@
|
|||
#include "external/sdefl.h" // Deflate (RFC 1951) compressor
|
||||
#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 <stdio.h> // Required for: sprintf() [Used in OpenURL()]
|
||||
#include <string.h> // Required for: strrchr(), strcmp(), strlen()
|
||||
|
|
@ -643,6 +643,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
|||
#endif
|
||||
|
||||
#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 EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadEvent *gamepadEvent, 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
|
||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 });
|
||||
#else
|
||||
// Set default internal texture (1px white) and rectangle to be used for shapes drawing
|
||||
SetShapesTexture(rlGetTextureDefault(), (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f });
|
||||
// Set default texture and rectangle to be used for shapes drawing
|
||||
// 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
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
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_keydown_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback);
|
||||
|
||||
// Support mouse events
|
||||
emscripten_set_click_callback("#canvas", NULL, 1, EmscriptenMouseCallback);
|
||||
|
||||
// Support touch events
|
||||
emscripten_set_touchstart_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
|
||||
emscripten_set_touchend_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
|
||||
|
|
@ -2171,13 +2177,13 @@ void EndTextureMode(void)
|
|||
// Begin custom shader mode
|
||||
void BeginShaderMode(Shader shader)
|
||||
{
|
||||
rlSetShader(shader);
|
||||
rlSetShader(shader.id, shader.locs);
|
||||
}
|
||||
|
||||
// End custom shader mode (returns to default shader)
|
||||
void EndShaderMode(void)
|
||||
{
|
||||
rlSetShader(rlGetShaderDefault());
|
||||
rlSetShader(rlGetShaderIdDefault(), rlGetShaderLocsDefault());
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
// 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_TEXCOORD01] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
shader.locs[SHADER_LOC_VERTEX_NORMAL] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
shader.locs[SHADER_LOC_VERTEX_TANGENT] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
shader.locs[SHADER_LOC_VERTEX_POSITION] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
shader.locs[SHADER_LOC_VERTEX_TEXCOORD01] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
shader.locs[SHADER_LOC_VERTEX_NORMAL] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
shader.locs[SHADER_LOC_VERTEX_TANGENT] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
|
||||
// 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_VIEW] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_VIEW);
|
||||
shader.locs[SHADER_LOC_MATRIX_PROJECTION] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_PROJECTION);
|
||||
shader.locs[SHADER_LOC_MATRIX_MODEL] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_MODEL);
|
||||
shader.locs[SHADER_LOC_MATRIX_NORMAL] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_UNIFORM_NAME_NORMAL);
|
||||
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP);
|
||||
shader.locs[SHADER_LOC_MATRIX_VIEW] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW);
|
||||
shader.locs[SHADER_LOC_MATRIX_PROJECTION] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION);
|
||||
shader.locs[SHADER_LOC_MATRIX_MODEL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL);
|
||||
shader.locs[SHADER_LOC_MATRIX_NORMAL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL);
|
||||
|
||||
// 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_MAP_DIFFUSE] = rlGetLocationUniform(shader.id, 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_NORMAL] = rlGetLocationUniform(shader.id, DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2);
|
||||
shader.locs[SHADER_LOC_COLOR_DIFFUSE] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR);
|
||||
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, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1); // SHADER_LOC_MAP_METALNESS
|
||||
shader.locs[SHADER_LOC_MAP_NORMAL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2);
|
||||
}
|
||||
|
||||
return shader;
|
||||
|
|
@ -2375,7 +2381,7 @@ RLAPI Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
|
|||
// Unload shader from GPU memory (VRAM)
|
||||
void UnloadShader(Shader shader)
|
||||
{
|
||||
if (shader.id != rlGetShaderDefault().id)
|
||||
if (shader.id != rlGetShaderIdDefault())
|
||||
{
|
||||
rlUnloadShaderProgram(shader.id);
|
||||
RL_FREE(shader.locs);
|
||||
|
|
@ -5568,6 +5574,13 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
|||
#endif
|
||||
|
||||
#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
|
||||
static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
|
||||
{
|
||||
|
|
|
|||
47
src/models.c
47
src/models.c
|
|
@ -40,26 +40,18 @@
|
|||
|
||||
// Check if config flags have been externally provided on compilation line
|
||||
#if !defined(EXTERNAL_CONFIG_FLAGS)
|
||||
#include "config.h" // Defines module configuration flags
|
||||
#include "config.h" // Defines module configuration flags
|
||||
#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 <stdlib.h> // Required for: malloc(), free()
|
||||
#include <string.h> // Required for: memcmp(), strlen()
|
||||
#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)
|
||||
#define TINYOBJ_MALLOC RL_MALLOC
|
||||
#define TINYOBJ_CALLOC RL_CALLOC
|
||||
|
|
@ -89,6 +81,14 @@
|
|||
#include "external/par_shapes.h" // Shapes 3d parametric generation
|
||||
#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
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -1371,7 +1371,11 @@ Material *LoadMaterials(const char *fileName, int *materialCount)
|
|||
// Set materials shader to default (DIFFUSE, SPECULAR, NORMAL)
|
||||
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;
|
||||
|
|
@ -1384,8 +1388,12 @@ Material LoadMaterialDefault(void)
|
|||
Material material = { 0 };
|
||||
material.maps = (MaterialMap *)RL_CALLOC(MAX_MATERIAL_MAPS, sizeof(MaterialMap));
|
||||
|
||||
material.shader = rlGetShaderDefault();
|
||||
material.maps[MATERIAL_MAP_DIFFUSE].texture = rlGetTextureDefault(); // White texture (1x1 pixel)
|
||||
// Using rlgl default shader
|
||||
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_SPECULAR].texture; // NOTE: By default, not set
|
||||
|
||||
|
|
@ -1399,12 +1407,12 @@ Material LoadMaterialDefault(void)
|
|||
void UnloadMaterial(Material material)
|
||||
{
|
||||
// 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)
|
||||
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);
|
||||
|
|
@ -3400,10 +3408,11 @@ static Model LoadOBJ(const char *fileName)
|
|||
// NOTE: Uses default shader, which only supports MATERIAL_MAP_DIFFUSE
|
||||
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
|
||||
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].value = 0.0f;
|
||||
|
|
|
|||
11
src/raudio.c
11
src/raudio.c
|
|
@ -70,11 +70,10 @@
|
|||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||
#else
|
||||
#include "raylib.h" // Declares module functions
|
||||
|
||||
// Check if config flags have been externally provided on compilation line
|
||||
#if !defined(EXTERNAL_CONFIG_FLAGS)
|
||||
#include "config.h" // Defines module configuration flags
|
||||
#endif
|
||||
// Check if config flags have been externally provided on compilation line
|
||||
#if !defined(EXTERNAL_CONFIG_FLAGS)
|
||||
#include "config.h" // Defines module configuration flags
|
||||
#endif
|
||||
#include "utils.h" // Required for: fopen() Android mapping
|
||||
#endif
|
||||
|
||||
|
|
@ -173,7 +172,7 @@ typedef struct tagBITMAPINFOHEADER {
|
|||
#if defined(RAUDIO_STANDALONE)
|
||||
#include <string.h> // Required for: strcmp() [Used in IsFileExtension()]
|
||||
|
||||
#if !defined(TRACELOG)
|
||||
#ifndef TRACELOG
|
||||
#define TRACELOG(level, ...) (void)0
|
||||
#endif
|
||||
|
||||
|
|
|
|||
13
src/raylib.h
13
src/raylib.h
|
|
@ -22,7 +22,7 @@
|
|||
*
|
||||
* NOTES:
|
||||
* 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 RenderBatch is loaded on rlglInit()->rlLoadRenderBatch() [rlgl] (OpenGL 3.3 or ES2)
|
||||
*
|
||||
|
|
@ -128,6 +128,16 @@
|
|||
#define CLITERAL(type) (type)
|
||||
#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
|
||||
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
||||
#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 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 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 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)
|
||||
|
|
|
|||
116
src/raymath.h
116
src/raymath.h
|
|
@ -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:
|
||||
*
|
||||
|
|
@ -9,14 +9,10 @@
|
|||
* 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 RAYMATH_HEADER_ONLY
|
||||
* #define RAYMATH_STATIC_INLINE
|
||||
* Define static inline functions code, so #include header suffices for use.
|
||||
* 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
|
||||
*
|
||||
|
|
@ -42,15 +38,8 @@
|
|||
#ifndef RAYMATH_H
|
||||
#define RAYMATH_H
|
||||
|
||||
//#define RAYMATH_STANDALONE // NOTE: To use raymath as standalone lib, just uncomment this line
|
||||
//#define RAYMATH_HEADER_ONLY // NOTE: To compile functions as static inline, uncomment this line
|
||||
|
||||
#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"
|
||||
#if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_STATIC_INLINE)
|
||||
#error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_STATIC_INLINE is contradictory"
|
||||
#endif
|
||||
|
||||
#if defined(RAYMATH_IMPLEMENTATION)
|
||||
|
|
@ -61,7 +50,7 @@
|
|||
#else
|
||||
#define RMDEF extern inline // Provide external definition
|
||||
#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
|
||||
#else
|
||||
#if defined(__TINYC__)
|
||||
|
|
@ -100,43 +89,61 @@
|
|||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
#if defined(RAYMATH_STANDALONE)
|
||||
// Vector2 type
|
||||
typedef struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
} Vector2;
|
||||
#if !defined(RL_VECTOR2_TYPE)
|
||||
// Vector2 type
|
||||
typedef struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
} Vector2;
|
||||
#define RL_VECTOR2_TYPE
|
||||
#endif
|
||||
|
||||
// Vector3 type
|
||||
typedef struct Vector3 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} Vector3;
|
||||
#if !defined(RL_VECTOR3_TYPE)
|
||||
// Vector3 type
|
||||
typedef struct Vector3 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} Vector3;
|
||||
#define RL_VECTOR3_TYPE
|
||||
#endif
|
||||
|
||||
// Vector4 type
|
||||
typedef struct Vector4 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
} Vector4;
|
||||
#if !defined(RL_VECTOR4_TYPE)
|
||||
// Vector4 type
|
||||
typedef struct Vector4 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
} Vector4;
|
||||
#define RL_VECTOR4_TYPE
|
||||
#endif
|
||||
|
||||
// Quaternion type
|
||||
typedef Vector4 Quaternion;
|
||||
#if !defined(RL_QUATERNION_TYPE)
|
||||
// Quaternion type
|
||||
typedef Vector4 Quaternion;
|
||||
#define RL_QUATERNION_TYPE
|
||||
#endif
|
||||
|
||||
// Matrix type (OpenGL style 4x4 - right handed, column major)
|
||||
typedef struct Matrix {
|
||||
float m0, m4, m8, m12;
|
||||
float m1, m5, m9, m13;
|
||||
float m2, m6, m10, m14;
|
||||
float m3, m7, m11, m15;
|
||||
} Matrix;
|
||||
#if !defined(RL_MATRIX_TYPE)
|
||||
// Matrix type (OpenGL style 4x4 - right handed, column major)
|
||||
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;
|
||||
#define RL_MATRIX_TYPE
|
||||
#endif
|
||||
|
||||
// NOTE: Helper types to be used instead of array return types for *ToFloat functions
|
||||
typedef struct float3 { float v[3]; } float3;
|
||||
typedef struct float16 { float v[16]; } float16;
|
||||
typedef struct float3 {
|
||||
float v[3];
|
||||
} float3;
|
||||
|
||||
typedef struct float16 {
|
||||
float v[16];
|
||||
} float16;
|
||||
|
||||
#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;
|
||||
|
||||
float length, ilength;
|
||||
length = Vector3Length(v);
|
||||
float length, inverseLength;
|
||||
length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
|
||||
if (length == 0.0f) length = 1.0f;
|
||||
ilength = 1.0f/length;
|
||||
inverseLength = 1.0f/length;
|
||||
|
||||
result.x *= ilength;
|
||||
result.y *= ilength;
|
||||
result.z *= ilength;
|
||||
result.x *= inverseLength;
|
||||
result.y *= inverseLength;
|
||||
result.z *= inverseLength;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1424,8 +1431,9 @@ RMDEF Matrix QuaternionToMatrix(Quaternion q)
|
|||
RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
|
||||
{
|
||||
Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
if (Vector3Length(axis) != 0.0f)
|
||||
float axisLength = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z);
|
||||
|
||||
if (axisLength != 0.0f)
|
||||
{
|
||||
angle *= 0.5f;
|
||||
|
||||
|
|
|
|||
1407
src/rlgl.h
1407
src/rlgl.h
File diff suppressed because it is too large
Load diff
|
|
@ -36,7 +36,7 @@
|
|||
#include "config.h" // Defines module configuration flags
|
||||
#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()
|
||||
|
||||
|
|
|
|||
|
|
@ -64,17 +64,14 @@
|
|||
#include "config.h" // Defines module configuration flags
|
||||
#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 <string.h> // Required for: strlen() [Used in ImageTextEx()]
|
||||
#include <math.h> // Required for: fabsf()
|
||||
#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
|
||||
#if !defined(SUPPORT_FILEFORMAT_BMP)
|
||||
#define STBI_NO_BMP
|
||||
|
|
@ -331,12 +328,15 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
|
|||
int comp = 0;
|
||||
image.data = stbi_load_from_memory(fileData, dataSize, &image.width, &image.height, &comp, 0);
|
||||
|
||||
image.mipmaps = 1;
|
||||
if (image.data != NULL)
|
||||
{
|
||||
image.mipmaps = 1;
|
||||
|
||||
if (comp == 1) image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
|
||||
else if (comp == 2) image.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA;
|
||||
else if (comp == 3) image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8;
|
||||
else if (comp == 4) image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
if (comp == 1) image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
|
||||
else if (comp == 2) image.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA;
|
||||
else if (comp == 3) image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8;
|
||||
else if (comp == 4) image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -380,8 +380,9 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
|
|||
#endif
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -393,7 +394,7 @@ Image LoadImageFromTexture(Texture2D texture)
|
|||
|
||||
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)
|
||||
{
|
||||
|
|
@ -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 g = (unsigned char)(round(coln.y*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;
|
||||
|
||||
|
|
@ -2930,7 +2931,7 @@ void GenTextureMipmaps(Texture2D *texture)
|
|||
{
|
||||
// NOTE: NPOT textures support check inside function
|
||||
// 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
|
||||
|
|
@ -3806,7 +3807,7 @@ void SetPixelColor(void *dstPtr, Color color, int format)
|
|||
unsigned char r = (unsigned char)(round(coln.x*31.0f));
|
||||
unsigned char g = (unsigned char)(round(coln.y*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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue