summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--init.c2
-rw-r--r--light.c15
-rw-r--r--render.c87
-rw-r--r--zoom/light.h1
4 files changed, 42 insertions, 63 deletions
diff --git a/init.c b/init.c
index 19aaf02..defc60e 100644
--- a/init.c
+++ b/init.c
@@ -49,8 +49,6 @@ int InitGame() {
meditex_blue = LoadTexture("medib.tex");
-
-
lightmap = LoadTexture("lightmap.tex");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
diff --git a/light.c b/light.c
index dcea864..216007d 100644
--- a/light.c
+++ b/light.c
@@ -6,17 +6,11 @@
int nLights = 0;
LIGHT *lights;
-static COLOR ambient;
+COLOR ambient;
-static void UpdateAmbient() {
- glClearColor(ambient.r/(nLights+1), ambient.g/(nLights+1), ambient.b/(nLights+1), 1.0);
-}
-
void SetAmbient(COLOR c) {
ambient = c;
-
- UpdateAmbient();
}
void AddLight(LIGHT light) {
@@ -27,8 +21,6 @@ void AddLight(LIGHT light) {
lights[nLights] = light;
nLights++;
-
- UpdateAmbient();
}
void ResetLights() {
@@ -38,8 +30,3 @@ void ResetLights() {
UpdateAmbient();
}
}
-
-void ApplyLightScale() {
- glAccum(GL_LOAD, 1);
- glAccum(GL_RETURN, nLights+1);
-}
diff --git a/render.c b/render.c
index fd57ca7..d626a99 100644
--- a/render.c
+++ b/render.c
@@ -13,6 +13,7 @@ extern LEVEL level;
extern GLuint sphere;
extern int nLights;
extern LIGHT *lights;
+extern COLOR ambient;
extern GLuint lightmap;
@@ -47,79 +48,73 @@ void Render() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ glBlendFunc(GL_ONE, GL_ZERO);
- glBlendFunc(GL_ONE, GL_ONE);
-
- glColor3f(0.0, 0.0, 0.0);
- glTexCoord2f(0.0, 0.0);
+ glColor3fv((GLfloat*)&ambient);
- glBegin(GL_TRIANGLES);
+ glActiveTexture(GL_TEXTURE1);
+ glDisable(GL_TEXTURE_2D);
+ glActiveTexture(GL_TEXTURE0);
for(i = 0; i < room->nPolygons; i++) {
+ glBindTexture(GL_TEXTURE_2D, room->polygons[i].texture);
+
+ glBegin(GL_TRIANGLES);
+
+ glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[0]);
glVertex3fv((GLfloat*)&room->polygons[i].vertices[0]);
+ glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[1]);
glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
+ glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[2]);
glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
+
+ glEnd();
}
- glEnd();
-
glDepthFunc(GL_EQUAL);
glDepthMask(GL_FALSE);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glBlendFunc(GL_ONE, GL_ONE);
+
+ glColor3f(1.0, 1.0, 1.0);
glBindTexture(GL_TEXTURE_2D, lightmap);
+ glActiveTexture(GL_TEXTURE1);
+ glEnable(GL_TEXTURE_2D);
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);
+ glBindTexture(GL_TEXTURE_2D, room->polygons[j].texture);
- p = VectorAdd(lights[i].pos, VectorMul(room->polygons[j].normal, d));
+ glBegin(GL_TRIANGLES);
- v1 = VectorNormalize(VectorSub(room->polygons[j].vertices[0], room->polygons[j].vertices[1]));
- v2 = VectorCross(v1, room->polygons[j].normal);
+ d = VectorDot(room->polygons[j].normal, VectorSub(room->polygons[j].vertices[0], lights[i].pos));
- for(k = 0; k < 3; k++) {
- v = VectorSub(room->polygons[j].vertices[k], p);
+ if(d < 0) {
+ 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);
- glTexCoord2f(VectorDot(v, v1)*0.04 / d + 0.5, VectorDot(v, v2)*0.04 / d + 0.5);
- glVertex3fv((GLfloat*)&room->polygons[j].vertices[k]);
+ for(k = 0; k < 3; k++) {
+ v = VectorSub(room->polygons[j].vertices[k], p);
+
+ 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]);
+ }
}
+
+ glEnd();
}
-
- 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();
+ //ApplyLightScale();
/*glPushMatrix();
glDisable(GL_TEXTURE_2D);
diff --git a/zoom/light.h b/zoom/light.h
index 06d6756..8194081 100644
--- a/zoom/light.h
+++ b/zoom/light.h
@@ -18,6 +18,5 @@ typedef struct _LIGHT {
void SetAmbient(COLOR);
void AddLight(LIGHT);
void ResetLights();
-void ApplyLightScale();
#endif