summaryrefslogtreecommitdiffstats
path: root/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'render.c')
-rw-r--r--render.c173
1 files changed, 102 insertions, 71 deletions
diff --git a/render.c b/render.c
index 508be8a..fd57ca7 100644
--- a/render.c
+++ b/render.c
@@ -1,69 +1,22 @@
-#include <GL/gl.h>
+#include <stdlib.h>
#include <math.h>
-#include <zoom/render.h>
-#include <zoom/player.h>
-#include <zoom/level.h>
-#include <zoom/texture.h>
+#include <GL/gl.h>
#include <neofx/math.h>
+#include <zoom/level.h>
+#include <zoom/light.h>
+#include <zoom/player.h>
+#include <zoom/render.h>
+
extern PLAYER player;
extern LEVEL level;
extern GLuint sphere;
-extern LIGHT light;
+extern int nLights;
+extern LIGHT *lights;
+extern GLuint lightmap;
-void RenderWall(WALL w, GLuint *textures) {
- int i;
- float d, s, t;
- VECTOR v, v1, v2;
- VERTEX p;
-
- glBindTexture(GL_TEXTURE_2D, textures[w.texture]);
-
- d = VectorDot(w.normal, VectorSub(w.vertices[0], light.pos));
-
- if(d >= 0) {
- glActiveTexture(GL_TEXTURE0);
- glDisable(GL_TEXTURE_2D);
-
- glBegin(GL_TRIANGLES);
-
- for(i = 0; i < 3; i++) {
- glMultiTexCoord2fv(GL_TEXTURE1, (GLfloat*)&w.texcoords[i]);
- glVertex3fv((GLfloat*)&w.vertices[i]);
- }
-
- glEnd();
-
- glEnable(GL_TEXTURE_2D);
- glActiveTexture(GL_TEXTURE1);
-
- return;
- }
-
- p = VectorAdd(light.pos, VectorMul(w.normal, d));
-
- v1 = VectorNormalize(VectorSub(w.vertices[0], w.vertices[1]));
- v2 = VectorCross(v1, w.normal);
-
- glBegin(GL_TRIANGLES);
-
- glNormal3fv((GLfloat*)&w.normal);
-
- for(i = 0; i < 3; i++) {
- v = VectorSub(w.vertices[i], p);
- s = VectorDot(v, v1)*0.005 / d + 0.5;
- t = VectorDot(v, v2)*0.005 / d + 0.5;
- glMultiTexCoord2f(GL_TEXTURE0, s, t);
- glMultiTexCoord2fv(GL_TEXTURE1, (GLfloat*)&w.texcoords[i]);
- glVertex3fv((GLfloat*)&w.vertices[i]);
- }
-
- glEnd();
-}
void Render() {
- //GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
- //GLfloat light_emission[] = {1.0, 1.0, 1.0, 1.0};
GLfloat std_emission[] = {0.0, 0.0, 0.0, 1.0};
MATRIX rotate = {
player.rotycos, 0.0, -player.rotysin, 0.0,
@@ -71,10 +24,14 @@ void Render() {
player.rotysin, 0.0, player.rotycos, 0.0,
0.0, 0.0, 0.0, 1.0
};
- COLOR color_light = {1.0, 1.0, 1.0};
- COLOR color_ambient = {0.1, 0.1, 0.1};
+ POLYGON_LIST *room;
+ int i, j, k;
+ float d;
+ VECTOR v, v1, v2;
+ VERTEX p;
+ COLOR c;
+
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(player.rotx, 1.0, 0.0, 0.0);
@@ -83,21 +40,95 @@ void Render() {
glTranslatef(-player.pos.x, -player.pos.y, -player.pos.z);
- //glLightfv(GL_LIGHT0, GL_POSITION, light_position);
- glPushMatrix();
+ room = DrawRoom(&level, player.room);
+
+ glDepthMask(GL_TRUE);
+ glDepthFunc(GL_LESS);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+
+ glBlendFunc(GL_ONE, GL_ONE);
+
+ glColor3f(0.0, 0.0, 0.0);
+ glTexCoord2f(0.0, 0.0);
+
+ glBegin(GL_TRIANGLES);
+
+ for(i = 0; i < room->nPolygons; i++) {
+ glVertex3fv((GLfloat*)&room->polygons[i].vertices[0]);
+ glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
+ glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
+ }
+
+ glEnd();
+
+ glDepthFunc(GL_EQUAL);
+ glDepthMask(GL_FALSE);
+
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+ glBindTexture(GL_TEXTURE_2D, lightmap);
+
+ for(i = 0; i < nLights; i++) {
+ glBegin(GL_TRIANGLES);
+
+ for(j = 0; j < room->nPolygons; j++) {
+ d = VectorDot(room->polygons[j].normal, VectorSub(room->polygons[j].vertices[0], lights[i].pos));
+
+ if(d >= 0) continue;
+
+ c = VectorMul(lights[i].diffuse, 1.0/((nLights+1)*d*d));
+ glColor3fv((GLfloat*)&c);
+
+ p = VectorAdd(lights[i].pos, VectorMul(room->polygons[j].normal, d));
+
+ v1 = VectorNormalize(VectorSub(room->polygons[j].vertices[0], room->polygons[j].vertices[1]));
+ v2 = VectorCross(v1, room->polygons[j].normal);
+
+ for(k = 0; k < 3; k++) {
+ v = VectorSub(room->polygons[j].vertices[k], p);
+
+ glTexCoord2f(VectorDot(v, v1)*0.04 / d + 0.5, VectorDot(v, v2)*0.04 / d + 0.5);
+ glVertex3fv((GLfloat*)&room->polygons[j].vertices[k]);
+ }
+ }
+
+ glEnd();
+ }
+
+ glBlendFunc(GL_DST_COLOR, GL_ZERO);
+
+ glColor3f(1.0, 1.0, 1.0);
+
+ /*for(i = 0; i < room->nPolygons; i++) {
+ glBindTexture(GL_TEXTURE_2D, room->polygons[i].texture);
+
+ glBegin(GL_TRIANGLES);
+
+ glTexCoord2fv((GLfloat*)&room->polygons[i].texcoords[0]);
+ glVertex3fv((GLfloat*)&room->polygons[i].vertices[0]);
+ glTexCoord2fv((GLfloat*)&room->polygons[i].texcoords[1]);
+ glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
+ glTexCoord2fv((GLfloat*)&room->polygons[i].texcoords[2]);
+ glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
+
+ glEnd();
+ }*/
+
+ free(room);
+
+ ApplyLightScale();
+
+ /*glPushMatrix();
glDisable(GL_TEXTURE_2D);
- glColor3fv((GLfloat*)&color_light);
- //glMaterialfv(GL_FRONT, GL_EMISSION, light_emission);
- glTranslatef(light.pos.x, light.pos.y, light.pos.z);
+ glColor3f(1.0, 1.0, 1.0);
+ glTranslatef(lights[0].pos.x, lights[0].pos.y, lights[0].pos.z);
glScalef(0.1, 0.1, 0.1);
glCallList(sphere);
- //glMaterialfv(GL_FRONT, GL_EMISSION, std_emission);
glEnable(GL_TEXTURE_2D);
- glPopMatrix();
-
- glColor3fv((GLfloat*)&color_ambient);
-
- DrawRoom(&level, player.room);
+ glPopMatrix();*/
glFlush();
}