@@ -1337,10 +1337,19 @@ void UploadMesh(Mesh *mesh, bool dynamic)
13371337 rlEnableVertexAttribute (RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION );
13381338
13391339 // Enable vertex attributes: texcoords (shader-location = 1)
1340- mesh -> vboId [RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD ] = rlLoadVertexBuffer (mesh -> texcoords , mesh -> vertexCount * 2 * sizeof (float ), dynamic );
1341- rlSetVertexAttribute (RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD , 2 , RL_FLOAT , 0 , 0 , 0 );
1342- rlEnableVertexAttribute (RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD );
13431340
1341+ if (mesh -> texcoords != NULL )
1342+ {
1343+ mesh -> vboId [RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD ] = rlLoadVertexBuffer (mesh -> texcoords , mesh -> vertexCount * 2 * sizeof (float ), dynamic );
1344+ rlSetVertexAttribute (RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD , 2 , RL_FLOAT , 0 , 0 , 0 );
1345+ rlEnableVertexAttribute (RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD );
1346+ }
1347+ else
1348+ {
1349+ float value [2 ] = { 0.0f , 0.0f };
1350+ rlSetVertexAttributeDefault (RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD , value , SHADER_ATTRIB_VEC2 , 2 );
1351+ rlDisableVertexAttribute (RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD );
1352+ }
13441353 // WARNING: When setting default vertex attribute values, the values for each generic vertex attribute
13451354 // is part of current state, and it is maintained even if a different program object is used
13461355#if !defined(PLATFORM_VITA )
@@ -1474,11 +1483,12 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
14741483 if (mesh .animVertices ) rlEnableStatePointer (GL_VERTEX_ARRAY , mesh .animVertices );
14751484 else rlEnableStatePointer (GL_VERTEX_ARRAY , mesh .vertices );
14761485
1477- rlEnableStatePointer (GL_TEXTURE_COORD_ARRAY , mesh .texcoords );
1486+ if ( mesh . texcoords ) rlEnableStatePointer (GL_TEXTURE_COORD_ARRAY , mesh .texcoords );
14781487
14791488 if (mesh .animNormals ) rlEnableStatePointer (GL_NORMAL_ARRAY , mesh .animNormals );
1480- else rlEnableStatePointer (GL_NORMAL_ARRAY , mesh .normals );
1481- rlEnableStatePointer (GL_COLOR_ARRAY , mesh .colors );
1489+ else if (mesh .normals ) rlEnableStatePointer (GL_NORMAL_ARRAY , mesh .normals );
1490+
1491+ if (mesh .colors ) rlEnableStatePointer (GL_COLOR_ARRAY , mesh .colors );
14821492
14831493 rlPushMatrix ();
14841494 rlMultMatrixf (MatrixToFloat (transform ));
@@ -3887,6 +3897,7 @@ void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float
38873897
38883898// Draw a model points
38893899// WARNING: OpenGL ES 2.0 does not support point mode drawing
3900+ // TODO: gate these properly for non es 2.0 versions only
38903901void DrawModelPoints (Model model , Vector3 position , float scale , Color tint )
38913902{
38923903 rlEnablePointMode ();
@@ -4475,7 +4486,11 @@ static Model LoadOBJ(const char *fileName)
44754486 model .meshes [i ].vertices = (float * )MemAlloc (sizeof (float )* vertexCount * 3 );
44764487 model .meshes [i ].normals = (float * )MemAlloc (sizeof (float )* vertexCount * 3 );
44774488 model .meshes [i ].texcoords = (float * )MemAlloc (sizeof (float )* vertexCount * 2 );
4489+ #if defined(GRAPHICS_API_OPENGL_33 ) || defined(GRAPHICS_API_OPENGL_ES2 )
44784490 model .meshes [i ].colors = (unsigned char * )MemAlloc (sizeof (unsigned char )* vertexCount * 4 );
4491+ #else
4492+ model .meshes [i ].colors = NULL ;
4493+ #endif
44794494 }
44804495
44814496 MemFree (localMeshVertexCounts );
@@ -4529,7 +4544,17 @@ static Model LoadOBJ(const char *fileName)
45294544
45304545 for (int i = 0 ; i < 3 ; i ++ ) model .meshes [meshIndex ].vertices [localMeshVertexCount * 3 + i ] = objAttributes .vertices [vertIndex * 3 + i ];
45314546
4532- for (int i = 0 ; i < 2 ; i ++ ) model .meshes [meshIndex ].texcoords [localMeshVertexCount * 2 + i ] = objAttributes .texcoords [texcordIndex * 2 + i ];
4547+ if (objAttributes .texcoords != NULL && texcordIndex != TINYOBJ_INVALID_INDEX && texcordIndex >= 0 )
4548+ {
4549+ for (int i = 0 ; i < 2 ; i ++ ) model .meshes [meshIndex ].texcoords [localMeshVertexCount * 2 + i ] = objAttributes .texcoords [texcordIndex * 2 + i ];
4550+ model .meshes [meshIndex ].texcoords [localMeshVertexCount * 2 + 1 ] = 1.0f - model .meshes [meshIndex ].texcoords [localMeshVertexCount * 2 + 1 ];
4551+ }
4552+ else
4553+ {
4554+ model .meshes [meshIndex ].texcoords [localMeshVertexCount * 2 + 0 ] = 0.0f ;
4555+ model .meshes [meshIndex ].texcoords [localMeshVertexCount * 2 + 1 ] = 0.0f ;
4556+ }
4557+
45334558 if (objAttributes .normals != NULL && normalIndex != TINYOBJ_INVALID_INDEX && normalIndex >= 0 )
45344559 {
45354560 for (int i = 0 ; i < 3 ; i ++ ) model .meshes [meshIndex ].normals [localMeshVertexCount * 3 + i ] = objAttributes .normals [normalIndex * 3 + i ];
@@ -4540,11 +4565,9 @@ static Model LoadOBJ(const char *fileName)
45404565 model .meshes [meshIndex ].normals [localMeshVertexCount * 3 + 1 ] = 1.0f ;
45414566 model .meshes [meshIndex ].normals [localMeshVertexCount * 3 + 2 ] = 0.0f ;
45424567 }
4543-
4544- model .meshes [meshIndex ].texcoords [localMeshVertexCount * 2 + 1 ] = 1.0f - model .meshes [meshIndex ].texcoords [localMeshVertexCount * 2 + 1 ];
4545-
4568+ #if defined(GRAPHICS_API_OPENGL_33 ) || defined(GRAPHICS_API_OPENGL_ES2 )
45464569 for (int i = 0 ; i < 4 ; i ++ ) model .meshes [meshIndex ].colors [localMeshVertexCount * 4 + i ] = 255 ;
4547-
4570+ #endif
45484571 faceVertIndex ++ ;
45494572 localMeshVertexCount ++ ;
45504573 }
0 commit comments