Skip to content

Commit 48c1619

Browse files
authored
added consistent behavior for texture in opengl11 draw states and fixed loadobj texcoord behavior for opengl11 context (#5328)
1 parent e92832f commit 48c1619

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/rmodels.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
14351435
#define GL_COLOR_ARRAY 0x8076
14361436
#define GL_TEXTURE_COORD_ARRAY 0x8078
14371437

1438-
rlEnableTexture(material.maps[MATERIAL_MAP_DIFFUSE].texture.id);
1438+
if (mesh.texcoords && material.maps[MATERIAL_MAP_DIFFUSE].texture.id > 0) rlEnableTexture(material.maps[MATERIAL_MAP_DIFFUSE].texture.id);
14391439

14401440
if (mesh.animVertices) rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.animVertices);
14411441
else rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.vertices);
@@ -4429,10 +4429,12 @@ static Model LoadOBJ(const char *fileName)
44294429

44304430
model.meshes[i].vertices = (float *)MemAlloc(sizeof(float)*vertexCount*3);
44314431
model.meshes[i].normals = (float *)MemAlloc(sizeof(float)*vertexCount*3);
4432-
model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
44334432
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
4433+
model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
44344434
model.meshes[i].colors = (unsigned char *)MemAlloc(sizeof(unsigned char)*vertexCount*4);
44354435
#else
4436+
if (objAttributes.texcoords != NULL && objAttributes.num_texcoords > 0) model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
4437+
else model.meshes[i].texcoords = NULL;
44364438
model.meshes[i].colors = NULL;
44374439
#endif
44384440
}
@@ -4488,16 +4490,11 @@ static Model LoadOBJ(const char *fileName)
44884490

44894491
for (int i = 0; i < 3; i++) model.meshes[meshIndex].vertices[localMeshVertexCount*3 + i] = objAttributes.vertices[vertIndex*3 + i];
44904492

4491-
if ((objAttributes.texcoords != NULL) && (texcordIndex != TINYOBJ_INVALID_INDEX) && (texcordIndex >= 0))
4493+
if ((objAttributes.texcoords != NULL) && (texcordIndex != TINYOBJ_INVALID_INDEX) && (texcordIndex >= 0) && (model.meshes[meshIndex].texcoords))
44924494
{
44934495
for (int i = 0; i < 2; i++) model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + i] = objAttributes.texcoords[texcordIndex*2 + i];
44944496
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1];
44954497
}
4496-
else
4497-
{
4498-
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 0] = 0.0f;
4499-
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 0.0f;
4500-
}
45014498

45024499
if ((objAttributes.normals != NULL) && (normalIndex != TINYOBJ_INVALID_INDEX) && (normalIndex >= 0))
45034500
{

0 commit comments

Comments
 (0)