Corrected crazy bug about model textures

On OpenGL ES it was set to use GL_CLAMP_TO_EDGE wrap mode for textures.
On LoadOBJ() texture coordinates were wrongly Y-flipped
This commit is contained in:
raysan5 2015-09-02 20:36:05 +02:00
parent ab459bf418
commit 94d0e83207
2 changed files with 19 additions and 8 deletions

View file

@ -1731,7 +1731,7 @@ static VertexData LoadOBJ(const char *fileName)
int tcCounter = 0; // Used to count texcoords float by float int tcCounter = 0; // Used to count texcoords float by float
int nCounter = 0; // Used to count normals float by float int nCounter = 0; // Used to count normals float by float
int vNum[3], vtNum[3], vnNum[3]; int vNum[3], vtNum[3], vnNum[3]; // Used to store triangle indices for v, vt, vn
rewind(objFile); // Return to the beginning of the file, to read again rewind(objFile); // Return to the beginning of the file, to read again
@ -1803,14 +1803,16 @@ static VertexData LoadOBJ(const char *fileName)
if (numTexCoords > 0) if (numTexCoords > 0)
{ {
// NOTE: If using negative texture coordinates with a texture filter of GL_CLAMP_TO_EDGE doesn't work!
// NOTE: Texture coordinates are Y flipped upside-down
vData.texcoords[tcCounter] = midTexCoords[vtNum[0]-1].x; vData.texcoords[tcCounter] = midTexCoords[vtNum[0]-1].x;
vData.texcoords[tcCounter + 1] = -midTexCoords[vtNum[0]-1].y; vData.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[0]-1].y;
tcCounter += 2; tcCounter += 2;
vData.texcoords[tcCounter] = midTexCoords[vtNum[1]-1].x; vData.texcoords[tcCounter] = midTexCoords[vtNum[1]-1].x;
vData.texcoords[tcCounter + 1] = -midTexCoords[vtNum[1]-1].y; vData.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[1]-1].y;
tcCounter += 2; tcCounter += 2;
vData.texcoords[tcCounter] = midTexCoords[vtNum[2]-1].x; vData.texcoords[tcCounter] = midTexCoords[vtNum[2]-1].x;
vData.texcoords[tcCounter + 1] = -midTexCoords[vtNum[2]-1].y; vData.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[2]-1].y;
tcCounter += 2; tcCounter += 2;
} }
} break; } break;

View file

@ -1219,7 +1219,7 @@ void rlglClose(void)
rlDeleteVertexArrays(postproQuad.mesh.vaoId); rlDeleteVertexArrays(postproQuad.mesh.vaoId);
TraceLog(INFO, "[FBO %i] Unloaded postpro quad data", fbo); TraceLog(INFO, "[FBO %i] Unloaded postprocessing data", fbo);
} }
free(draws); free(draws);
@ -1780,8 +1780,17 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int textureForma
// NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used
#if defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_ES2)
// NOTE: OpenGL ES 2.0 with no GL_OES_texture_npot support (i.e. WebGL) has limited NPOT support, so CLAMP_TO_EDGE must be used // NOTE: OpenGL ES 2.0 with no GL_OES_texture_npot support (i.e. WebGL) has limited NPOT support, so CLAMP_TO_EDGE must be used
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Set texture to clamp on x-axis if (npotSupported)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Set texture to clamp on y-axis {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repeat on x-axis
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repeat on y-axis
}
else
{
// NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Set texture to clamp on x-axis
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Set texture to clamp on y-axis
}
#else #else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repeat on x-axis glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repeat on x-axis
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repeat on y-axis glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repeat on y-axis