From e43bceafaba72d34dfbea1deecd56c2f694d704a Mon Sep 17 00:00:00 2001 From: neoraider Date: Tue, 24 Oct 2006 15:04:02 +0000 Subject: Beleuchtung und Rendering ge?ndert, um Schatten zu erm?glichen. --- level.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 15 deletions(-) (limited to 'level.c') diff --git a/level.c b/level.c index f8c1fda..e7b8343 100644 --- a/level.c +++ b/level.c @@ -6,12 +6,14 @@ #include #include #include +#include extern GLuint sphere; extern GLuint meditex_blue; extern float objrot; -extern LIGHT light; +extern LIGHT *lights; +extern int nLights; int LoadLevel(char *filename, LEVEL *level) { FILE *file; @@ -68,8 +70,33 @@ int LoadLevel(char *filename, LEVEL *level) { return 1; } -void DrawRoom(LEVEL *level, int nr) { +POLYGON_LIST *DrawRoom(LEVEL *level, int nr) { + ROOM room = level->rooms[nr]; + POLYGON_LIST *p; int i; + + p = malloc(sizeof(POLYGON_LIST)+sizeof(POLYGON)*room.nWalls); + p->nPolygons = room.nWalls; + + for(i = 0; i < room.nWalls; i++) { + p->polygons[i].vertices[0] = room.walls[i].vertices[0]; + p->polygons[i].vertices[1] = room.walls[i].vertices[1]; + p->polygons[i].vertices[2] = room.walls[i].vertices[2]; + + p->polygons[i].normal = room.walls[i].normal; + + p->polygons[i].texture = level->textures[room.walls[i].texture]; + + p->polygons[i].texcoords[0] = room.walls[i].texcoords[0]; + p->polygons[i].texcoords[1] = room.walls[i].texcoords[1]; + p->polygons[i].texcoords[2] = room.walls[i].texcoords[2]; + } + + return p; +} + +/*void DrawRoom(LEVEL *level, int nr) { + int i, j; int r, g; GLfloat std_emission[] = {0.0, 0.0, 0.0, 1.0}; GLfloat medipak100_emission[] = {1.0, 0.0, 0.0, 1.0}; @@ -80,15 +107,31 @@ void DrawRoom(LEVEL *level, int nr) { float s, t, d; MATRIX transform; + for(i = 0; i < room.nWalls; i++) - RenderWall(room.walls[i], level->textures); + RenderWallDepth(room.walls[i]); + + for(i = 0; i < nLights; i++) { + glClear(GL_COLOR_BUFFER_BIT); + for(j = 0; j < room.nWalls; j++) + RenderWallLight(room.walls[j], lights[i]); + + glAccum(GL_ACCUM, 1.0/(nLights+1)); + } + + glAccum(GL_RETURN, 1.0); + + //for(i = 0; i < room.nWalls; i++) + // RenderWall(room.walls[i], level->textures); + + glColor3f(1.0/(nLights+1), 1.0/(nLights+1), 1.0/(nLights+1)); for(i = 0; i < room.nThings; i++) { if(!room.things[i].visible) continue; switch(room.things[i].type) { case THING_MEDIPAK100: glPushMatrix(); - //glBindTexture(GL_TEXTURE_2D, meditex_blue); + glBindTexture(GL_TEXTURE_2D, meditex_blue); glMaterialfv(GL_FRONT, GL_EMISSION, medipak100_emission); glTranslatef(room.things[i].pos.x, room.things[i].pos.y, room.things[i].pos.z); glRotatef(objrot*10, 0.0, 1.0, 0.0); @@ -101,7 +144,7 @@ void DrawRoom(LEVEL *level, int nr) { for(i = 0; i < room.nGates; i++) { if(room.gateinfo[i].state == STATE_CLOSED) { - //glBindTexture(GL_TEXTURE_2D, level->textures[room.gates[i].walls[0].texture]); + glBindTexture(GL_TEXTURE_2D, level->textures[room.gates[i].walls[0].texture]); glBegin(GL_TRIANGLES); @@ -115,7 +158,7 @@ void DrawRoom(LEVEL *level, int nr) { glEnd(); - //glBindTexture(GL_TEXTURE_2D, level->textures[room.gates[i].walls[0].texture]); + glBindTexture(GL_TEXTURE_2D, level->textures[room.gates[i].walls[0].texture]); glBegin(GL_TRIANGLES); @@ -150,7 +193,7 @@ void DrawRoom(LEVEL *level, int nr) { + t1.texcoords[2].t * (1 - room.gateinfo[i].timer/1000.0); t2.texcoords[0] = t1.texcoords[0]; - //glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]); + glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]); glBegin(GL_TRIANGLES); @@ -164,7 +207,7 @@ void DrawRoom(LEVEL *level, int nr) { glEnd(); - //glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]); + glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]); glBegin(GL_TRIANGLES); @@ -194,7 +237,7 @@ void DrawRoom(LEVEL *level, int nr) { glPushMatrix(); transform = VectorMatrix(p1, v1, p2, v2); glMultMatrixf(transform.f); - DrawRoom(level, r); + //DrawRoom(level, r); glPopMatrix(); } else if(room.gateinfo[i].state == STATE_CLOSING) { @@ -218,7 +261,7 @@ void DrawRoom(LEVEL *level, int nr) { + t1.texcoords[2].t * room.gateinfo[i].timer/1000.0; t2.texcoords[0] = t1.texcoords[0]; - //glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]); + glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]); glBegin(GL_TRIANGLES); @@ -232,7 +275,7 @@ void DrawRoom(LEVEL *level, int nr) { glEnd(); - //glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]); + glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]); glBegin(GL_TRIANGLES); @@ -262,7 +305,7 @@ void DrawRoom(LEVEL *level, int nr) { glPushMatrix(); transform = VectorMatrix(p1, v1, p2, v2); glMultMatrixf(transform.f); - DrawRoom(level, r); + //DrawRoom(level, r); glPopMatrix(); } else { @@ -282,11 +325,11 @@ void DrawRoom(LEVEL *level, int nr) { glPushMatrix(); transform = VectorMatrix(p1, v1, p2, v2); glMultMatrixf(transform.f); - DrawRoom(level, r); + //DrawRoom(level, r); glPopMatrix(); } } -} +}*/ void FreeLevel(LEVEL *level) { int i; @@ -295,7 +338,10 @@ void FreeLevel(LEVEL *level) { for(i = 0; i < level->nRooms; i++) { if(level->rooms[i].nWalls) free(level->rooms[i].walls); if(level->rooms[i].nThings) free(level->rooms[i].things); - if(level->rooms[i].nGates) free(level->rooms[i].gates); + if(level->rooms[i].nGates) { + free(level->rooms[i].gates); + free(level->rooms[i].gateinfo); + } } free(level->rooms); } -- cgit v1.2.3