Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
This commit is contained in:
commit
9799856ad4
12 changed files with 1887 additions and 1293 deletions
|
@ -1448,6 +1448,7 @@ static void InitDisplay(int width, int height)
|
|||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Profiles Hint: Only 3.3 and above!
|
||||
// Other values: GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_COMPAT_PROFILE
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); // Fordward Compatibility Hint: Only 3.3 and above!
|
||||
//glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
||||
}
|
||||
|
||||
if (fullscreen)
|
||||
|
|
403
src/models.c
403
src/models.c
|
@ -55,7 +55,9 @@ extern unsigned int whiteTexture;
|
|||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
static Mesh LoadOBJ(const char *fileName);
|
||||
static Mesh LoadOBJ(const char *fileName); // Load OBJ mesh data
|
||||
static Material LoadMTL(const char *fileName); // Load MTL material data
|
||||
|
||||
static Mesh GenMeshHeightmap(Image image, Vector3 size);
|
||||
static Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize);
|
||||
|
||||
|
@ -542,24 +544,19 @@ void DrawGizmo(Vector3 position)
|
|||
Model LoadModel(const char *fileName)
|
||||
{
|
||||
Model model = { 0 };
|
||||
Mesh mesh = { 0 };
|
||||
|
||||
// NOTE: Initialize default data for model in case loading fails, maybe a cube?
|
||||
// TODO: Initialize default data for model in case loading fails, maybe a cube?
|
||||
|
||||
if (strcmp(GetExtension(fileName),"obj") == 0) mesh = LoadOBJ(fileName);
|
||||
if (strcmp(GetExtension(fileName),"obj") == 0) model.mesh = LoadOBJ(fileName);
|
||||
else TraceLog(WARNING, "[%s] Model extension not recognized, it can't be loaded", fileName);
|
||||
|
||||
// NOTE: At this point we have all vertex, texcoord, normal data for the model in mesh struct
|
||||
|
||||
if (mesh.vertexCount == 0) TraceLog(WARNING, "Model could not be loaded");
|
||||
if (model.mesh.vertexCount == 0) TraceLog(WARNING, "Model could not be loaded");
|
||||
else
|
||||
{
|
||||
// NOTE: model properties (transform, texture, shader) are initialized inside rlglLoadModel()
|
||||
model = rlglLoadModel(mesh); // Upload vertex data to GPU
|
||||
|
||||
// NOTE: Now that vertex data is uploaded to GPU VRAM, we can free arrays from CPU RAM
|
||||
// We don't need CPU vertex data on OpenGL 3.3 or ES2... for static meshes...
|
||||
// ...but we could keep CPU vertex data in case we need to update the mesh
|
||||
rlglLoadMesh(&model.mesh); // Upload vertex data to GPU
|
||||
|
||||
model.transform = MatrixIdentity();
|
||||
model.material = LoadDefaultMaterial();
|
||||
}
|
||||
|
||||
return model;
|
||||
|
@ -568,22 +565,111 @@ Model LoadModel(const char *fileName)
|
|||
// Load a 3d model (from vertex data)
|
||||
Model LoadModelEx(Mesh data)
|
||||
{
|
||||
Model model;
|
||||
Model model = { 0 };
|
||||
|
||||
// NOTE: model properties (transform, texture, shader) are initialized inside rlglLoadModel()
|
||||
model = rlglLoadModel(data); // Upload vertex data to GPU
|
||||
rlglLoadMesh(&data); // Upload vertex data to GPU
|
||||
|
||||
// NOTE: Vertex data is managed externally, must be deallocated manually
|
||||
model.transform = MatrixIdentity();
|
||||
model.material = LoadDefaultMaterial();
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
// Load a 3d model from rRES file (raylib Resource)
|
||||
Model LoadModelFromRES(const char *rresName, int resId)
|
||||
{
|
||||
Model model = { 0 };
|
||||
bool found = false;
|
||||
|
||||
char id[4]; // rRES file identifier
|
||||
unsigned char version; // rRES file version and subversion
|
||||
char useless; // rRES header reserved data
|
||||
short numRes;
|
||||
|
||||
ResInfoHeader infoHeader;
|
||||
|
||||
FILE *rresFile = fopen(rresName, "rb");
|
||||
|
||||
if (rresFile == NULL)
|
||||
{
|
||||
TraceLog(WARNING, "[%s] rRES raylib resource file could not be opened", rresName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read rres file (basic file check - id)
|
||||
fread(&id[0], sizeof(char), 1, rresFile);
|
||||
fread(&id[1], sizeof(char), 1, rresFile);
|
||||
fread(&id[2], sizeof(char), 1, rresFile);
|
||||
fread(&id[3], sizeof(char), 1, rresFile);
|
||||
fread(&version, sizeof(char), 1, rresFile);
|
||||
fread(&useless, sizeof(char), 1, rresFile);
|
||||
|
||||
if ((id[0] != 'r') && (id[1] != 'R') && (id[2] != 'E') &&(id[3] != 'S'))
|
||||
{
|
||||
TraceLog(WARNING, "[%s] This is not a valid raylib resource file", rresName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read number of resources embedded
|
||||
fread(&numRes, sizeof(short), 1, rresFile);
|
||||
|
||||
for (int i = 0; i < numRes; i++)
|
||||
{
|
||||
fread(&infoHeader, sizeof(ResInfoHeader), 1, rresFile);
|
||||
|
||||
if (infoHeader.id == resId)
|
||||
{
|
||||
found = true;
|
||||
|
||||
// Check data is of valid MODEL type
|
||||
if (infoHeader.type == 8)
|
||||
{
|
||||
// TODO: Load model data
|
||||
}
|
||||
else
|
||||
{
|
||||
TraceLog(WARNING, "[%s] Required resource do not seem to be a valid MODEL resource", rresName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Depending on type, skip the right amount of parameters
|
||||
switch (infoHeader.type)
|
||||
{
|
||||
case 0: fseek(rresFile, 6, SEEK_CUR); break; // IMAGE: Jump 6 bytes of parameters
|
||||
case 1: fseek(rresFile, 6, SEEK_CUR); break; // SOUND: Jump 6 bytes of parameters
|
||||
case 2: fseek(rresFile, 5, SEEK_CUR); break; // MODEL: Jump 5 bytes of parameters (TODO: Review)
|
||||
case 3: break; // TEXT: No parameters
|
||||
case 4: break; // RAW: No parameters
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Jump DATA to read next infoHeader
|
||||
fseek(rresFile, infoHeader.size, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(rresFile);
|
||||
}
|
||||
|
||||
if (!found) TraceLog(WARNING, "[%s] Required resource id [%i] could not be found in the raylib resource file", rresName, resId);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
// Load a heightmap image as a 3d model
|
||||
// NOTE: model map size is defined in generic units
|
||||
Model LoadHeightmap(Image heightmap, Vector3 size)
|
||||
{
|
||||
Mesh mesh = GenMeshHeightmap(heightmap, size);
|
||||
Model model = rlglLoadModel(mesh);
|
||||
Model model = { 0 };
|
||||
|
||||
model.mesh = GenMeshHeightmap(heightmap, size);
|
||||
|
||||
rlglLoadMesh(&model.mesh);
|
||||
|
||||
model.transform = MatrixIdentity();
|
||||
model.material = LoadDefaultMaterial();
|
||||
|
||||
return model;
|
||||
}
|
||||
|
@ -591,8 +677,14 @@ Model LoadHeightmap(Image heightmap, Vector3 size)
|
|||
// Load a map image as a 3d model (cubes based)
|
||||
Model LoadCubicmap(Image cubicmap)
|
||||
{
|
||||
Mesh mesh = GenMeshCubicmap(cubicmap, (Vector3){ 1.0, 1.0, 1.5f });
|
||||
Model model = rlglLoadModel(mesh);
|
||||
Model model = { 0 };
|
||||
|
||||
model.mesh = GenMeshCubicmap(cubicmap, (Vector3){ 1.0, 1.0, 1.5f });
|
||||
|
||||
rlglLoadMesh(&model.mesh);
|
||||
|
||||
model.transform = MatrixIdentity();
|
||||
model.material = LoadDefaultMaterial();
|
||||
|
||||
return model;
|
||||
}
|
||||
|
@ -603,23 +695,54 @@ void UnloadModel(Model model)
|
|||
// Unload mesh data
|
||||
free(model.mesh.vertices);
|
||||
free(model.mesh.texcoords);
|
||||
free(model.mesh.normals);
|
||||
free(model.mesh.colors);
|
||||
//if (model.mesh.texcoords2 != NULL) free(model.mesh.texcoords2); // Not used
|
||||
//if (model.mesh.tangents != NULL) free(model.mesh.tangents); // Not used
|
||||
if (model.mesh.normals != NULL) free(model.mesh.normals);
|
||||
if (model.mesh.colors != NULL) free(model.mesh.colors);
|
||||
if (model.mesh.tangents != NULL) free(model.mesh.tangents);
|
||||
if (model.mesh.texcoords2 != NULL) free(model.mesh.texcoords2);
|
||||
|
||||
TraceLog(INFO, "Unloaded model data from RAM (CPU)");
|
||||
|
||||
rlDeleteBuffers(model.mesh.vboId[0]); // vertex
|
||||
rlDeleteBuffers(model.mesh.vboId[1]); // texcoords
|
||||
rlDeleteBuffers(model.mesh.vboId[2]); // normals
|
||||
//rlDeleteBuffers(model.mesh.vboId[3]); // texcoords2 (NOT USED)
|
||||
//rlDeleteBuffers(model.mesh.vboId[4]); // tangents (NOT USED)
|
||||
//rlDeleteBuffers(model.mesh.vboId[5]); // colors (NOT USED)
|
||||
rlDeleteBuffers(model.mesh.vboId[3]); // colors
|
||||
rlDeleteBuffers(model.mesh.vboId[4]); // tangents
|
||||
rlDeleteBuffers(model.mesh.vboId[5]); // texcoords2
|
||||
|
||||
rlDeleteVertexArrays(model.mesh.vaoId);
|
||||
}
|
||||
|
||||
// Load material data (from file)
|
||||
Material LoadMaterial(const char *fileName)
|
||||
{
|
||||
Material material = { 0 };
|
||||
|
||||
if (strcmp(GetExtension(fileName),"mtl") == 0) material = LoadMTL(fileName);
|
||||
else TraceLog(WARNING, "[%s] Material extension not recognized, it can't be loaded", fileName);
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
// Load default material (uses default models shader)
|
||||
Material LoadDefaultMaterial(void)
|
||||
{
|
||||
Material material = { 0 };
|
||||
|
||||
material.shader = GetDefaultShader();
|
||||
material.texDiffuse = GetDefaultTexture(); // White texture (1x1 pixel)
|
||||
//material.texNormal; // NOTE: By default, not set
|
||||
//material.texSpecular; // NOTE: By default, not set
|
||||
|
||||
material.colDiffuse = WHITE; // Diffuse color
|
||||
material.colAmbient = WHITE; // Ambient color
|
||||
material.colSpecular = WHITE; // Specular color
|
||||
|
||||
material.glossiness = 100.0f; // Glossiness level
|
||||
material.normalDepth = 1.0f; // Normal map depth
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
// Link a texture to a model
|
||||
void SetModelTexture(Model *model, Texture2D texture)
|
||||
{
|
||||
|
@ -632,7 +755,7 @@ static Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
|||
{
|
||||
#define GRAY_VALUE(c) ((c.r+c.g+c.b)/3)
|
||||
|
||||
Mesh mesh;
|
||||
Mesh mesh = { 0 };
|
||||
|
||||
int mapX = heightmap.width;
|
||||
int mapZ = heightmap.height;
|
||||
|
@ -647,7 +770,7 @@ static Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
|||
mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float));
|
||||
mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float));
|
||||
mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float));
|
||||
mesh.colors = (unsigned char *)malloc(mesh.vertexCount*4*sizeof(unsigned char)); // Not used...
|
||||
mesh.colors = NULL;
|
||||
|
||||
int vCounter = 0; // Used to count vertices float by float
|
||||
int tcCounter = 0; // Used to count texcoords float by float
|
||||
|
@ -730,16 +853,12 @@ static Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
|||
|
||||
free(pixels);
|
||||
|
||||
// Fill color data
|
||||
// NOTE: Not used any more... just one plain color defined at DrawModel()
|
||||
for (int i = 0; i < (4*mesh.vertexCount); i++) mesh.colors[i] = 255;
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
static Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
||||
{
|
||||
Mesh mesh;
|
||||
Mesh mesh = { 0 };
|
||||
|
||||
Color *cubicmapPixels = GetImageData(cubicmap);
|
||||
|
||||
|
@ -1048,11 +1167,7 @@ static Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
|||
mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float));
|
||||
mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float));
|
||||
mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float));
|
||||
mesh.colors = (unsigned char *)malloc(mesh.vertexCount*4*sizeof(unsigned char)); // Not used...
|
||||
|
||||
// Fill color data
|
||||
// NOTE: Not used any more... just one plain color defined at DrawModel()
|
||||
for (int i = 0; i < (4*mesh.vertexCount); i++) mesh.colors[i] = 255;
|
||||
mesh.colors = NULL;
|
||||
|
||||
int fCounter = 0;
|
||||
|
||||
|
@ -1100,31 +1215,59 @@ void DrawModel(Model model, Vector3 position, float scale, Color tint)
|
|||
{
|
||||
Vector3 vScale = { scale, scale, scale };
|
||||
Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
|
||||
DrawModelEx(model, position, rotationAxis, 0.0f, vScale, tint);
|
||||
}
|
||||
|
||||
// Draw a model with extended parameters
|
||||
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
|
||||
{
|
||||
// NOTE: Rotation must be provided in degrees, it's converted to radians inside rlglDrawModel()
|
||||
rlglDrawModel(model, position, rotationAxis, rotationAngle, scale, tint, false);
|
||||
// Calculate transformation matrix from function parameters
|
||||
// Get transform matrix (rotation -> scale -> translation)
|
||||
Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD);
|
||||
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
|
||||
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
|
||||
|
||||
// Combine model transformation matrix (model.transform) with matrix generated by function parameters (matTransform)
|
||||
//Matrix matModel = MatrixMultiply(model.transform, matTransform); // Transform to world-space coordinates
|
||||
|
||||
model.transform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
|
||||
model.material.colDiffuse = tint;
|
||||
|
||||
rlglDrawEx(model.mesh, model.material, model.transform, false);
|
||||
}
|
||||
|
||||
// Draw a model wires (with texture if set)
|
||||
void DrawModelWires(Model model, Vector3 position, float scale, Color color)
|
||||
void DrawModelWires(Model model, Vector3 position, float scale, Color tint)
|
||||
{
|
||||
Vector3 vScale = { scale, scale, scale };
|
||||
Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
rlglDrawModel(model, position, rotationAxis, 0.0f, vScale, color, true);
|
||||
// Calculate transformation matrix from function parameters
|
||||
// Get transform matrix (rotation -> scale -> translation)
|
||||
Matrix matRotation = MatrixRotate(rotationAxis, 0.0f);
|
||||
Matrix matScale = MatrixScale(vScale.x, vScale.y, vScale.z);
|
||||
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
|
||||
|
||||
model.transform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
|
||||
model.material.colDiffuse = tint;
|
||||
|
||||
rlglDrawEx(model.mesh, model.material, model.transform, true);
|
||||
}
|
||||
|
||||
// Draw a model wires (with texture if set) with extended parameters
|
||||
void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
|
||||
{
|
||||
// NOTE: Rotation must be provided in degrees, it's converted to radians inside rlglDrawModel()
|
||||
rlglDrawModel(model, position, rotationAxis, rotationAngle, scale, tint, true);
|
||||
// Calculate transformation matrix from function parameters
|
||||
// Get transform matrix (rotation -> scale -> translation)
|
||||
Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD);
|
||||
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
|
||||
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
|
||||
|
||||
model.transform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
|
||||
model.material.colDiffuse = tint;
|
||||
|
||||
rlglDrawEx(model.mesh, model.material, model.transform, true);
|
||||
}
|
||||
|
||||
// Draw a billboard
|
||||
|
@ -1742,7 +1885,7 @@ static Mesh LoadOBJ(const char *fileName)
|
|||
mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float));
|
||||
mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float));
|
||||
mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float));
|
||||
mesh.colors = (unsigned char *)malloc(mesh.vertexCount*4*sizeof(unsigned char));
|
||||
mesh.colors = NULL;
|
||||
|
||||
int vCounter = 0; // Used to count vertices float by float
|
||||
int tcCounter = 0; // Used to count texcoords float by float
|
||||
|
@ -1841,10 +1984,6 @@ static Mesh LoadOBJ(const char *fileName)
|
|||
|
||||
// Security check, just in case no normals or no texcoords defined in OBJ
|
||||
if (numTexCoords == 0) for (int i = 0; i < (2*mesh.vertexCount); i++) mesh.texcoords[i] = 0.0f;
|
||||
|
||||
// NOTE: We set all vertex colors to white
|
||||
// NOTE: Not used any more... just one plain color defined at DrawModel()
|
||||
for (int i = 0; i < (4*mesh.vertexCount); i++) mesh.colors[i] = 255;
|
||||
|
||||
// Now we can free temp mid* arrays
|
||||
free(midVertices);
|
||||
|
@ -1856,3 +1995,163 @@ static Mesh LoadOBJ(const char *fileName)
|
|||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
// Load MTL material data (specs: http://paulbourke.net/dataformats/mtl/)
|
||||
// NOTE: Texture map parameters are not supported
|
||||
static Material LoadMTL(const char *fileName)
|
||||
{
|
||||
#define MAX_BUFFER_SIZE 128
|
||||
|
||||
Material material = { 0 }; // LoadDefaultMaterial();
|
||||
|
||||
char buffer[MAX_BUFFER_SIZE];
|
||||
Vector3 color = { 1.0f, 1.0f, 1.0f };
|
||||
char *mapFileName;
|
||||
|
||||
FILE *mtlFile;
|
||||
|
||||
mtlFile = fopen(fileName, "rt");
|
||||
|
||||
if (mtlFile == NULL)
|
||||
{
|
||||
TraceLog(WARNING, "[%s] MTL file could not be opened", fileName);
|
||||
return material;
|
||||
}
|
||||
|
||||
while(!feof(mtlFile))
|
||||
{
|
||||
fgets(buffer, MAX_BUFFER_SIZE, mtlFile);
|
||||
|
||||
switch (buffer[0])
|
||||
{
|
||||
case 'n': // newmtl string Material name. Begins a new material description.
|
||||
{
|
||||
// TODO: Support multiple materials in a single .mtl
|
||||
sscanf(buffer, "newmtl %s", mapFileName);
|
||||
|
||||
TraceLog(INFO, "[%s] Loading material...", mapFileName);
|
||||
}
|
||||
case 'i': // illum int Illumination model
|
||||
{
|
||||
// illum = 1 if specular disabled
|
||||
// illum = 2 if specular enabled (lambertian model)
|
||||
// ...
|
||||
}
|
||||
case 'K': // Ka, Kd, Ks, Ke
|
||||
{
|
||||
switch (buffer[1])
|
||||
{
|
||||
case 'a': // Ka float float float Ambient color (RGB)
|
||||
{
|
||||
sscanf(buffer, "Ka %f %f %f", &color.x, &color.y, &color.z);
|
||||
material.colAmbient.r = (unsigned char)(color.x*255);
|
||||
material.colAmbient.g = (unsigned char)(color.y*255);
|
||||
material.colAmbient.b = (unsigned char)(color.z*255);
|
||||
} break;
|
||||
case 'd': // Kd float float float Diffuse color (RGB)
|
||||
{
|
||||
sscanf(buffer, "Kd %f %f %f", &color.x, &color.y, &color.z);
|
||||
material.colDiffuse.r = (unsigned char)(color.x*255);
|
||||
material.colDiffuse.g = (unsigned char)(color.y*255);
|
||||
material.colDiffuse.b = (unsigned char)(color.z*255);
|
||||
} break;
|
||||
case 's': // Ks float float float Specular color (RGB)
|
||||
{
|
||||
sscanf(buffer, "Ks %f %f %f", &color.x, &color.y, &color.z);
|
||||
material.colSpecular.r = (unsigned char)(color.x*255);
|
||||
material.colSpecular.g = (unsigned char)(color.y*255);
|
||||
material.colSpecular.b = (unsigned char)(color.z*255);
|
||||
} break;
|
||||
case 'e': // Ke float float float Emmisive color (RGB)
|
||||
{
|
||||
// TODO: Support Ke ?
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
} break;
|
||||
case 'N': // Ns, Ni
|
||||
{
|
||||
if (buffer[1] == 's') // Ns int Shininess (specular exponent). Ranges from 0 to 1000.
|
||||
{
|
||||
sscanf(buffer, "Ns %i", &material.glossiness);
|
||||
}
|
||||
else if (buffer[1] == 'i') // Ni int Refraction index.
|
||||
{
|
||||
// Not supported...
|
||||
}
|
||||
} break;
|
||||
case 'm': // map_Kd, map_Ks, map_Ka, map_Bump, map_d
|
||||
{
|
||||
switch (buffer[4])
|
||||
{
|
||||
case 'K': // Color texture maps
|
||||
{
|
||||
if (buffer[5] == 'd') // map_Kd string Diffuse color texture map.
|
||||
{
|
||||
sscanf(buffer, "map_Kd %s", mapFileName);
|
||||
if (mapFileName != NULL) material.texDiffuse = LoadTexture(mapFileName);
|
||||
}
|
||||
else if (buffer[5] == 's') // map_Ks string Specular color texture map.
|
||||
{
|
||||
sscanf(buffer, "map_Ks %s", mapFileName);
|
||||
if (mapFileName != NULL) material.texSpecular = LoadTexture(mapFileName);
|
||||
}
|
||||
else if (buffer[5] == 'a') // map_Ka string Ambient color texture map.
|
||||
{
|
||||
// Not supported...
|
||||
}
|
||||
} break;
|
||||
case 'B': // map_Bump string Bump texture map.
|
||||
{
|
||||
sscanf(buffer, "map_Bump %s", mapFileName);
|
||||
if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName);
|
||||
} break;
|
||||
case 'b': // map_bump string Bump texture map.
|
||||
{
|
||||
sscanf(buffer, "map_bump %s", mapFileName);
|
||||
if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName);
|
||||
} break;
|
||||
case 'd': // map_d string Opacity texture map.
|
||||
{
|
||||
// Not supported...
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
} break;
|
||||
case 'd': // d, disp
|
||||
{
|
||||
if (buffer[1] == ' ') // d float Dissolve factor. d is inverse of Tr
|
||||
{
|
||||
float alpha = 1.0f;
|
||||
sscanf(buffer, "d %f", &alpha);
|
||||
material.colDiffuse.a = (unsigned char)(alpha*255);
|
||||
}
|
||||
else if (buffer[1] == 'i') // disp string Displacement map
|
||||
{
|
||||
// Not supported...
|
||||
}
|
||||
} break;
|
||||
case 'b': // bump string Bump texture map
|
||||
{
|
||||
sscanf(buffer, "bump %s", mapFileName);
|
||||
if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName);
|
||||
} break;
|
||||
case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d
|
||||
{
|
||||
float ialpha = 0.0f;
|
||||
sscanf(buffer, "Tr %f", &ialpha);
|
||||
material.colDiffuse.a = (unsigned char)((1.0f - ialpha)*255);
|
||||
|
||||
} break;
|
||||
case 'r': // refl string Reflection texture map
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(mtlFile);
|
||||
|
||||
// NOTE: At this point we have all material data
|
||||
TraceLog(INFO, "[%s] Material loaded successfully", fileName);
|
||||
|
||||
return material;
|
||||
}
|
||||
|
|
47
src/raylib.h
47
src/raylib.h
|
@ -369,12 +369,12 @@ typedef struct BoundingBox {
|
|||
// Vertex data definning a mesh
|
||||
typedef struct Mesh {
|
||||
int vertexCount; // num vertices
|
||||
float *vertices; // vertex position (XYZ - 3 components per vertex)
|
||||
float *texcoords; // vertex texture coordinates (UV - 2 components per vertex)
|
||||
float *texcoords2; // vertex second texture coordinates (useful for lightmaps)
|
||||
float *normals; // vertex normals (XYZ - 3 components per vertex)
|
||||
float *tangents; // vertex tangents (XYZ - 3 components per vertex)
|
||||
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex)
|
||||
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 (XYZ - 3 components per vertex) (shader-location = 4)
|
||||
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
||||
|
||||
BoundingBox bounds; // mesh limits defined by min and max points
|
||||
|
||||
|
@ -386,11 +386,13 @@ typedef struct Mesh {
|
|||
typedef struct Shader {
|
||||
unsigned int id; // Shader program id
|
||||
|
||||
// Variable attributes locations
|
||||
int vertexLoc; // Vertex attribute location point (vertex shader)
|
||||
int texcoordLoc; // Texcoord attribute location point (vertex shader)
|
||||
int normalLoc; // Normal attribute location point (vertex shader)
|
||||
int colorLoc; // Color attibute location point (vertex shader)
|
||||
// Vertex attributes locations (default locations)
|
||||
int vertexLoc; // Vertex attribute location point (default-location = 0)
|
||||
int texcoordLoc; // Texcoord attribute location point (default-location = 1)
|
||||
int normalLoc; // Normal attribute location point (default-location = 2)
|
||||
int colorLoc; // Color attibute location point (default-location = 3)
|
||||
int tangentLoc; // Tangent attribute location point (default-location = 4)
|
||||
int texcoord2Loc; // Texcoord2 attribute location point (default-location = 5)
|
||||
|
||||
// Uniform locations
|
||||
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
||||
|
@ -801,17 +803,20 @@ void DrawGizmo(Vector3 position);
|
|||
//------------------------------------------------------------------------------------
|
||||
// Model 3d Loading and Drawing Functions (Module: models)
|
||||
//------------------------------------------------------------------------------------
|
||||
Model LoadModel(const char *fileName); // Load a 3d model (.OBJ)
|
||||
Model LoadModelEx(Mesh data); // Load a 3d model (from mesh data)
|
||||
//Model LoadModelFromRES(const char *rresName, int resId); // TODO: Load a 3d model from rRES file (raylib Resource)
|
||||
Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model
|
||||
Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based)
|
||||
void UnloadModel(Model model); // Unload 3d model from memory
|
||||
void SetModelTexture(Model *model, Texture2D texture); // Link a texture to a model
|
||||
Model LoadModel(const char *fileName); // Load a 3d model (.OBJ)
|
||||
Model LoadModelEx(Mesh data); // Load a 3d model (from mesh data)
|
||||
Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource)
|
||||
Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model
|
||||
Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based)
|
||||
void UnloadModel(Model model); // Unload 3d model from memory
|
||||
void SetModelTexture(Model *model, Texture2D texture); // Link a texture to a model
|
||||
|
||||
Material LoadMaterial(const char *fileName); // Load material data (from file)
|
||||
Material LoadDefaultMaterial(void); // Load default material (uses default models shader)
|
||||
|
||||
void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
|
||||
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters
|
||||
void DrawModelWires(Model model, Vector3 position, float scale, Color color); // Draw a model wires (with texture if set)
|
||||
void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set)
|
||||
void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
|
||||
void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires)
|
||||
|
||||
|
@ -832,11 +837,11 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
|||
// NOTE: This functions are useless when using OpenGL 1.1
|
||||
//------------------------------------------------------------------------------------
|
||||
Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
|
||||
unsigned int LoadShaderProgram(char *vShaderStr, char *fShaderStr); // Load custom shaders strings and return program id
|
||||
void UnloadShader(Shader shader); // Unload a custom shader from memory
|
||||
void SetDefaultShader(void); // Set default shader to be used in batch draw
|
||||
void SetCustomShader(Shader shader); // Set custom shader to be used in batch draw
|
||||
void SetModelShader(Model *model, Shader shader); // Link a shader to a model
|
||||
Shader GetDefaultShader(void); // Get default shader
|
||||
Texture2D GetDefaultTexture(void); // Get default texture
|
||||
|
||||
int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
|
||||
void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float)
|
||||
|
|
971
src/rlgl.c
971
src/rlgl.c
File diff suppressed because it is too large
Load diff
15
src/rlgl.h
15
src/rlgl.h
|
@ -280,29 +280,28 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int textureForma
|
|||
RenderTexture2D rlglLoadRenderTexture(int width, int height); // Load a texture to be used for rendering (fbo with color and depth attachments)
|
||||
void rlglUpdateTexture(unsigned int id, int width, int height, int format, void *data); // Update GPU texture with new data
|
||||
void rlglGenerateMipmaps(Texture2D texture); // Generate mipmap data for selected texture
|
||||
|
||||
// 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
|
||||
|
||||
Model rlglLoadModel(Mesh mesh); // Upload vertex data into GPU and provided VAO/VBO ids
|
||||
void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color color, bool wires);
|
||||
void rlglLoadMesh(Mesh *mesh); // Upload vertex data into GPU and provided VAO/VBO ids
|
||||
void rlglDrawEx(Mesh mesh, Material material, Matrix transform, bool wires);
|
||||
|
||||
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
|
||||
|
||||
unsigned char *rlglReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
||||
void *rlglReadTexturePixels(Texture2D texture); // Read texture pixel data
|
||||
|
||||
// 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
|
||||
unsigned int LoadShaderProgram(char *vShaderStr, char *fShaderStr); // Load custom shader strings and return program id
|
||||
void UnloadShader(Shader shader); // Unload a custom shader from memory
|
||||
void SetCustomShader(Shader shader); // Set custom shader to be used in batch draw
|
||||
void SetDefaultShader(void); // Set default shader to be used in batch draw
|
||||
void SetModelShader(Model *model, Shader shader); // Link a shader to a model
|
||||
Shader GetDefaultShader(void); // Get default shader
|
||||
Texture2D GetDefaultTexture(void); // Get default texture
|
||||
|
||||
int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
|
||||
void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue