i fixed that it works like a charm now
only thing still not completely working are shadows & dynamic lighting
"need a struct replacement for the lookuptable"
here's my current code for the md3 renderer
Code:
void R_DrawQ3Model(entity_t *e)
{
int i, j, k, lnum;
int frame;
int lastframe;
int vertframeoffset;
int lastvertframeoffset;
float alpha;
float blend, iblend;
float l, add, radiusmax = 0.0;
vec3_t l_v, vec, normal;
vec3_t dist, ang, dlight_color;
model_t *clmodel;
md3header_mem_t *header;
md3surface_mem_t *surf;
md3shader_mem_t *shader;
md3st_mem_t *tc;
md3tri_mem_t *tris;
md3vert_mem_t *verts, *vertslast;
if (!gl_notrans.value) {
// allways true if not -nehahra
model_alpha = currententity->transparency;
if (model_alpha == 0) {
model_alpha = 1.0;
}
} else {
model_alpha = 1.0;
}
alpha = (currententity == &cl.viewent && gl_mtexable) ?
(
(cl.items & IT_INVISIBILITY) ?
gl_ringalpha.value : bound(0, r_drawviewmodel.value, 1)
) : model_alpha;
if (alpha < 1.0) {
glEnable (GL_BLEND);
}
//md3 interpolation
clmodel = e->model;
e->frame_interval = 0.1f;
if (e->pose2 != e->frame) {
e->frame_start_time = realtime;
e->pose1 = e->pose2;
e->pose2 = e->frame;
blend = 0;
} else {
blend = (realtime - e->frame_start_time) / e->frame_interval;
if (blend > 1)
blend = 1;
}
iblend = 1.0 - blend;
// get lighting information
// make thunderbolt and torches full light
if (clmodel->modhint == MOD_THUNDERBOLT) {
ambientlight = 210;
shadelight = 0;
r_lightlevel = true;
} else if (clmodel->modhint == MOD_FLAME) {
ambientlight = 255;
shadelight = 0;
r_lightlevel = true;
} else {
// normal lighting
r_lightlevel = false;
ambientlight = shadelight = R_LightPoint (currententity->origin);
for (lnum = 0 ; lnum < MAX_DLIGHTS ; lnum++) {
if (cl_dlights[lnum].die < realtime || !cl_dlights[lnum].radius) continue;
VectorSubtract (e->origin, cl_dlights[lnum].origin, dist);
add = cl_dlights[lnum].radius - Length (dist);
if (add > 0) {
if (gl_vertexlights.value) {
if (!radiusmax || cl_dlights[lnum].radius > radiusmax) {
radiusmax = cl_dlights[lnum].radius;
VectorCopy(cl_dlights[lnum].origin, vertexlight);
}
}
VectorCopy(bubblecolor[cl_dlights[lnum].type], dlight_color);
for (i=0 ; i<3 ; i++) {
lightcolor[i] = lightcolor[i] + (dlight_color[i] * add) * 2;
if (lightcolor[i] > 256) {
switch (i) {
case 0:
lightcolor[1] = lightcolor[1] - (1 * lightcolor[1]/3);
lightcolor[2] = lightcolor[2] - (1 * lightcolor[2]/3);
break;
case 1:
lightcolor[0] = lightcolor[0] - (1 * lightcolor[0]/3);
lightcolor[2] = lightcolor[2] - (1 * lightcolor[2]/3);
break;
case 2:
lightcolor[1] = lightcolor[1] - (1 * lightcolor[1]/3);
lightcolor[0] = lightcolor[0] - (1 * lightcolor[0]/3);
break;
}
}
}
}
}
// calculate pitch and yaw for vertex lighting
if (gl_vertexlights.value) {
apitch = currententity->angles[0];
ayaw = currententity->angles[1];
if (!radiusmax) {
vlight_pitch = 45;
vlight_yaw = 45;
} else {
VectorSubtract(vertexlight, currententity->origin, dist);
vectoangles(dist, ang);
vlight_pitch = ang[0];
vlight_yaw = ang[1];
}
}
// clamp lighting so it doesn't overbright as much
ambientlight = min(128, ambientlight);
if (ambientlight + shadelight > 192) {
shadelight = 192 - ambientlight;
}
// always give the gun some light
if (e == &cl.viewent && ambientlight < 24) {
ambientlight = shadelight = 24;
}
// never allow players to go totally black
if (clmodel->modhint == MOD_PLAYER) {
if (ambientlight < 8) {
ambientlight = shadelight = 8;
}
}
}
if (clmodel->modhint == MOD_PLAYER && r_fullbrightskins.value) {
ambientlight = shadelight = 128;
r_lightlevel = true;
}
header = (md3header_mem_t *)Mod_Extradata (currententity->model);
if (*(long *)header->id != MD3IDHEADER){
Con_Printf("MD3 bad model for: %s\n", header->filename);
return;
}
glPushMatrix();
//interpolate unless its the viewmodel
if (e != &cl.viewent) {
R_BlendedRotateForEntity (e, 0);
} else {
R_RotateForEntity (e);
}
surf = (md3surface_mem_t *)((byte *)header + header->offs_surfaces);
for (i = 0; i < header->num_surfaces; i++) {
if (*(long *)surf->id != MD3IDHEADER){
Con_Printf("MD3 bad surface for: %s\n", header->filename);
}
if (surf->num_surf_frames == 0){
surf = (md3surface_mem_t *)((byte *)surf + surf->offs_end);
continue; //shouldn't ever do this, each surface should have at least one frame
}
frame = e->frame;
frame = frame%surf->num_surf_frames; //cap the frame inside the list of frames in the model
vertframeoffset = frame*surf->num_surf_verts * sizeof(md3vert_mem_t);
lastframe = e->pose1%surf->num_surf_frames;
lastvertframeoffset = lastframe*surf->num_surf_verts * sizeof(md3vert_mem_t);
//get pointer to shaders
shader = (md3shader_mem_t *)((byte *)surf + surf->offs_shaders);
tc = (md3st_mem_t *)((byte *)surf + surf->offs_tc);
tris = (md3tri_mem_t *)((byte *)surf + surf->offs_tris);
verts = (md3vert_mem_t *)((byte *)surf + surf->offs_verts + vertframeoffset);
vertslast = (md3vert_mem_t *)((byte *)surf + surf->offs_verts + lastvertframeoffset);
// if shader binds to e->skinum
// it will fuck up modeltextures
// so use currententity instead
if (surf->num_surf_shaders!=0) {
GL_Bind(shader[(currententity->skinnum%surf->num_surf_shaders)].texnum);
} else {
GL_Bind(0);
}
// normals and vertexes come from the frame list
// blend the light intensity from the two frames together
// yeah like fuck it does that right :(
if (blend >=1) {
l = R_LerpVertexLight ((int)verts->normal, (int)verts->vec, blend, apitch, ayaw);
l = min(l, 1);
} else {
l = R_GetVertexLightValue ((int)verts->normal, apitch, ayaw);
l = min(l, 1);
}
if (!r_lightlevel) {
for (i=0 ; i<3 ; i++) {
l_v[i] = lightcolor[i] / 256 + l;
}
glColor4f (l_v[0], l_v[1], l_v[2], alpha);
}
if (blend >=1) {
glNormalPointer(GL_FLOAT, 6 * sizeof(float), (float *)verts->normal);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (float *)verts->vec);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, (float *)tc);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawElements(GL_TRIANGLES, surf->num_surf_tris*3, GL_UNSIGNED_INT, (int *)tris);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
} else {
glBegin(GL_TRIANGLES);
//for each triangle
for (j = 0; j < surf->num_surf_tris; j++) {
//draw the poly
for (k=0; k < 3; k++) {
//interpolated
vec[0] = verts[tris[j].tri[k]].vec[0] * blend + vertslast[tris[j].tri[k]].vec[0] * iblend;
vec[1] = verts[tris[j].tri[k]].vec[1] * blend + vertslast[tris[j].tri[k]].vec[1] * iblend;
vec[2] = verts[tris[j].tri[k]].vec[2] * blend + vertslast[tris[j].tri[k]].vec[2] * iblend;
normal[0] = verts[tris[j].tri[k]].normal[0] * blend + vertslast[tris[j].tri[k]].normal[0] * iblend;
normal[1] = verts[tris[j].tri[k]].normal[1] * blend + vertslast[tris[j].tri[k]].normal[1] * iblend;
normal[2] = verts[tris[j].tri[k]].normal[2] * blend + vertslast[tris[j].tri[k]].normal[2] * iblend;
glTexCoord2f (tc[tris[j].tri[k]].s, tc[tris[j].tri[k]].t);
glTexCoord2f (tc[tris[j].tri[k]].s, tc[tris[j].tri[k]].t);
glVertex3fv(vec);
glNormal3fv(normal);
}
}
glEnd();
}
surf = (md3surface_mem_t *)((byte *)surf + surf->offs_end);
if (alpha < 1.0) {
glDisable (GL_BLEND);
}
}
glPopMatrix();
}
hope this is to some help