Fixed a few unnoticable mistakes [vanilla]

This commit is contained in:
AJ Freda 2018-12-19 20:52:47 -05:00 committed by mazmazz
parent 09629f092f
commit 4806dadd88
2 changed files with 31 additions and 47 deletions

View file

@ -454,12 +454,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
else // Full float loading method else // Full float loading method
{ {
md2triangle_t *trisPtr = tris; md2triangle_t *trisPtr = tris;
float *uvptr = retModel->meshes[0].uvs; float *uvptr;
char *ptr = (char*)frames; char *ptr = (char*)frames;
retModel->meshes[0].numVertices = header->numTris*3; retModel->meshes[0].numVertices = header->numTris*3;
retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0);
retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0); retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0);
uvptr = retModel->meshes[0].uvs;
for (i = 0; i < retModel->meshes[0].numTriangles; i++, trisPtr++) for (i = 0; i < retModel->meshes[0].numTriangles; i++, trisPtr++)
{ {

View file

@ -1924,6 +1924,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
GLfloat diffuse[4]; GLfloat diffuse[4];
float pol = 0.0f; float pol = 0.0f;
scale *= 0.5f;
float scalex = scale, scaley = scale, scalez = scale; float scalex = scale, scaley = scale, scalez = scale;
boolean useTinyFrames; boolean useTinyFrames;
@ -1935,8 +1936,6 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f}; GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f};
#endif #endif
scale *= 0.5f;
if (duration != 0 && duration != -1 && tics != -1) // don't interpolate if instantaneous or infinite in length if (duration != 0 && duration != -1 && tics != -1) // don't interpolate if instantaneous or infinite in length
{ {
UINT32 newtime = (duration - tics); // + 1; UINT32 newtime = (duration - tics); // + 1;
@ -2054,22 +2053,16 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices);
pglDisableClientState(GL_NORMAL_ARRAY); pglDisableClientState(GL_NORMAL_ARRAY);
pglDisableClientState(GL_TEXTURE_COORD_ARRAY); pglDisableClientState(GL_TEXTURE_COORD_ARRAY);
pglDisableClientState(GL_TEXTURE_COORD_ARRAY); pglDisableClientState(GL_VERTEX_ARRAY);
} }
else else
{ {
short *buffer, *vertPtr;
char *normBuffer, *normPtr;
float *uvPtr;
int j = 0;
// Dangit, I soooo want to do this in a GLSL shader... // Dangit, I soooo want to do this in a GLSL shader...
pglBegin(GL_TRIANGLES); short *buffer = malloc(mesh->numVertices * sizeof(short) * 3);
short *vertPtr = buffer;
buffer = malloc(mesh->numVertices * sizeof(short)); char *normBuffer = malloc(mesh->numVertices * sizeof(char) * 3);
vertPtr = buffer; char *normPtr = normBuffer;
normBuffer = malloc(mesh->numVertices * sizeof(char)); int j = 0;
normPtr = normBuffer;
for (j = 0; j < mesh->numVertices; j++) for (j = 0; j < mesh->numVertices; j++)
{ {
@ -2078,24 +2071,19 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
*normPtr++ = (char)(frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j]))); *normPtr++ = (char)(frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j])));
} }
uvPtr = mesh->uvs; pglEnableClientState(GL_VERTEX_ARRAY);
vertPtr = buffer; pglEnableClientState(GL_TEXTURE_COORD_ARRAY);
normPtr = normBuffer; pglEnableClientState(GL_NORMAL_ARRAY);
for (j = 0; j < mesh->numTriangles; j++) pglVertexPointer(3, GL_SHORT, 0, buffer);
{ pglNormalPointer(GL_BYTE, 0, normBuffer);
pglTexCoord2fv(uvPtr); pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs);
pglNormal3bv((signed char*) normPtr); pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices);
pglVertex3sv(vertPtr); pglDisableClientState(GL_NORMAL_ARRAY);
pglDisableClientState(GL_TEXTURE_COORD_ARRAY);
uvPtr += 2; pglDisableClientState(GL_VERTEX_ARRAY);
normPtr += 3;
vertPtr += 3;
}
free(buffer); free(buffer);
free(normBuffer); free(normBuffer);
pglEnd();
} }
} }
else else
@ -2118,39 +2106,34 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3);
pglDisableClientState(GL_NORMAL_ARRAY); pglDisableClientState(GL_NORMAL_ARRAY);
pglDisableClientState(GL_TEXTURE_COORD_ARRAY); pglDisableClientState(GL_TEXTURE_COORD_ARRAY);
pglDisableClientState(GL_TEXTURE_COORD_ARRAY); pglDisableClientState(GL_VERTEX_ARRAY);
} }
else else
{ {
int j = 0; int j = 0;
float *uvPtr; float *uvPtr = mesh->uvs;
float *frameVert; float *frameVert = frame->vertices;
float *frameNormal; float *frameNormal = frame->normals;
float *nextFrameVert; float *nextFrameVert = nextframe->vertices;
float *nextFrameNormal; float *nextFrameNormal = nextframe->normals;
// Dangit, I soooo want to do this in a GLSL shader... // Dangit, I soooo want to do this in a GLSL shader...
pglBegin(GL_TRIANGLES); pglBegin(GL_TRIANGLES);
uvPtr = mesh->uvs; for (j = 0; j < mesh->numTriangles * 3; j++)
frameVert = frame->vertices;
frameNormal = frame->normals;
nextFrameVert = nextframe->vertices;
nextFrameNormal = frame->normals;
for (j = 0; j < mesh->numTriangles; j++)
{ {
// Interpolate // Interpolate
float px1 = *frameVert++; float px1 = *frameVert++;
float px2 = *nextFrameVert++;
float py1 = *frameVert++; float py1 = *frameVert++;
float py2 = *nextFrameVert++;
float pz1 = *frameVert++; float pz1 = *frameVert++;
float px2 = *nextFrameVert++;
float py2 = *nextFrameVert++;
float pz2 = *nextFrameVert++; float pz2 = *nextFrameVert++;
float nx1 = *frameNormal++; float nx1 = *frameNormal++;
float nx2 = *nextFrameNormal++;
float ny1 = *frameNormal++; float ny1 = *frameNormal++;
float ny2 = *nextFrameNormal++;
float nz1 = *frameNormal++; float nz1 = *frameNormal++;
float nx2 = *nextFrameNormal++;
float ny2 = *nextFrameNormal++;
float nz2 = *nextFrameNormal++; float nz2 = *nextFrameNormal++;
pglTexCoord2fv(uvPtr); pglTexCoord2fv(uvPtr);
@ -2161,7 +2144,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
(py1 + pol * (py2 - py1)), (py1 + pol * (py2 - py1)),
(pz1 + pol * (pz2 - pz1))); (pz1 + pol * (pz2 - pz1)));
uvPtr++; uvPtr += 2;
} }
pglEnd(); pglEnd();