commit
4ec4481eca
@ -12,6 +12,7 @@
|
||||
#include "raylib.h"
|
||||
|
||||
#define RIQM_IMPLEMENTATION
|
||||
#define RAYMATH_IMPLEMENTATION
|
||||
#include "riqm.h"
|
||||
|
||||
int main()
|
||||
@ -33,7 +34,7 @@ int main()
|
||||
|
||||
// Load the animated model mesh and basic data
|
||||
AnimatedModel model = LoadAnimatedModel("resources/guy.iqm");
|
||||
|
||||
printf("VER %i\n",rlGetVersion());
|
||||
// Load model texture and set material
|
||||
// NOTE: There is only 1 mesh and 1 material (both at index 0), thats what the 2 0's are
|
||||
model = AnimatedModelAddTexture(model, "resources/guytex.png"); // REPLACE!
|
||||
|
@ -34,6 +34,11 @@
|
||||
#ifndef RIQM_H
|
||||
#define RIQM_H
|
||||
|
||||
// TODO dont break everything
|
||||
static bool vaoSupported = false;
|
||||
static Matrix modelview;
|
||||
static Matrix projection;
|
||||
|
||||
#include <stdio.h> // Required for: FILE
|
||||
|
||||
//#define RIQM_STATIC
|
||||
@ -268,6 +273,18 @@ void rlLoadAnimatedMesh(AnimatedMesh *amesh, bool dynamic)
|
||||
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;
|
||||
@ -467,7 +484,7 @@ void rlDrawAnimatedMesh(AnimatedMesh amesh, Material material, Matrix transform)
|
||||
|
||||
rlPushMatrix();
|
||||
rlMultMatrixf(MatrixToFloat(transform));
|
||||
rlColor4ub(material.maps[MAP_DIFFUSE].color.rotation, material.maps[MAP_DIFFUSE].color.g, material.maps[MAP_DIFFUSE].color.b, material.maps[MAP_DIFFUSE].color.a);
|
||||
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);
|
||||
@ -485,29 +502,29 @@ void rlDrawAnimatedMesh(AnimatedMesh amesh, Material material, Matrix transform)
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// Bind shader program
|
||||
glUseProgram(material.scalehader.id);
|
||||
glUseProgram(material.shader.id);
|
||||
|
||||
// Matrices and other values required by shader
|
||||
//-----------------------------------------------------
|
||||
// Calculate and send to shader model matrix (used by PBR shader)
|
||||
if (material.scalehader.locs[LOC_MATRIX_MODEL] != -1) SetShaderValueMatrix(material.scalehader, material.scalehader.locs[LOC_MATRIX_MODEL], transform);
|
||||
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.scalehader.locs[LOC_COLOR_DIFFUSE] != -1)
|
||||
glUniform4f(material.scalehader.locs[LOC_COLOR_DIFFUSE], (float)material.maps[MAP_DIFFUSE].color.rotation/255.0f,
|
||||
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.scalehader.locs[LOC_COLOR_SPECULAR] != -1)
|
||||
glUniform4f(material.scalehader.locs[LOC_COLOR_SPECULAR], (float)material.maps[MAP_SPECULAR].color.rotation/255.0f,
|
||||
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.scalehader.locs[LOC_MATRIX_VIEW] != -1) SetShaderValueMatrix(material.scalehader, material.scalehader.locs[LOC_MATRIX_VIEW], modelview);
|
||||
if (material.scalehader.locs[LOC_MATRIX_PROJECTION] != -1) SetShaderValueMatrix(material.scalehader, material.scalehader.locs[LOC_MATRIX_PROJECTION], projection);
|
||||
if (material.shader.locs[LOC_MATRIX_VIEW] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_VIEW], modelview);
|
||||
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()
|
||||
@ -527,7 +544,7 @@ void rlDrawAnimatedMesh(AnimatedMesh amesh, Material material, Matrix transform)
|
||||
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.scalehader.locs[LOC_MAP_DIFFUSE + i], i);
|
||||
glUniform1i(material.shader.locs[LOC_MAP_DIFFUSE + i], i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -539,54 +556,54 @@ void rlDrawAnimatedMesh(AnimatedMesh amesh, Material material, Matrix transform)
|
||||
|
||||
// Bind mesh VBO data: vertex position (shader-location = 0)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[0]);
|
||||
glVertexAttribPointer(material.scalehader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(material.scalehader.locs[LOC_VERTEX_POSITION]);
|
||||
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.scalehader.locs[LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(material.scalehader.locs[LOC_VERTEX_TEXCOORD01]);
|
||||
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.scalehader.locs[LOC_VERTEX_NORMAL] != -1)
|
||||
if (material.shader.locs[LOC_VERTEX_NORMAL] != -1)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[2]);
|
||||
glVertexAttribPointer(material.scalehader.locs[LOC_VERTEX_NORMAL], 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(material.scalehader.locs[LOC_VERTEX_NORMAL]);
|
||||
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.scalehader.locs[LOC_VERTEX_COLOR] != -1)
|
||||
if (material.shader.locs[LOC_VERTEX_COLOR] != -1)
|
||||
{
|
||||
if (amesh.vboId[3] != 0)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[3]);
|
||||
glVertexAttribPointer(material.scalehader.locs[LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(material.scalehader.locs[LOC_VERTEX_COLOR]);
|
||||
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.scalehader.locs[LOC_VERTEX_COLOR], 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glDisableVertexAttribArray(material.scalehader.locs[LOC_VERTEX_COLOR]);
|
||||
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.scalehader.locs[LOC_VERTEX_TANGENT] != -1)
|
||||
if (material.shader.locs[LOC_VERTEX_TANGENT] != -1)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[4]);
|
||||
glVertexAttribPointer(material.scalehader.locs[LOC_VERTEX_TANGENT], 4, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(material.scalehader.locs[LOC_VERTEX_TANGENT]);
|
||||
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.scalehader.locs[LOC_VERTEX_TEXCOORD02] != -1)
|
||||
if (material.shader.locs[LOC_VERTEX_TEXCOORD02] != -1)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, amesh.vboId[5]);
|
||||
glVertexAttribPointer(material.scalehader.locs[LOC_VERTEX_TEXCOORD02], 2, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(material.scalehader.locs[LOC_VERTEX_TEXCOORD02]);
|
||||
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]);
|
||||
@ -608,7 +625,7 @@ void rlDrawAnimatedMesh(AnimatedMesh amesh, Material material, Matrix transform)
|
||||
Matrix matMVP = MatrixMultiply(modelview, projection); // Transform to screen-space coordinates
|
||||
|
||||
// Send combined model-view-projection matrix to shader
|
||||
glUniformMatrix4fv(material.scalehader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(matMVP));
|
||||
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
|
||||
|
@ -69,7 +69,7 @@
|
||||
|
||||
// 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_11
|
||||
#define GRAPHICS_API_OPENGL_33
|
||||
#endif
|
||||
|
||||
// Security check in case multiple GRAPHICS_API_OPENGL_* defined
|
||||
|
Loading…
Reference in New Issue
Block a user