Browse Source

First working version of IQM animations

Still a work in progress but it already works...
Current riqm API could be simplified...
pull/589/head
Ray 6 years ago
parent
commit
198a023527
8 changed files with 83 additions and 6458 deletions
  1. +0
    -5466
      examples/others/iqm_loader/glad.h
  2. +3
    -3
      examples/others/iqm_loader/models_iqm_animation.c
  3. BIN
      examples/others/iqm_loader/models_iqm_animation.gif
  4. +55
    -485
      examples/others/iqm_loader/riqm.h
  5. +0
    -500
      examples/others/iqm_loader/rlgl.h
  6. +10
    -2
      release/include/raylib.h
  7. +10
    -2
      src/raylib.h
  8. +5
    -0
      src/rlgl.h

+ 0
- 5466
examples/others/iqm_loader/glad.h
File diff suppressed because it is too large
View File


+ 3
- 3
examples/others/iqm_loader/models_iqm_animation.c View File

@ -77,10 +77,10 @@ int main()
DrawGrid(10, 1.0f); // Draw a grid
EndMode3D();
DrawText("PRESS SPACE to PLAY IQM MODEL ANIMATION", 10, 10, 20, MAROON);
DrawText("(c) Guy IQM 3D model by -------", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawFPS(10, 10);
DrawText("(c) Guy IQM 3D model by @culacant", screenWidth - 200, screenHeight - 20, 10, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------

BIN
examples/others/iqm_loader/models_iqm_animation.gif View File

Before After
Width: 800  |  Height: 450  |  Size: 580 KiB

+ 55
- 485
examples/others/iqm_loader/riqm.h View File

@ -73,36 +73,10 @@ typedef struct Animation {
Pose **framepose;
} Animation;
typedef struct AnimatedMesh {
//Mesh mesh;
// Mesh struct defines:
//-------------------------
int vertexCount;
int triangleCount;
float *vertices;
float *normals;
float *texcoords;
unsigned short *triangles; //equivalent to mes.indices
unsigned int vaoId;
unsigned int vboId[7];
//-------------------------
char name[MESH_NAME_LENGTH];
float *animVertices;
float *animNormals;
float *weightBias;
int *weightId;
} AnimatedMesh;
// Animated Model type
typedef struct AnimatedModel {
int meshCount;
AnimatedMesh *mesh;
Mesh *mesh;
int materialCount;
int *meshMaterialId;
@ -125,15 +99,14 @@ RIQMDEF void UnloadAnimatedModel(AnimatedModel model);
RIQMDEF Animation LoadAnimation(const char *filename);
RIQMDEF void UnloadAnimation(Animation anim);
RIQMDEF AnimatedModel AnimatedModelAddTexture(AnimatedModel model,const char *filename); // GENERIC!
RIQMDEF AnimatedModel SetMeshMaterial(AnimatedModel model,int meshid, int textureid); // GENERIC!
RIQMDEF AnimatedModel AnimatedModelAddTexture(AnimatedModel model, const char *filename); // GENERIC!
RIQMDEF AnimatedModel SetMeshMaterial(AnimatedModel model, int meshid, int textureid); // GENERIC!
// Usage functionality
RIQMDEF bool CheckSkeletonsMatch(AnimatedModel model, Animation anim);
RIQMDEF void AnimateModel(AnimatedModel model, Animation anim, int frame);
RIQMDEF void DrawAnimatedModel(AnimatedModel model,Vector3 position,float scale,Color tint);
RIQMDEF void DrawAnimatedModelEx(AnimatedModel model,Vector3 position,Vector3 rotationAxis,float rotationAngle, Vector3 scale,Color tint);
RIQMDEF void DrawAnimatedModel(AnimatedModel model, Vector3 position, float scale, Color tint);
RIQMDEF void DrawAnimatedModelEx(AnimatedModel model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint);
#endif // RIQM_H
@ -153,10 +126,6 @@ RIQMDEF void DrawAnimatedModelEx(AnimatedModel model,Vector3 position,Vector3 ro
#include <string.h> // Required for: strncmp(),strcpy()
#include "raymath.h" // Required for: Vector3, Quaternion functions
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
#include "glad.h" // Required for OpenGL functions > TO BE REMOVED!
//----------------------------------------------------------------------------------
// Defines and Macros
@ -253,412 +222,8 @@ typedef enum {
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
//----------------------------------------------------------------------------------
void rlLoadAnimatedMesh(AnimatedMesh *amesh, bool dynamic);
void rlUnloadAnimatedMesh(AnimatedMesh *amesh);
void rlUpdateAnimatedMesh(AnimatedMesh *amesh);
void rlDrawAnimatedMesh(AnimatedMesh amesh, Material material, Matrix transform);
static AnimatedModel LoadIQM(const char *filename);
//----------------------------------------------------------------------------------
// Module Functions Definition
//----------------------------------------------------------------------------------
void rlLoadAnimatedMesh(AnimatedMesh *amesh, bool dynamic)
{
amesh->vaoId = 0; // Vertex Array Object
amesh->vboId[0] = 0; // Vertex positions VBO << these are the animated vertices in animVertices
amesh->vboId[1] = 0; // Vertex texcoords VBO
amesh->vboId[2] = 0; // Vertex normals VBO << these are the animated normals in animNormals
amesh->vboId[3] = 0; // Vertex colors VBO
amesh->vboId[4] = 0; // Vertex tangents VBO UNUSED
amesh->vboId[5] = 0; // Vertex texcoords2 VBO UNUSED
amesh->vboId[6] = 0; // Vertex indices VBO
#if defined(GRAPHICS_API_OPENGL_11)
TraceLog(LOG_WARNING, "OGL 11");
#endif
#if defined(GRAPHICS_API_OPENGL_21)
TraceLog(LOG_WARNING, "OGL 21");
#endif
#if defined(GRAPHICS_API_OPENGL_33)
TraceLog(LOG_WARNING, "OGL 33");
#endif
#if defined(GRAPHICS_API_OPENGL_ES2)
TraceLog(LOG_WARNING, "OGL ES2");
#endif
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
int drawHint = GL_STATIC_DRAW;
if (dynamic) drawHint = GL_DYNAMIC_DRAW;
//if (vaoSupported)
{
// Initialize Quads VAO (Buffer A)
glGenVertexArrays(1, &amesh->vaoId);
glBindVertexArray(amesh->vaoId);
}
// NOTE: Attributes must be uploaded considering default locations points
// Enable vertex attributes: position (shader-location = 0)
glGenBuffers(1, &amesh->vboId[0]);
glBindBuffer(GL_ARRAY_BUFFER, amesh->vboId[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*amesh->vertexCount, amesh->animVertices, drawHint);
glVertexAttribPointer(0, 3, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(0);
// Enable vertex attributes: texcoords (shader-location = 1)
glGenBuffers(1, &amesh->vboId[1]);
glBindBuffer(GL_ARRAY_BUFFER, amesh->vboId[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*amesh->vertexCount, amesh->texcoords, drawHint);
glVertexAttribPointer(1, 2, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(1);
// Enable vertex attributes: normals (shader-location = 2)
if (amesh->animNormals != NULL)
{
glGenBuffers(1, &amesh->vboId[2]);
glBindBuffer(GL_ARRAY_BUFFER, amesh->vboId[2]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*amesh->vertexCount, amesh->animNormals, drawHint);
glVertexAttribPointer(2, 3, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(2);
}
else
{
// Default color vertex attribute set to WHITE
glVertexAttrib3f(2, 1.0f, 1.0f, 1.0f);
glDisableVertexAttribArray(2);
}
// colors UNUSED
/*
// Default color vertex attribute (shader-location = 3)
if (mesh->colors != NULL)
{
glGenBuffers(1, &amesh->vboId[3]);
glBindBuffer(GL_ARRAY_BUFFER, amesh->vboId[3]);
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*mesh->vertexCount, mesh->colors, drawHint);
glVertexAttribPointer(3, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
glEnableVertexAttribArray(3);
}
else
{
// Default color vertex attribute set to WHITE
glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f);
glDisableVertexAttribArray(3);
}
*/
// colors to default
glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f);
glDisableVertexAttribArray(3);
// tangents UNUSED
/*
// Default tangent vertex attribute (shader-location = 4)
if (mesh->tangents != NULL)
{
glGenBuffers(1, &mesh->vboId[4]);
glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId[4]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*mesh->vertexCount, mesh->tangents, drawHint);
glVertexAttribPointer(4, 4, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(4);
}
else
{
// Default tangents vertex attribute
glVertexAttrib4f(4, 0.0f, 0.0f, 0.0f, 0.0f);
glDisableVertexAttribArray(4);
}
*/
// tangents to default
glVertexAttrib4f(4, 0.0f, 0.0f, 0.0f, 0.0f);
glDisableVertexAttribArray(4);
// texcoords2 UNUSED
/*
// Default texcoord2 vertex attribute (shader-location = 5)
if (mesh->texcoords2 != NULL)
{
glGenBuffers(1, &mesh->vboId[5]);
glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId[5]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*mesh->vertexCount, mesh->texcoords2, drawHint);
glVertexAttribPointer(5, 2, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(5);
}
else
{
// Default texcoord2 vertex attribute
glVertexAttrib2f(5, 0.0f, 0.0f);
glDisableVertexAttribArray(5);
}
*/
// texcoords2 to default
glVertexAttrib2f(5, 0.0f, 0.0f);
glDisableVertexAttribArray(5);
if (amesh->triangles != NULL)
{
glGenBuffers(1, &amesh->vboId[6]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, amesh->vboId[6]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short)*amesh->triangleCount*3, amesh->triangles, GL_STATIC_DRAW);
}
if (amesh->vaoId > 0) TraceLog(LOG_INFO, "[VAO ID %i] Mesh uploaded successfully to VRAM (GPU)", amesh->vaoId);
else TraceLog(LOG_WARNING, "Mesh could not be uploaded to VRAM (GPU)");
#endif
}
// Unload mesh data from CPU and GPU
void rlUnloadAnimatedMesh(AnimatedMesh *amesh)
{
if (amesh->vertices != NULL) free(amesh->vertices);
if (amesh->animVertices != NULL) free(amesh->animVertices);
if (amesh->texcoords != NULL) free(amesh->texcoords);
if (amesh->normals != NULL) free(amesh->normals);
if (amesh->animNormals != NULL) free(amesh->animNormals);
// if (mesh->colors != NULL) free(mesh->colors);
// if (mesh->tangents != NULL) free(mesh->tangents);
// if (mesh->texcoords2 != NULL) free(mesh->texcoords2);
if (amesh->triangles != NULL) free(amesh->triangles);
if (amesh->weightId != NULL) free(amesh->weightId);
if (amesh->weightBias != NULL) free(amesh->weightBias);
rlDeleteBuffers(amesh->vboId[0]); // vertex
rlDeleteBuffers(amesh->vboId[1]); // texcoords
rlDeleteBuffers(amesh->vboId[2]); // normals
rlDeleteBuffers(amesh->vboId[3]); // colors
rlDeleteBuffers(amesh->vboId[4]); // tangents
rlDeleteBuffers(amesh->vboId[5]); // texcoords2
rlDeleteBuffers(amesh->vboId[6]); // indices
rlDeleteVertexArrays(amesh->vaoId);
}
// Update vertex and normal data into GPU
void rlUpdateAnimatedMesh(AnimatedMesh *amesh)
{
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Activate mesh VAO
glBindVertexArray(amesh->vaoId);
// Update positions data
glBindBuffer(GL_ARRAY_BUFFER, amesh->vboId[0]);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*amesh->vertexCount, amesh->animVertices);
// Update normals data
glBindBuffer(GL_ARRAY_BUFFER, amesh->vboId[2]);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*amesh->vertexCount, amesh->animNormals);
// Unbind the current VAO
glBindVertexArray(0);
//mesh.vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
// Now we can modify vertices
//glUnmapBuffer(GL_ARRAY_BUFFER);
#endif
}
// Draw a 3d mesh with material and transform
void rlDrawAnimatedMesh(AnimatedMesh amesh, Material material, Matrix transform)
{
#if defined(GRAPHICS_API_OPENGL_11)
/*
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, material.maps[MAP_DIFFUSE].texture.id);
// NOTE: On OpenGL 1.1 we use Vertex Arrays to draw model
glEnableClientState(GL_VERTEX_ARRAY); // Enable vertex array
glEnableClientState(GL_TEXTURE_COORD_ARRAY); // Enable texture coords array
//if (amesh.normals != NULL) glEnableClientState(GL_NORMAL_ARRAY); // Enable normals array
//if (amesh.colors != NULL) glEnableClientState(GL_COLOR_ARRAY); // Enable colors array
glVertexPointer(3, GL_FLOAT, 0, amesh.animVertices); // Pointer to vertex coords array
glTexCoordPointer(2, GL_FLOAT, 0, amesh.texcoords); // Pointer to texture coords array
if (amesh.animNormals != NULL) glNormalPointer(GL_FLOAT, 0, amesh.animNormals); // Pointer to normals array
//if (mesh.colors != NULL) glColorPointer(4, GL_UNSIGNED_BYTE, 0, mesh.colors); // Pointer to colors array
rlPushMatrix();
rlMultMatrixf(MatrixToFloat(transform));
rlColor4ub(material.maps[MAP_DIFFUSE].color.r, material.maps[MAP_DIFFUSE].color.g, material.maps[MAP_DIFFUSE].color.b, material.maps[MAP_DIFFUSE].color.a);
if (amesh.triangles != NULL) glDrawElements(GL_TRIANGLES, amesh.triangleCount*3, GL_UNSIGNED_SHORT, amesh.triangles);
else glDrawArrays(GL_TRIANGLES, 0, amesh.vertexCount);
rlPopMatrix();
glDisableClientState(GL_VERTEX_ARRAY); // Disable vertex array
glDisableClientState(GL_TEXTURE_COORD_ARRAY); // Disable texture coords array
if (amesh.animNormals != NULL) glDisableClientState(GL_NORMAL_ARRAY); // Disable normals array
//if (mesh.colors != NULL) glDisableClientState(GL_NORMAL_ARRAY); // Disable colors array
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
*/
#endif
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Bind shader program
glUseProgram(material.shader.id);
// Matrices and other values required by shader
//-----------------------------------------------------
// Calculate and send to shader model matrix (used by PBR shader)
if (material.shader.locs[LOC_MATRIX_MODEL] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_MODEL], transform);
// Upload to shader material.colDiffuse
if (material.shader.locs[LOC_COLOR_DIFFUSE] != -1)
glUniform4f(material.shader.locs[LOC_COLOR_DIFFUSE], (float)material.maps[MAP_DIFFUSE].color.r/255.0f,
(float)material.maps[MAP_DIFFUSE].color.g/255.0f,
(float)material.maps[MAP_DIFFUSE].color.b/255.0f,
(float)material.maps[MAP_DIFFUSE].color.a/255.0f);
// Upload to shader material.colSpecular (if available)
if (material.shader.locs[LOC_COLOR_SPECULAR] != -1)
glUniform4f(material.shader.locs[LOC_COLOR_SPECULAR], (float)material.maps[MAP_SPECULAR].color.r/255.0f,
(float)material.maps[MAP_SPECULAR].color.g/255.0f,
(float)material.maps[MAP_SPECULAR].color.b/255.0f,
(float)material.maps[MAP_SPECULAR].color.a/255.0f);
if (material.shader.locs[LOC_MATRIX_VIEW] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_VIEW], GetMatrixModelview());
if (material.shader.locs[LOC_MATRIX_PROJECTION] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_PROJECTION], projection);
// At this point the modelview matrix just contains the view matrix (camera)
// That's because BeginMode3D() sets it an no model-drawing function modifies it, all use rlPushMatrix() and rlPopMatrix()
Matrix matView = GetMatrixModelview(); // View matrix (camera)
Matrix matProjection = projection; // Projection matrix (perspective)
// Calculate model-view matrix combining matModel and matView
Matrix matModelView = MatrixMultiply(transform, matView); // Transform to camera-space coordinates
//-----------------------------------------------------
// Bind active texture maps (if available)
for (int i = 0; i < MAX_MATERIAL_MAPS; i++)
{
if (material.maps[i].texture.id > 0)
{
glActiveTexture(GL_TEXTURE0 + i);
if ((i == MAP_IRRADIANCE) || (i == MAP_PREFILTER) || (i == MAP_CUBEMAP)) glBindTexture(GL_TEXTURE_CUBE_MAP, material.maps[i].texture.id);
else glBindTexture(GL_TEXTURE_2D, material.maps[i].texture.id);
glUniform1i(material.shader.locs[LOC_MAP_DIFFUSE + i], i);
}
}
glBindVertexArray(amesh.vaoId);
/*
// Bind vertex array objects (or VBOs)
if (vaoSupported) glBindVertexArray(amesh.vaoId);
else
{
// TODO: Simplify VBO binding into a for loop
// Bind mesh VBO data: vertex position (shader-location = 0)
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[0]);
glVertexAttribPointer(material.shader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_POSITION]);
// Bind mesh VBO data: vertex texcoords (shader-location = 1)
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[1]);
glVertexAttribPointer(material.shader.locs[LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_TEXCOORD01]);
// Bind mesh VBO data: vertex normals (shader-location = 2, if available)
if (material.shader.locs[LOC_VERTEX_NORMAL] != -1)
{
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[2]);
glVertexAttribPointer(material.shader.locs[LOC_VERTEX_NORMAL], 3, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_NORMAL]);
}
// Bind mesh VBO data: vertex colors (shader-location = 3, if available)
if (material.shader.locs[LOC_VERTEX_COLOR] != -1)
{
if (amesh.vboId[3] != 0)
{
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[3]);
glVertexAttribPointer(material.shader.locs[LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_COLOR]);
}
else
{
// Set default value for unused attribute
// NOTE: Required when using default shader and no VAO support
glVertexAttrib4f(material.shader.locs[LOC_VERTEX_COLOR], 1.0f, 1.0f, 1.0f, 1.0f);
glDisableVertexAttribArray(material.shader.locs[LOC_VERTEX_COLOR]);
}
}
// Bind mesh VBO data: vertex tangents (shader-location = 4, if available)
if (material.shader.locs[LOC_VERTEX_TANGENT] != -1)
{
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[4]);
glVertexAttribPointer(material.shader.locs[LOC_VERTEX_TANGENT], 4, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_TANGENT]);
}
// Bind mesh VBO data: vertex texcoords2 (shader-location = 5, if available)
if (material.shader.locs[LOC_VERTEX_TEXCOORD02] != -1)
{
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[5]);
glVertexAttribPointer(material.shader.locs[LOC_VERTEX_TEXCOORD02], 2, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_TEXCOORD02]);
}
if (amesh.triangles != NULL) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, amesh.vboId[6]);
}
*/
int eyesCount = 1;
#if defined(SUPPORT_VR_SIMULATOR)
if (vrStereoRender) eyesCount = 2;
#endif
for (int eye = 0; eye < eyesCount; eye++)
{
if (eyesCount == 1) modelview = matModelView;
#if defined(SUPPORT_VR_SIMULATOR)
else SetStereoView(eye, matProjection, matModelView);
#endif
// Calculate model-view-projection matrix (MVP)
Matrix matMVP = MatrixMultiply(modelview, projection); // Transform to screen-space coordinates
// Send combined model-view-projection matrix to shader
glUniformMatrix4fv(material.shader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(matMVP));
// Draw call!
if (amesh.triangles != NULL) glDrawElements(GL_TRIANGLES, amesh.triangleCount*3, GL_UNSIGNED_SHORT, 0); // Indexed vertices draw
else glDrawArrays(GL_TRIANGLES, 0, amesh.vertexCount);
}
// Unbind all binded texture maps
for (int i = 0; i < MAX_MATERIAL_MAPS; i++)
{
glActiveTexture(GL_TEXTURE0 + i); // Set shader active texture
if ((i == MAP_IRRADIANCE) || (i == MAP_PREFILTER) || (i == MAP_CUBEMAP)) glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
else glBindTexture(GL_TEXTURE_2D, 0); // Unbind current active texture
}
glBindVertexArray(0);
/*
// Unind vertex array objects (or VBOs)
if (vaoSupported) glBindVertexArray(0);
else
{
glBindBuffer(GL_ARRAY_BUFFER, 0);
if (amesh.triangles != NULL) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
*/
// Unbind shader program
glUseProgram(0);
// Restore projection/modelview matrices
// NOTE: In stereo rendering matrices are being modified to fit every eye
projection = matProjection;
modelview = matView;
#endif
}
#ifdef __cplusplus
extern "C" { // Prevents name mangling of functions
#endif
@ -668,7 +233,7 @@ AnimatedModel LoadAnimatedModel(const char *filename)
{
AnimatedModel out = LoadIQM(filename);
for (int i = 0; i < out.meshCount; i++) rlLoadAnimatedMesh(&out.mesh[i], false);
for (int i = 0; i < out.meshCount; i++) rlLoadMesh(&out.mesh[i], false);
out.transform = MatrixIdentity();
out.meshMaterialId = malloc(sizeof(int)*out.meshCount);
@ -901,7 +466,7 @@ void UnloadAnimatedModel(AnimatedModel model)
free(model.joints);
free(model.basepose);
for (int i = 0; i < model.meshCount; i++) rlUnloadAnimatedMesh(&model.mesh[i]);
for (int i = 0; i < model.meshCount; i++) rlUnloadMesh(&model.mesh[i]);
free(model.mesh);
}
@ -961,21 +526,23 @@ void AnimateModel(AnimatedModel model, Animation anim, int frame)
outs = anim.framepose[frame][weightId].scale;
// vertices
outv = (Vector3){model.mesh[m].vertices[vcounter],model.mesh[m].vertices[vcounter + 1],model.mesh[m].vertices[vcounter + 2]};
outv = Vector3MultiplyV(outv,outs);
outv = Vector3Subtract(outv,baset);
outv = Vector3RotateByQuaternion(outv,QuaternionMultiply(outr,QuaternionInvert(baser)));
outv = Vector3Add(outv,outt);
model.mesh[m].animVertices[vcounter] = outv.x;
model.mesh[m].animVertices[vcounter + 1] = outv.y;
model.mesh[m].animVertices[vcounter + 2] = outv.z;
// NOTE: We use mesh.baseVertices (default position) to calculate mesh.vertices (animated position)
outv = (Vector3){ model.mesh[m].baseVertices[vcounter], model.mesh[m].baseVertices[vcounter + 1], model.mesh[m].baseVertices[vcounter + 2] };
outv = Vector3MultiplyV(outv, outs);
outv = Vector3Subtract(outv, baset);
outv = Vector3RotateByQuaternion(outv, QuaternionMultiply(outr, QuaternionInvert(baser)));
outv = Vector3Add(outv, outt);
model.mesh[m].vertices[vcounter] = outv.x;
model.mesh[m].vertices[vcounter + 1] = outv.y;
model.mesh[m].vertices[vcounter + 2] = outv.z;
// normals
outn = (Vector3){model.mesh[m].normals[vcounter],model.mesh[m].normals[vcounter + 1],model.mesh[m].normals[vcounter + 2]};
outn = Vector3RotateByQuaternion(outn,QuaternionMultiply(outr,QuaternionInvert(baser)));
model.mesh[m].animNormals[vcounter] = outn.x;
model.mesh[m].animNormals[vcounter + 1] = outn.y;
model.mesh[m].animNormals[vcounter + 2] = outn.z;
// NOTE: We use mesh.baseNormals (default normal) to calculate mesh.normals (animated normals)
outn = (Vector3){ model.mesh[m].baseNormals[vcounter], model.mesh[m].baseNormals[vcounter + 1], model.mesh[m].baseNormals[vcounter + 2] };
outn = Vector3RotateByQuaternion(outn, QuaternionMultiply(outr, QuaternionInvert(baser)));
model.mesh[m].normals[vcounter] = outn.x;
model.mesh[m].normals[vcounter + 1] = outn.y;
model.mesh[m].normals[vcounter + 2] = outn.z;
vcounter += 3;
wcounter += 4;
}
@ -983,16 +550,16 @@ void AnimateModel(AnimatedModel model, Animation anim, int frame)
}
// Draw an animated model
void DrawAnimatedModel(AnimatedModel model,Vector3 position,float scale,Color tint)
void DrawAnimatedModel(AnimatedModel model, Vector3 position, float scale, Color tint)
{
Vector3 vScale = { scale, scale, scale };
Vector3 rotationAxis = { 0.0f,0.0f,0.0f };
Vector3 rotationAxis = { 1.0f, 0.0f,0.0f };
DrawAnimatedModelEx(model, position, rotationAxis, 0.0f, vScale, tint);
DrawAnimatedModelEx(model, position, rotationAxis, o">-90.0f, vScale, tint);
}
// Draw an animated model with extended parameters
void DrawAnimatedModelEx(AnimatedModel model,Vector3 position,Vector3 rotationAxis,float rotationAngle, Vector3 scale,Color tint)
void DrawAnimatedModelEx(AnimatedModel model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
{
if (model.materialCount == 0)
{
@ -1000,25 +567,21 @@ void DrawAnimatedModelEx(AnimatedModel model,Vector3 position,Vector3 rotationAx
return;
}
Matrix matScale = MatrixScale(scale.x,scale.y,scale.z);
Matrix matRotation = MatrixRotate(rotationAxis,rotationAngle*DEG2RAD);
Matrix matTranslation = MatrixTranslate(position.x,position.y,position.z);
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD);
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
Matrix matTransform = MatrixMultiply(MatrixMultiply(matScale,matRotation),matTranslation);
model.transform = MatrixMultiply(model.transform,matTransform);
Matrix matTransform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
model.transform = MatrixMultiply(model.transform, matTransform);
for (int i = 0; i < model.meshCount; i++)
{
rlUpdateAnimatedMesh(&model.mesh[i]);
rlDrawAnimatedMesh(model.mesh[i],model.materials[model.meshMaterialId[i]],MatrixIdentity());
rlUpdateMesh(model.mesh[i], 0, model.mesh[i].vertexCount); // Update vertex position
rlUpdateMesh(model.mesh[i], 2, model.mesh[i].vertexCount); // Update vertex normals
rlDrawMesh(model.mesh[i], model.materials[model.meshMaterialId[i]], model.transform); // Draw mesh
}
}
// Load animated model meshes from IQM file
static AnimatedModel LoadIQM(const char *filename)
{
@ -1069,22 +632,29 @@ static AnimatedModel LoadIQM(const char *filename)
fread(imesh, sizeof(IQMMesh)*iqm.num_meshes, 1, iqmFile);
model.meshCount = iqm.num_meshes;
model.mesh = malloc(sizeof(AnimatedMesh)*iqm.num_meshes);
model.mesh = malloc(sizeof(Mesh)*iqm.num_meshes);
char name[MESH_NAME_LENGTH];
for (int i = 0; i < iqm.num_meshes; i++)
{
fseek(iqmFile,iqm.ofs_text+imesh[i].name,SEEK_SET);
fread(model.mesh[i].name, sizeof(char)*MESH_NAME_LENGTH, 1, iqmFile);
fread(name, sizeof(char)*MESH_NAME_LENGTH, 1, iqmFile); // Mesh name not used...
model.mesh[i].vertexCount = imesh[i].num_vertexes;
model.mesh[i].vertices = malloc(sizeof(float)*imesh[i].num_vertexes*3);
model.mesh[i].normals = malloc(sizeof(float)*imesh[i].num_vertexes*3);
model.mesh[i].baseVertices = malloc(sizeof(float)*imesh[i].num_vertexes*3); // Default IQM base position
model.mesh[i].baseNormals = malloc(sizeof(float)*imesh[i].num_vertexes*3); // Default IQM base normal
model.mesh[i].texcoords = malloc(sizeof(float)*imesh[i].num_vertexes*2);
model.mesh[i].weightId = malloc(sizeof(int)*imesh[i].num_vertexes*4);
model.mesh[i].weightBias = malloc(sizeof(float)*imesh[i].num_vertexes*4);
model.mesh[i].triangleCount = imesh[i].num_triangles;
model.mesh[i].triangles = malloc(sizeof(unsigned short)*imesh[i].num_triangles*3);
model.mesh[i].animVertices = malloc(sizeof(float)*imesh[i].num_vertexes*3);
model.mesh[i].animNormals = malloc(sizeof(float)*imesh[i].num_vertexes*3);
model.mesh[i].indices = malloc(sizeof(unsigned short)*imesh[i].num_triangles*3);
// What we actually process for rendering, should be updated transforming mesh.vertices and mesh.normals
model.mesh[i].vertices = malloc(sizeof(float)*imesh[i].num_vertexes*3);
model.mesh[i].normals = malloc(sizeof(float)*imesh[i].num_vertexes*3);
}
// tris
@ -1096,12 +666,12 @@ static AnimatedModel LoadIQM(const char *filename)
{
int tcounter = 0;
for (int i=imesh[m].first_triangle; i < imesh[m].first_triangle+imesh[m].num_triangles; i++)
for (int i = imesh[m].first_triangle; i < imesh[m].first_triangle+imesh[m].num_triangles; i++)
{
// IQM triangles are stored counter clockwise, but raylib sets opengl to clockwise drawing, so we swap them around
model.mesh[m].triangles[tcounter+2] = tri[i].vertex[0] - imesh[m].first_vertex;
model.mesh[m].triangles[tcounter+1] = tri[i].vertex[1] - imesh[m].first_vertex;
model.mesh[m].triangles[tcounter] = tri[i].vertex[2] - imesh[m].first_vertex;
model.mesh[m].indices[tcounter+2] = tri[i].vertex[0] - imesh[m].first_vertex;
model.mesh[m].indices[tcounter+1] = tri[i].vertex[1] - imesh[m].first_vertex;
model.mesh[m].indices[tcounter] = tri[i].vertex[2] - imesh[m].first_vertex;
tcounter += 3;
}
}
@ -1127,7 +697,7 @@ static AnimatedModel LoadIQM(const char *filename)
for (int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++)
{
model.mesh[m].vertices[vcounter] = vertex[i];
model.mesh[m].animVertices[vcounter] = vertex[i];
model.mesh[m].baseVertices[vcounter] = vertex[i];
vcounter++;
}
}
@ -1144,7 +714,7 @@ static AnimatedModel LoadIQM(const char *filename)
for (int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++)
{
model.mesh[m].normals[vcounter] = normal[i];
model.mesh[m].animNormals[vcounter] = normal[i];
model.mesh[m].baseNormals[vcounter] = normal[i];
vcounter++;
}
}

+ 0
- 500
examples/others/iqm_loader/rlgl.h View File

@ -1,500 +0,0 @@
/**********************************************************************************************
*
* rlgl - raylib OpenGL abstraction layer
*
* rlgl is a wrapper for multiple OpenGL versions (1.1, 2.1, 3.3 Core, ES 2.0) to
* pseudo-OpenGL 1.1 style functions (rlVertex, rlTranslate, rlRotate...).
*
* When chosing an OpenGL version greater than OpenGL 1.1, rlgl stores vertex data on internal
* VBO buffers (and VAOs if available). It requires calling 3 functions:
* rlglInit() - Initialize internal buffers and auxiliar resources
* rlglDraw() - Process internal buffers and send required draw calls
* rlglClose() - De-initialize internal buffers data and other auxiliar resources
*
* CONFIGURATION:
*
* #define GRAPHICS_API_OPENGL_11
* #define GRAPHICS_API_OPENGL_21
* #define GRAPHICS_API_OPENGL_33
* #define GRAPHICS_API_OPENGL_ES2
* Use selected OpenGL graphics backend, should be supported by platform
* Those preprocessor defines are only used on rlgl module, if OpenGL version is
* required by any other module, use rlGetVersion() tocheck it
*
* #define RLGL_STANDALONE
* Use rlgl as standalone library (no raylib dependency)
*
* #define SUPPORT_VR_SIMULATOR
* Support VR simulation functionality (stereo rendering)
*
* #define SUPPORT_DISTORTION_SHADER
* Include stereo rendering distortion shader (shader_distortion.h)
*
* DEPENDENCIES:
* raymath - 3D math functionality (Vector3, Matrix, Quaternion)
* GLAD - OpenGL extensions loading (OpenGL 3.3 Core only)
*
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2014-2017 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you
* wrote the original software. If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
**********************************************************************************************/
#ifndef RLGL_H
#define RLGL_H
#if defined(RLGL_STANDALONE)
#define RAYMATH_STANDALONE
#else
#include "raylib.h" // Required for: Model, Shader, Texture2D, TraceLog()
#endif
#include "raymath.h" // Required for: Vector3, Matrix
// Security check in case no GRAPHICS_API_OPENGL_* defined
#if !defined(GRAPHICS_API_OPENGL_11) && !defined(GRAPHICS_API_OPENGL_21) && !defined(GRAPHICS_API_OPENGL_33) && !defined(GRAPHICS_API_OPENGL_ES2)
#define GRAPHICS_API_OPENGL_33
#endif
// Security check in case multiple GRAPHICS_API_OPENGL_* defined
#if defined(GRAPHICS_API_OPENGL_11)
#if defined(GRAPHICS_API_OPENGL_21)
#undef GRAPHICS_API_OPENGL_21
#endif
#if defined(GRAPHICS_API_OPENGL_33)
#undef GRAPHICS_API_OPENGL_33
#endif
#if defined(GRAPHICS_API_OPENGL_ES2)
#undef GRAPHICS_API_OPENGL_ES2
#endif
#endif
#if defined(GRAPHICS_API_OPENGL_21)
#define GRAPHICS_API_OPENGL_33
#endif
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
// NOTE: This is the maximum amount of lines, triangles and quads per frame, be careful!
#define MAX_LINES_BATCH 8192
#define MAX_TRIANGLES_BATCH 4096
#define MAX_QUADS_BATCH 8192
#elif defined(GRAPHICS_API_OPENGL_ES2)
// NOTE: Reduce memory sizes for embedded systems (RPI and HTML5)
// NOTE: On HTML5 (emscripten) this is allocated on heap, by default it's only 16MB!...just take care...
#define MAX_LINES_BATCH 1024 // Critical for wire shapes (sphere)
#define MAX_TRIANGLES_BATCH 2048 // Critical for some shapes (sphere)
#define MAX_QUADS_BATCH 1024 // Be careful with text, every letter maps a quad
#endif
// Texture parameters (equivalent to OpenGL defines)
#define RL_TEXTURE_WRAP_S 0x2802 // GL_TEXTURE_WRAP_S
#define RL_TEXTURE_WRAP_T 0x2803 // GL_TEXTURE_WRAP_T
#define RL_TEXTURE_MAG_FILTER 0x2800 // GL_TEXTURE_MAG_FILTER
#define RL_TEXTURE_MIN_FILTER 0x2801 // GL_TEXTURE_MIN_FILTER
#define RL_TEXTURE_ANISOTROPIC_FILTER 0x3000 // Anisotropic filter (custom identifier)
#define RL_FILTER_NEAREST 0x2600 // GL_NEAREST
#define RL_FILTER_LINEAR 0x2601 // GL_LINEAR
#define RL_FILTER_MIP_NEAREST 0x2700 // GL_NEAREST_MIPMAP_NEAREST
#define RL_FILTER_NEAREST_MIP_LINEAR 0x2702 // GL_NEAREST_MIPMAP_LINEAR
#define RL_FILTER_LINEAR_MIP_NEAREST 0x2701 // GL_LINEAR_MIPMAP_NEAREST
#define RL_FILTER_MIP_LINEAR 0x2703 // GL_LINEAR_MIPMAP_LINEAR
#define RL_WRAP_REPEAT 0x2901 // GL_REPEAT
#define RL_WRAP_CLAMP 0x812F // GL_CLAMP_TO_EDGE
#define RL_WRAP_CLAMP_MIRROR 0x8742 // GL_MIRROR_CLAMP_EXT
// Matrix modes (equivalent to OpenGL)
#define RL_MODELVIEW 0x1700 // GL_MODELVIEW
#define RL_PROJECTION 0x1701 // GL_PROJECTION
#define RL_TEXTURE 0x1702 // GL_TEXTURE
// Primitive assembly draw modes
#define RL_LINES 0x0001 // GL_LINES
#define RL_TRIANGLES 0x0004 // GL_TRIANGLES
#define RL_QUADS 0x0007 // GL_QUADS
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef enum { OPENGL_11 = 1, OPENGL_21, OPENGL_33, OPENGL_ES_20 } GlVersion;
typedef unsigned char byte;
#if defined(RLGL_STANDALONE)
#ifndef __cplusplus
// Boolean type
typedef enum { false, true } bool;
#endif
// Color type, RGBA (32bit)
typedef struct Color {
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
} Color;
// Rectangle type
typedef struct Rectangle {
int x;
int y;
int width;
int height;
} Rectangle;
// Texture2D type
// NOTE: Data stored in GPU memory
typedef struct Texture2D {
unsigned int id; // OpenGL texture id
int width; // Texture base width
int height; // Texture base height
int mipmaps; // Mipmap levels, 1 by default
int format; // Data format (PixelFormat)
} Texture2D;
// RenderTexture2D type, for texture rendering
typedef struct RenderTexture2D {
unsigned int id; // Render texture (fbo) id
Texture2D texture; // Color buffer attachment texture
Texture2D depth; // Depth buffer attachment texture
} RenderTexture2D;
// Vertex data definning a mesh
typedef struct Mesh {
int vertexCount; // number of vertices stored in arrays
int triangleCount; // number of triangles stored (indexed or not)
float *vertices; // vertex position (XYZ - 3 components per vertex) (shader-location = 0)
float *texcoords; // vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
float *texcoords2; // vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
float *normals; // vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
float *tangents; // vertex tangents (XYZW - 4 components per vertex) (shader-location = 4)
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
unsigned short *indices;// vertex indices (in case vertex data comes indexed)
unsigned int vaoId; // OpenGL Vertex Array Object id
unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (7 types of vertex data)
} Mesh;
// Shader and material limits
#define MAX_SHADER_LOCATIONS 32
#define MAX_MATERIAL_MAPS 12
// Shader type (generic)
typedef struct Shader {
unsigned int id; // Shader program id
int locs[MAX_SHADER_LOCATIONS]; // Shader locations array
} Shader;
// Material texture map
typedef struct MaterialMap {
Texture2D texture; // Material map texture
Color color; // Material map color
float value; // Material map value
} MaterialMap;
// Material type (generic)
typedef struct Material {
Shader shader; // Material shader
MaterialMap maps[MAX_MATERIAL_MAPS]; // Material maps
float *params; // Material generic parameters (if required)
} Material;
// Camera type, defines a camera position/orientation in 3d space
typedef struct Camera {
Vector3 position; // Camera position
Vector3 target; // Camera target it looks-at
Vector3 up; // Camera up vector (rotation over its axis)
float fovy; // Camera field-of-view apperture in Y (degrees)
} Camera;
// Head-Mounted-Display device parameters
typedef struct VrDeviceInfo {
int hResolution; // HMD horizontal resolution in pixels
int vResolution; // HMD vertical resolution in pixels
float hScreenSize; // HMD horizontal size in meters
float vScreenSize; // HMD vertical size in meters
float vScreenCenter; // HMD screen center in meters
float eyeToScreenDistance; // HMD distance between eye and display in meters
float lensSeparationDistance; // HMD lens separation distance in meters
float interpupillaryDistance; // HMD IPD (distance between pupils) in meters
float lensDistortionValues[4]; // HMD lens distortion constant parameters
float chromaAbCorrection[4]; // HMD chromatic aberration correction parameters
} VrDeviceInfo;
// TraceLog message types
typedef enum {
LOG_INFO = 0,
LOG_ERROR,
LOG_WARNING,
LOG_DEBUG,
LOG_OTHER
} TraceLogType;
// Texture formats (support depends on OpenGL version)
typedef enum {
UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
UNCOMPRESSED_GRAY_ALPHA,
UNCOMPRESSED_R5G6B5, // 16 bpp
UNCOMPRESSED_R8G8B8, // 24 bpp
UNCOMPRESSED_R5G5B5A1, // 16 bpp (1 bit alpha)
UNCOMPRESSED_R4G4B4A4, // 16 bpp (4 bit alpha)
UNCOMPRESSED_R8G8B8A8, // 32 bpp
UNCOMPRESSED_R32, // 32 bpp (1 channel - float)
UNCOMPRESSED_R32G32B32, // 32*3 bpp (3 channels - float)
UNCOMPRESSED_R32G32B32A32, // 32*4 bpp (4 channels - float)
COMPRESSED_DXT1_RGB, // 4 bpp (no alpha)
COMPRESSED_DXT1_RGBA, // 4 bpp (1 bit alpha)
COMPRESSED_DXT3_RGBA, // 8 bpp
COMPRESSED_DXT5_RGBA, // 8 bpp
COMPRESSED_ETC1_RGB, // 4 bpp
COMPRESSED_ETC2_RGB, // 4 bpp
COMPRESSED_ETC2_EAC_RGBA, // 8 bpp
COMPRESSED_PVRT_RGB, // 4 bpp
COMPRESSED_PVRT_RGBA, // 4 bpp
COMPRESSED_ASTC_4x4_RGBA, // 8 bpp
COMPRESSED_ASTC_8x8_RGBA // 2 bpp
} PixelFormat;
// Texture parameters: filter mode
// NOTE 1: Filtering considers mipmaps if available in the texture
// NOTE 2: Filter is accordingly set for minification and magnification
typedef enum {
FILTER_POINT = 0, // No filter, just pixel aproximation
FILTER_BILINEAR, // Linear filtering
FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps)
FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x
FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x
FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x
} TextureFilterMode;
// Texture parameters: wrap mode
typedef enum {
WRAP_REPEAT = 0,
WRAP_CLAMP,
WRAP_MIRROR
} TextureWrapMode;
// Color blending modes (pre-defined)
typedef enum {
BLEND_ALPHA = 0,
BLEND_ADDITIVE,
BLEND_MULTIPLIED
} BlendMode;
// Shader location point type
typedef enum {
LOC_VERTEX_POSITION = 0,
LOC_VERTEX_TEXCOORD01,
LOC_VERTEX_TEXCOORD02,
LOC_VERTEX_NORMAL,
LOC_VERTEX_TANGENT,
LOC_VERTEX_COLOR,
LOC_MATRIX_MVP,
LOC_MATRIX_MODEL,
LOC_MATRIX_VIEW,
LOC_MATRIX_PROJECTION,
LOC_VECTOR_VIEW,
LOC_COLOR_DIFFUSE,
LOC_COLOR_SPECULAR,
LOC_COLOR_AMBIENT,
LOC_MAP_ALBEDO, // LOC_MAP_DIFFUSE
LOC_MAP_METALNESS, // LOC_MAP_SPECULAR
LOC_MAP_NORMAL,
LOC_MAP_ROUGHNESS,
LOC_MAP_OCCLUSION,
LOC_MAP_EMISSION,
LOC_MAP_HEIGHT,
LOC_MAP_CUBEMAP,
LOC_MAP_IRRADIANCE,
LOC_MAP_PREFILTER,
LOC_MAP_BRDF
} ShaderLocationIndex;
#define LOC_MAP_DIFFUSE LOC_MAP_ALBEDO
#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
// Material map type
typedef enum {
MAP_ALBEDO = 0, // MAP_DIFFUSE
MAP_METALNESS = 1, // MAP_SPECULAR
MAP_NORMAL = 2,
MAP_ROUGHNESS = 3,
MAP_OCCLUSION,
MAP_EMISSION,
MAP_HEIGHT,
MAP_CUBEMAP, // NOTE: Uses GL_TEXTURE_CUBE_MAP
MAP_IRRADIANCE, // NOTE: Uses GL_TEXTURE_CUBE_MAP
MAP_PREFILTER, // NOTE: Uses GL_TEXTURE_CUBE_MAP
MAP_BRDF
} TexmapIndex;
#define MAP_DIFFUSE MAP_ALBEDO
#define MAP_SPECULAR MAP_METALNESS
// VR Head Mounted Display devices
typedef enum {
HMD_DEFAULT_DEVICE = 0,
HMD_OCULUS_RIFT_DK2,
HMD_OCULUS_RIFT_CV1,
HMD_OCULUS_GO,
HMD_VALVE_HTC_VIVE,
HMD_SONY_PSVR
} VrDevice;
#endif
#ifdef __cplusplus
extern "C" { // Prevents name mangling of functions
#endif
//------------------------------------------------------------------------------------
// Functions Declaration - Matrix operations
//------------------------------------------------------------------------------------
void rlMatrixMode(int mode); // Choose the current matrix to be transformed
void rlPushMatrix(void); // Push the current matrix to stack
void rlPopMatrix(void); // Pop lattest inserted matrix from stack
void rlLoadIdentity(void); // Reset current matrix to identity matrix
void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
void rlRotatef(float angleDeg, float x, float y, float z); // Multiply the current matrix by a rotation matrix
void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
void rlMultMatrixf(float *matf); // Multiply the current matrix by another matrix
void rlFrustum(double left, double right, double bottom, double top, double near, double far);
void rlOrtho(double left, double right, double bottom, double top, double near, double far);
void rlViewport(int x, int y, int width, int height); // Set the viewport area
//------------------------------------------------------------------------------------
// Functions Declaration - Vertex level operations
//------------------------------------------------------------------------------------
void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
void rlEnd(void); // Finish vertex providing
void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
void rlColor4ub(byte r, byte g, byte b, byte a); // Define one vertex (color) - 4 byte
void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
//------------------------------------------------------------------------------------
// Functions Declaration - OpenGL equivalent functions (common to 1.1, 3.3+, ES2)
// NOTE: This functions are used to completely abstract raylib code from OpenGL layer
//------------------------------------------------------------------------------------
void rlEnableTexture(unsigned int id); // Enable texture usage
void rlDisableTexture(void); // Disable texture usage
void rlTextureParameters(unsigned int id, int param, int value); // Set texture parameters (filter, wrap)
void rlEnableRenderTexture(unsigned int id); // Enable render texture (fbo)
void rlDisableRenderTexture(void); // Disable render texture (fbo), return to default framebuffer
void rlEnableDepthTest(void); // Enable depth test
void rlDisableDepthTest(void); // Disable depth test
void rlEnableWireMode(void); // Enable wire mode
void rlDisableWireMode(void); // Disable wire mode
void rlDeleteTextures(unsigned int id); // Delete OpenGL texture from GPU
void rlDeleteRenderTextures(RenderTexture2D target); // Delete render textures (fbo) from GPU
void rlDeleteShader(unsigned int id); // Delete OpenGL shader program from GPU
void rlDeleteVertexArrays(unsigned int id); // Unload vertex data (VAO) from GPU memory
void rlDeleteBuffers(unsigned int id); // Unload vertex data (VBO) from GPU memory
void rlClearColor(byte r, byte g, byte b, byte a); // Clear color buffer with color
void rlClearScreenBuffers(void); // Clear used screen buffers (color and depth)
//------------------------------------------------------------------------------------
// Functions Declaration - rlgl functionality
//------------------------------------------------------------------------------------
void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
void rlglClose(void); // De-inititialize rlgl (buffers, shaders, textures)
void rlglDraw(void); // Update and Draw default buffers (lines, triangles, quads)
int rlGetVersion(void); // Returns current OpenGL version
bool rlCheckBufferLimit(int type, int vCount); // Check internal buffer overflow for a given number of vertex
void rlSetDebugMarker(const char *text); // Set debug marker for analysis
void rlLoadExtensions(void *loader); // Load OpenGL extensions
Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
// Textures data management
unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
void rlUpdateTexture(unsigned int id, int width, int height, int format, const void *data); // Update GPU texture with new data
void rlUnloadTexture(unsigned int id);
void rlGenerateMipmaps(Texture2D *texture); // Generate mipmap data for selected texture
void *rlReadTexturePixels(Texture2D texture); // Read texture pixel data
unsigned char *rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
RenderTexture2D rlLoadRenderTexture(int width, int height); // Load a texture to be used for rendering (fbo with color and depth attachments)
// Vertex data management
void rlLoadMesh(Mesh *mesh, bool dynamic); // Upload vertex data into GPU and provided VAO/VBO ids
void rlUpdateMesh(Mesh mesh, int buffer, int numVertex); // Update vertex data on GPU (upload new data to one buffer)
void rlDrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform
void rlUnloadMesh(Mesh *mesh); // Unload mesh data from CPU and GPU
// NOTE: There is a set of shader related functions that are available to end user,
// to avoid creating function wrappers through core module, they have been directly declared in raylib.h
#if defined(RLGL_STANDALONE)
//------------------------------------------------------------------------------------
// Shaders System Functions (Module: rlgl)
// NOTE: This functions are useless when using OpenGL 1.1
//------------------------------------------------------------------------------------
Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
void UnloadShader(Shader shader); // Unload a custom shader from memory
Shader GetShaderDefault(void); // Get default shader
Texture2D GetTextureDefault(void); // Get default texture
// Shader configuration functions
int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
void SetShaderValue(Shader shader, int uniformLoc, const float *value, int size); // Set shader uniform value (float)
void SetShaderValuei(Shader shader, int uniformLoc, const int *value, int size); // Set shader uniform value (int)
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
Matrix GetMatrixModelview(); // Get internal modelview matrix
// Texture maps generation (PBR)
// NOTE: Required shaders should be provided
Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size); // Generate cubemap texture from HDR texture
Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size); // Generate irradiance texture using cubemap data
Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size); // Generate prefilter texture using cubemap data
Texture2D GenTextureBRDF(Shader shader, Texture2D cubemap, int size); // Generate BRDF texture using cubemap data
// Shading and blending
void BeginShaderMode(Shader shader); // Begin custom shader drawing
void EndShaderMode(void); // End custom shader drawing (use default shader)
void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
// VR simulator functionality
VrDeviceInfo GetVrDeviceInfo(int vrDeviceType); // Get VR device information for some standard devices
void InitVrSimulator(VrDeviceInfo info); // Init VR simulator for selected device parameters
void CloseVrSimulator(void); // Close VR simulator for current device
void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator)
void BeginVrDrawing(void); // Begin VR stereo rendering
void EndVrDrawing(void); // End VR stereo rendering
void TraceLog(int msgType, const char *text, ...); // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
#endif
#ifdef __cplusplus
}
#endif
#endif // RLGL_H

+ 10
- 2
release/include/raylib.h View File

@ -461,6 +461,7 @@ typedef struct Mesh {
int vertexCount; // Number of vertices stored in arrays
int triangleCount; // Number of triangles stored (indexed or not)
// Default vertex data
float *vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
float *texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
float *texcoords2; // Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
@ -468,9 +469,16 @@ typedef struct Mesh {
float *tangents; // Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4)
unsigned char *colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
unsigned short *indices;// Vertex indices (in case vertex data comes indexed)
// Animation vertex data
float *baseVertices; // Vertex base position (required to apply bones transformations)
float *baseNormals; // Vertex base normals (required to apply bones transformations)
float *weightBias; // Vertex weight bias
int *weightId; // Vertex weight id
// OpenGL identifiers
unsigned int vaoId; // OpenGL Vertex Array Object id
unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (7 types of vertex data)
unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (k">default vertex data)
} Mesh;
// Shader type (generic)

+ 10
- 2
src/raylib.h View File

@ -461,6 +461,7 @@ typedef struct Mesh {
int vertexCount; // Number of vertices stored in arrays
int triangleCount; // Number of triangles stored (indexed or not)
// Default vertex data
float *vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
float *texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
float *texcoords2; // Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
@ -468,9 +469,16 @@ typedef struct Mesh {
float *tangents; // Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4)
unsigned char *colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
unsigned short *indices;// Vertex indices (in case vertex data comes indexed)
// Animation vertex data
float *baseVertices; // Vertex base position (required to apply bones transformations)
float *baseNormals; // Vertex base normals (required to apply bones transformations)
float *weightBias; // Vertex weight bias
int *weightId; // Vertex weight id
// OpenGL identifiers
unsigned int vaoId; // OpenGL Vertex Array Object id
unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (7 types of vertex data)
unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (k">default vertex data)
} Mesh;
// Shader type (generic)

+ 5
- 0
src/rlgl.h View File

@ -2652,6 +2652,11 @@ void rlUnloadMesh(Mesh *mesh)
if (mesh->tangents != NULL) free(mesh->tangents);
if (mesh->texcoords2 != NULL) free(mesh->texcoords2);
if (mesh->indices != NULL) free(mesh->indices);
if (mesh->baseVertices != NULL) free(mesh->baseVertices);
if (mesh->baseNormals != NULL) free(mesh->baseNormals);
if (mesh->weightBias != NULL) free(mesh->weightBias);
if (mesh->weightId != NULL) free(mesh->weightId);
rlDeleteBuffers(mesh->vboId[0]); // vertex
rlDeleteBuffers(mesh->vboId[1]); // texcoords

Loading…
Cancel
Save