mirror of https://github.com/raysan5/raylib
WARNING: BREAKING CHANGE: rlgl complete decoupling from raylib -WIP-
rlgl has been redesigned to avoid any dependency to `raylib` or `raymath`, all functions using some of those libs have been reviewed. - REMOVED: `Texture2D`, `Shader` structs dependency - REMOVED: `Vector3`, `Matrix` structs dependency - REMOVED: raymath functions dependency, all required math is implemented in rlgl - ADDED: `rlMatrix` custom rlgl type - ADDED: `utils.c`: `rlMatrixFromMatrix()` and `rlMatrixToMatrix()` for a safe conversion between raylib<->rlgl matrix types - ADDED: `rl` prefix to all `rlgl` structs - Other small tweaks here and there
This commit is contained in:
parent
58e9a0894f
commit
8b7f43f89b
|
@ -50,8 +50,11 @@
|
|||
|
||||
#define RLGL_IMPLEMENTATION
|
||||
#define RLGL_STANDALONE
|
||||
#define RLGL_SUPPORT_TRACELOG
|
||||
#include "rlgl.h" // OpenGL 1.1 immediate-mode style coding
|
||||
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||
|
||||
#define RAYMATH_STANDALONE
|
||||
#define RAYMATH_HEADER_ONLY
|
||||
#include "raymath.h" // Vector3, Quaternion and Matrix functionality
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#define GLFW_INCLUDE_ES2
|
||||
|
@ -65,6 +68,9 @@
|
|||
#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo)
|
||||
#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
// Color, 4 components, R8G8B8A8 (32bit)
|
||||
typedef struct Color {
|
||||
unsigned char r; // Color red value
|
||||
|
@ -73,6 +79,21 @@ typedef struct Color {
|
|||
unsigned char a; // Color alpha value
|
||||
} Color;
|
||||
|
||||
#if !defined(RAYMATH_STANDALONE)
|
||||
// Vector2, 2 components
|
||||
typedef struct Vector2 {
|
||||
float x; // Vector x component
|
||||
float y; // Vector y component
|
||||
} Vector2;
|
||||
|
||||
// Vector3, 3 components
|
||||
typedef struct Vector3 {
|
||||
float x; // Vector x component
|
||||
float y; // Vector y component
|
||||
float z; // Vector z component
|
||||
} Vector3;
|
||||
#endif
|
||||
|
||||
// Camera type, defines a camera position/orientation in 3d space
|
||||
typedef struct Camera {
|
||||
Vector3 position; // Camera position
|
||||
|
@ -94,6 +115,24 @@ 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 DrawRectangleV(Vector2 position, Vector2 size, Color color);
|
||||
|
||||
// NOTE: We used raymath to get this functionality but it can be implemented here
|
||||
//static rlMatrix MatrixIdentity(void);
|
||||
//static rlMatrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far);
|
||||
//static rlMatrix MatrixPerspective(double fovy, double aspect, double near, double far);
|
||||
//static rlMatrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up);
|
||||
|
||||
rlMatrix rlMatrixFromMatrix(Matrix mat)
|
||||
{
|
||||
rlMatrix result = {
|
||||
mat.m0, mat.m4, mat.m8, mat.m12, // Matrix first row (4 comat.mponents)
|
||||
mat.m1, mat.m5, mat.m9, mat.m13, // Matrix second row (4 comat.mponents)
|
||||
mat.m2, mat.m6, mat.m10, mat.m14, // Matrix third row (4 comat.mponents)
|
||||
mat.m3, mat.m7, mat.m11, mat.m15, // Matrix fourth row (4 comat.mponents)
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Main Entry point
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -187,8 +226,8 @@ int main(void)
|
|||
Matrix matProj = MatrixPerspective((double)(camera.fovy*DEG2RAD), (double)screenWidth/(double)screenHeight, 0.01, 1000.0);
|
||||
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||
|
||||
rlSetMatrixModelview(matView); // Set internal modelview matrix (default shader)
|
||||
rlSetMatrixProjection(matProj); // Set internal projection matrix (default shader)
|
||||
rlSetMatrixModelview(rlMatrixFromMatrix(matView)); // Set internal modelview matrix (default shader)
|
||||
rlSetMatrixProjection(rlMatrixFromMatrix(matProj)); // Set internal projection matrix (default shader)
|
||||
|
||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, RAYWHITE);
|
||||
|
@ -205,8 +244,8 @@ int main(void)
|
|||
matProj = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0);
|
||||
matView = MatrixIdentity();
|
||||
|
||||
rlSetMatrixModelview(matView); // Set internal modelview matrix (default shader)
|
||||
rlSetMatrixProjection(matProj); // Set internal projection matrix (default shader)
|
||||
rlSetMatrixModelview(rlMatrixFromMatrix(matView)); // Set internal modelview matrix (default shader)
|
||||
rlSetMatrixProjection(rlMatrixFromMatrix(matProj)); // Set internal projection matrix (default shader)
|
||||
|
||||
#else // Let rlgl generate and multiply matrix internally
|
||||
|
||||
|
|
34
src/core.c
34
src/core.c
|
@ -119,19 +119,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
|
||||
|
@ -159,6 +154,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()
|
||||
|
@ -795,8 +795,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)
|
||||
|
@ -2138,13 +2140,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)
|
||||
|
@ -2183,8 +2185,8 @@ void BeginVrStereoMode(VrStereoConfig config)
|
|||
rlEnableStereoRender();
|
||||
|
||||
// Set stereo render matrices
|
||||
rlSetMatrixProjectionStereo(config.projection[0], config.projection[1]);
|
||||
rlSetMatrixViewOffsetStereo(config.viewOffset[0], config.viewOffset[1]);
|
||||
rlSetMatrixProjectionStereo(rlMatrixFromMatrix(config.projection[0]), rlMatrixFromMatrix(config.projection[1]));
|
||||
rlSetMatrixViewOffsetStereo(rlMatrixFromMatrix(config.viewOffset[0]), rlMatrixFromMatrix(config.viewOffset[1]));
|
||||
}
|
||||
|
||||
// End VR drawing process (and desktop mirror)
|
||||
|
@ -2342,7 +2344,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);
|
||||
|
@ -2379,7 +2381,7 @@ void SetShaderValueV(Shader shader, int locIndex, const void *value, int uniform
|
|||
void SetShaderValueMatrix(Shader shader, int locIndex, Matrix mat)
|
||||
{
|
||||
rlEnableShader(shader.id);
|
||||
rlSetUniformMatrix(locIndex, mat);
|
||||
rlSetUniformMatrix(locIndex, rlMatrixFromMatrix(mat));
|
||||
//rlDisableShader();
|
||||
}
|
||||
|
||||
|
|
71
src/models.c
71
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
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -1051,13 +1051,13 @@ void DrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int ins
|
|||
// That's because BeginMode3D() sets it and there is no model-drawing function
|
||||
// that modifies it, all use rlPushMatrix() and rlPopMatrix()
|
||||
Matrix matModel = MatrixIdentity();
|
||||
Matrix matView = rlGetMatrixModelview();
|
||||
Matrix matView = rlMatrixToMatrix(rlGetMatrixModelview());
|
||||
Matrix matModelView = MatrixIdentity();
|
||||
Matrix matProjection = rlGetMatrixProjection();
|
||||
Matrix matProjection = rlMatrixToMatrix(rlGetMatrixProjection());
|
||||
|
||||
// Upload view and projection matrices (if locations available)
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_VIEW] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_VIEW], matView);
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_PROJECTION] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_PROJECTION], matProjection);
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_VIEW] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_VIEW], rlMatrixFromMatrix(matView));
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_PROJECTION] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_PROJECTION], rlMatrixFromMatrix(matProjection));
|
||||
|
||||
if (instancing)
|
||||
{
|
||||
|
@ -1089,24 +1089,24 @@ void DrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int ins
|
|||
|
||||
// Accumulate internal matrix transform (push/pop) and view matrix
|
||||
// NOTE: In this case, model instance transformation must be computed in the shader
|
||||
matModelView = MatrixMultiply(rlGetMatrixTransform(), matView);
|
||||
matModelView = MatrixMultiply(rlMatrixToMatrix(rlGetMatrixTransform()), matView);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Model transformation matrix is send to shader uniform location: SHADER_LOC_MATRIX_MODEL
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_MODEL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_MODEL], transforms[0]);
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_MODEL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_MODEL], rlMatrixFromMatrix(transforms[0]));
|
||||
|
||||
// Accumulate several model transformations:
|
||||
// transforms[0]: model transformation provided (includes DrawModel() params combined with model.transform)
|
||||
// rlGetMatrixTransform(): rlgl internal transform matrix due to push/pop matrix stack
|
||||
matModel = MatrixMultiply(transforms[0], rlGetMatrixTransform());
|
||||
matModel = MatrixMultiply(transforms[0], rlMatrixToMatrix(rlGetMatrixTransform()));
|
||||
|
||||
// Get model-view matrix
|
||||
matModelView = MatrixMultiply(matModel, matView);
|
||||
}
|
||||
|
||||
// Upload model normal matrix (if locations available)
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_NORMAL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_NORMAL], MatrixTranspose(MatrixInvert(matModel)));
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_NORMAL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_NORMAL], rlMatrixFromMatrix(MatrixTranspose(MatrixInvert(matModel))));
|
||||
//-----------------------------------------------------
|
||||
|
||||
// Bind active texture maps (if available)
|
||||
|
@ -1199,11 +1199,11 @@ void DrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int ins
|
|||
{
|
||||
// Setup current eye viewport (half screen width)
|
||||
rlViewport(eye*rlGetFramebufferWidth()/2, 0, rlGetFramebufferWidth()/2, rlGetFramebufferHeight());
|
||||
matModelViewProjection = MatrixMultiply(MatrixMultiply(matModelView, rlGetMatrixViewOffsetStereo(eye)), rlGetMatrixProjectionStereo(eye));
|
||||
matModelViewProjection = MatrixMultiply(MatrixMultiply(matModelView, rlMatrixToMatrix(rlGetMatrixViewOffsetStereo(eye))), rlMatrixToMatrix(rlGetMatrixProjectionStereo(eye)));
|
||||
}
|
||||
|
||||
// Send combined model-view-projection matrix to shader
|
||||
rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_MVP], matModelViewProjection);
|
||||
rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_MVP], rlMatrixFromMatrix(matModelViewProjection));
|
||||
|
||||
if (instancing) // Draw mesh instanced
|
||||
{
|
||||
|
@ -1247,8 +1247,8 @@ void DrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int ins
|
|||
else
|
||||
{
|
||||
// Restore rlgl internal modelview and projection matrices
|
||||
rlSetMatrixModelview(matView);
|
||||
rlSetMatrixProjection(matProjection);
|
||||
rlSetMatrixModelview(rlMatrixFromMatrix(matView));
|
||||
rlSetMatrixProjection(rlMatrixFromMatrix(matProjection));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -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;
|
||||
|
|
|
@ -173,7 +173,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
|
||||
|
||||
|
|
|
@ -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)
|
||||
*
|
||||
|
@ -1315,6 +1315,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)
|
||||
|
|
743
src/rlgl.h
743
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
|
||||
|
@ -397,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)
|
||||
{
|
||||
|
@ -2348,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;
|
||||
|
||||
|
@ -2934,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
|
||||
|
@ -3810,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;
|
||||
|
||||
|
|
23
src/utils.c
23
src/utils.c
|
@ -99,6 +99,29 @@ static int android_close(void *cookie);
|
|||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Utilities
|
||||
//----------------------------------------------------------------------------------
|
||||
rlMatrix rlMatrixFromMatrix(Matrix mat)
|
||||
{
|
||||
rlMatrix result = {
|
||||
mat.m0, mat.m4, mat.m8, mat.m12, // Matrix first row (4 comat.mponents)
|
||||
mat.m1, mat.m5, mat.m9, mat.m13, // Matrix second row (4 comat.mponents)
|
||||
mat.m2, mat.m6, mat.m10, mat.m14, // Matrix third row (4 comat.mponents)
|
||||
mat.m3, mat.m7, mat.m11, mat.m15, // Matrix fourth row (4 comat.mponents)
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix rlMatrixToMatrix(rlMatrix mat)
|
||||
{
|
||||
Matrix result = {
|
||||
mat.m0, mat.m4, mat.m8, mat.m12, // Matrix first row (4 comat.mponents)
|
||||
mat.m1, mat.m5, mat.m9, mat.m13, // Matrix second row (4 comat.mponents)
|
||||
mat.m2, mat.m6, mat.m10, mat.m14, // Matrix third row (4 comat.mponents)
|
||||
mat.m3, mat.m7, mat.m11, mat.m15, // Matrix fourth row (4 comat.mponents)
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Set the current threshold (minimum) log level
|
||||
void SetTraceLogLevel(int logType) { logTypeLevel = logType; }
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#define TRACELOGD(...) (void)0
|
||||
#endif
|
||||
|
||||
#include "rlgl.h" // Required for: rlMatrix
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Some basic Defines
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -67,6 +69,9 @@ extern "C" { // Prevents name mangling of functions
|
|||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
rlMatrix rlMatrixFromMatrix(Matrix mat);
|
||||
Matrix rlMatrixToMatrix(rlMatrix mat);
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
void InitAssetManager(AAssetManager *manager, const char *dataPath); // Initialize asset manager from android app
|
||||
FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen() -> Read-only!
|
||||
|
|
Loading…
Reference in New Issue