2006-10-24 15:04:02 +00:00
|
|
|
#include <stdlib.h>
|
2005-04-18 15:27:00 +00:00
|
|
|
#include <math.h>
|
2006-10-24 15:04:02 +00:00
|
|
|
#include <GL/gl.h>
|
2006-11-20 22:40:04 +00:00
|
|
|
#include <GL/glext.h>
|
2005-04-22 19:51:02 +00:00
|
|
|
#include <neofx/math.h>
|
2006-10-24 15:04:02 +00:00
|
|
|
#include <zoom/level.h>
|
|
|
|
#include <zoom/light.h>
|
|
|
|
#include <zoom/player.h>
|
|
|
|
#include <zoom/render.h>
|
|
|
|
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
extern PLAYER player;
|
2007-05-14 17:38:01 +00:00
|
|
|
extern LEVEL *level;
|
2005-04-18 15:27:00 +00:00
|
|
|
extern GLuint sphere;
|
2006-10-24 15:04:02 +00:00
|
|
|
extern int nLights;
|
|
|
|
extern LIGHT *lights;
|
2006-11-19 22:03:05 +00:00
|
|
|
extern COLOR ambient;
|
2006-10-24 15:04:02 +00:00
|
|
|
extern GLuint lightmap;
|
2006-10-20 12:57:05 +00:00
|
|
|
|
2005-04-18 15:27:00 +00:00
|
|
|
|
2006-11-22 22:33:04 +00:00
|
|
|
static int SortByTex(const void *p1, const void *p2) {
|
|
|
|
return ((POLYGON*)p1)->texture - ((POLYGON*)p2)->texture;
|
|
|
|
}
|
|
|
|
|
2005-04-18 15:27:00 +00:00
|
|
|
void Render() {
|
2007-10-31 23:27:03 +00:00
|
|
|
//GLfloat std_emission[] ={{0.0, 0.0, 0.0, 1.0};
|
|
|
|
MATRIX rotate = {.f = {
|
2005-04-18 15:27:00 +00:00
|
|
|
player.rotycos, 0.0, -player.rotysin, 0.0,
|
|
|
|
0.0, 1.0, 0.0, 0.0,
|
|
|
|
player.rotysin, 0.0, player.rotycos, 0.0,
|
|
|
|
0.0, 0.0, 0.0, 1.0
|
2007-10-31 23:27:03 +00:00
|
|
|
}};
|
2006-10-24 15:04:02 +00:00
|
|
|
POLYGON_LIST *room;
|
|
|
|
int i, j, k;
|
|
|
|
float d;
|
|
|
|
VECTOR v, v1, v2;
|
|
|
|
VERTEX p;
|
|
|
|
COLOR c;
|
2006-11-22 22:33:04 +00:00
|
|
|
GLint last_tex;
|
2006-10-24 15:04:02 +00:00
|
|
|
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glRotatef(player.rotx, 1.0, 0.0, 0.0);
|
|
|
|
glMultMatrixf(rotate.f);
|
|
|
|
|
|
|
|
|
|
|
|
glTranslatef(-player.pos.x, -player.pos.y, -player.pos.z);
|
|
|
|
|
2007-05-14 17:38:01 +00:00
|
|
|
room = DrawRoom(level, player.room);
|
2006-11-22 22:33:04 +00:00
|
|
|
qsort(room->polygons, room->nPolygons, sizeof(POLYGON), SortByTex);
|
2006-10-24 15:04:02 +00:00
|
|
|
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
2006-11-19 22:03:05 +00:00
|
|
|
glBlendFunc(GL_ONE, GL_ZERO);
|
2006-10-24 15:04:02 +00:00
|
|
|
|
2006-11-19 22:03:05 +00:00
|
|
|
glColor3fv((GLfloat*)&ambient);
|
2006-10-24 15:04:02 +00:00
|
|
|
|
2006-11-19 22:03:05 +00:00
|
|
|
glActiveTexture(GL_TEXTURE1);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2006-10-24 15:04:02 +00:00
|
|
|
|
2006-11-22 22:33:04 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, room->polygons[0].texture);
|
|
|
|
last_tex = room->polygons[0].texture;
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
for(i = 0; i < room->nPolygons; i++) {
|
2006-11-22 22:33:04 +00:00
|
|
|
if(last_tex != room->polygons[i].texture) {
|
|
|
|
glEnd();
|
|
|
|
glBindTexture(GL_TEXTURE_2D, room->polygons[i].texture);
|
|
|
|
last_tex = room->polygons[i].texture;
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
}
|
2006-11-19 22:03:05 +00:00
|
|
|
|
|
|
|
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[0]);
|
2006-10-24 15:04:02 +00:00
|
|
|
glVertex3fv((GLfloat*)&room->polygons[i].vertices[0]);
|
2006-11-19 22:03:05 +00:00
|
|
|
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[1]);
|
2006-10-24 15:04:02 +00:00
|
|
|
glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
|
2006-11-19 22:03:05 +00:00
|
|
|
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[2]);
|
2006-10-24 15:04:02 +00:00
|
|
|
glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
|
2006-11-19 22:03:05 +00:00
|
|
|
|
2006-11-22 22:33:04 +00:00
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
}
|
|
|
|
|
2006-11-22 22:33:04 +00:00
|
|
|
glEnd();
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
glDepthFunc(GL_EQUAL);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
|
2006-11-19 22:03:05 +00:00
|
|
|
glBlendFunc(GL_ONE, GL_ONE);
|
|
|
|
|
|
|
|
glColor3f(1.0, 1.0, 1.0);
|
2006-10-24 15:04:02 +00:00
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, lightmap);
|
2006-11-19 22:03:05 +00:00
|
|
|
glActiveTexture(GL_TEXTURE1);
|
2006-10-24 15:04:02 +00:00
|
|
|
|
|
|
|
for(i = 0; i < nLights; i++) {
|
2007-10-31 20:57:00 +00:00
|
|
|
if(room->polygons[0].texture) {
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, room->polygons[0].texture);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
2006-11-22 22:33:04 +00:00
|
|
|
last_tex = room->polygons[0].texture;
|
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
for(j = 0; j < room->nPolygons; j++) {
|
2006-11-22 22:33:04 +00:00
|
|
|
if(last_tex != room->polygons[j].texture) {
|
|
|
|
glEnd();
|
|
|
|
glBindTexture(GL_TEXTURE_2D, room->polygons[j].texture);
|
|
|
|
last_tex = room->polygons[j].texture;
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
}
|
2006-10-24 15:04:02 +00:00
|
|
|
|
2006-11-19 22:03:05 +00:00
|
|
|
d = VectorDot(room->polygons[j].normal, VectorSub(room->polygons[j].vertices[0], lights[i].pos));
|
2006-10-24 15:04:02 +00:00
|
|
|
|
2006-11-19 22:03:05 +00:00
|
|
|
if(d < 0) {
|
2006-11-22 22:33:04 +00:00
|
|
|
c = VectorMul(lights[i].diffuse, 1.0/(d*d));
|
2006-11-19 22:03:05 +00:00
|
|
|
glColor3fv((GLfloat*)&c);
|
|
|
|
|
|
|
|
v1 = VectorNormalize(VectorSub(room->polygons[j].vertices[0], room->polygons[j].vertices[1]));
|
2006-10-24 15:04:02 +00:00
|
|
|
|
2006-11-19 22:03:05 +00:00
|
|
|
for(k = 0; k < 3; k++) {
|
2007-05-14 17:38:01 +00:00
|
|
|
p = VectorAdd(lights[i].pos, VectorMul(room->polygons[j].normals[k], d));
|
2006-11-19 22:03:05 +00:00
|
|
|
v = VectorSub(room->polygons[j].vertices[k], p);
|
|
|
|
|
2007-05-14 17:38:01 +00:00
|
|
|
v2 = VectorCross(v1, room->polygons[j].normals[k]);
|
|
|
|
|
2006-11-19 22:03:05 +00:00
|
|
|
glMultiTexCoord2f(0, VectorDot(v, v1)*0.04 / d + 0.5, VectorDot(v, v2)*0.04 / d + 0.5);
|
|
|
|
glMultiTexCoord2fv(1, (GLfloat*)&room->polygons[j].texcoords[k]);
|
|
|
|
glVertex3fv((GLfloat*)&room->polygons[j].vertices[k]);
|
|
|
|
}
|
2006-10-24 15:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-22 22:33:04 +00:00
|
|
|
|
|
|
|
glEnd();
|
2006-10-24 15:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(room);
|
|
|
|
|
|
|
|
/*glPushMatrix();
|
2005-04-18 15:27:00 +00:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
2006-10-24 15:04:02 +00:00
|
|
|
glColor3f(1.0, 1.0, 1.0);
|
|
|
|
glTranslatef(lights[0].pos.x, lights[0].pos.y, lights[0].pos.z);
|
2005-04-18 15:27:00 +00:00
|
|
|
glScalef(0.1, 0.1, 0.1);
|
|
|
|
glCallList(sphere);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
2006-10-24 15:04:02 +00:00
|
|
|
glPopMatrix();*/
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glFlush();
|
|
|
|
}
|