Beleuchtung und Rendering ge?ndert, um Schatten zu erm?glichen.

This commit is contained in:
neoraider 2006-10-24 15:04:02 +00:00
parent 79801b6b79
commit e43bceafab
12 changed files with 340 additions and 145 deletions

View file

@ -1,5 +1,5 @@
lib_LTLIBRARIES = libzoom.la lib_LTLIBRARIES = libzoom.la
libzoom_la_SOURCES = init.c level.c player.c render.c texture.c libzoom_la_SOURCES = init.c level.c player.c render.c texture.c light.c
libzoom_la_CFLAGS = @GL_CFLAGS@ @GLU_CFLAGS@ libzoom_la_CFLAGS = @GL_CFLAGS@ @GLU_CFLAGS@
libzoom_la_LIBADD = @GL_LIBS@ @GLU_LIBS@ libzoom_la_LIBADD = @GL_LIBS@ @GLU_LIBS@
nobase_include_HEADERS = zoom/types.h zoom/init.h zoom/level.h zoom/player.h zoom/render.h zoom/texture.h nobase_include_HEADERS = zoom/types.h zoom/init.h zoom/level.h zoom/player.h zoom/render.h zoom/texture.h zoom/light.h

View file

@ -69,6 +69,7 @@ GLU_CFLAGS = @GLU_CFLAGS@
GLU_LIBS = @GLU_LIBS@ GLU_LIBS = @GLU_LIBS@
GL_CFLAGS = @GL_CFLAGS@ GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@ GL_LIBS = @GL_LIBS@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -99,12 +100,10 @@ SET_MAKE = @SET_MAKE@
SHELL = @SHELL@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_AR = @ac_ct_AR@ XMKMF = @XMKMF@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@ ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@ ac_ct_F77 = @ac_ct_F77@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
acx_pthread_config = @acx_pthread_config@ acx_pthread_config = @acx_pthread_config@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
@ -120,31 +119,38 @@ build_cpu = @build_cpu@
build_os = @build_os@ build_os = @build_os@
build_vendor = @build_vendor@ build_vendor = @build_vendor@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host = @host@ host = @host@
host_alias = @host_alias@ host_alias = @host_alias@
host_cpu = @host_cpu@ host_cpu = @host_cpu@
host_os = @host_os@ host_os = @host_os@
host_vendor = @host_vendor@ host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@
target_alias = @target_alias@ target_alias = @target_alias@
lib_LTLIBRARIES = libzoom.la lib_LTLIBRARIES = libzoom.la
libzoom_la_SOURCES = init.c level.c player.c render.c texture.c libzoom_la_SOURCES = init.c level.c player.c render.c texture.c light.c
libzoom_la_CFLAGS = @GL_CFLAGS@ @GLU_CFLAGS@ libzoom_la_CFLAGS = @GL_CFLAGS@ @GLU_CFLAGS@
libzoom_la_LIBADD = @GL_LIBS@ @GLU_LIBS@ libzoom_la_LIBADD = @GL_LIBS@ @GLU_LIBS@
nobase_include_HEADERS = zoom/types.h zoom/init.h zoom/level.h zoom/player.h zoom/render.h zoom/texture.h nobase_include_HEADERS = zoom/types.h zoom/init.h zoom/level.h zoom/player.h zoom/render.h zoom/texture.h zoom/light.h
subdir = . subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@ -155,7 +161,8 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
libzoom_la_LDFLAGS = libzoom_la_LDFLAGS =
libzoom_la_DEPENDENCIES = libzoom_la_DEPENDENCIES =
am_libzoom_la_OBJECTS = libzoom_la-init.lo libzoom_la-level.lo \ am_libzoom_la_OBJECTS = libzoom_la-init.lo libzoom_la-level.lo \
libzoom_la-player.lo libzoom_la-render.lo libzoom_la-texture.lo libzoom_la-player.lo libzoom_la-render.lo libzoom_la-texture.lo \
libzoom_la-light.lo
libzoom_la_OBJECTS = $(am_libzoom_la_OBJECTS) libzoom_la_OBJECTS = $(am_libzoom_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I. DEFAULT_INCLUDES = -I. -I$(srcdir) -I.
@ -163,6 +170,7 @@ depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/libzoom_la-init.Plo \ @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/libzoom_la-init.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/libzoom_la-level.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/libzoom_la-level.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/libzoom_la-light.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/libzoom_la-player.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/libzoom_la-player.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/libzoom_la-render.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/libzoom_la-render.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/libzoom_la-texture.Plo @AMDEP_TRUE@ ./$(DEPDIR)/libzoom_la-texture.Plo
@ -260,6 +268,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-init.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-init.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-level.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-level.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-light.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-player.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-player.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-render.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-render.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-texture.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libzoom_la-texture.Plo@am__quote@
@ -462,6 +471,39 @@ libzoom_la-texture.lo: texture.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libzoom_la_CFLAGS) $(CFLAGS) -c -o libzoom_la-texture.lo `test -f 'texture.c' || echo '$(srcdir)/'`texture.c @am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libzoom_la_CFLAGS) $(CFLAGS) -c -o libzoom_la-texture.lo `test -f 'texture.c' || echo '$(srcdir)/'`texture.c
libzoom_la-light.o: light.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libzoom_la_CFLAGS) $(CFLAGS) -MT libzoom_la-light.o -MD -MP -MF "$(DEPDIR)/libzoom_la-light.Tpo" \
@am__fastdepCC_TRUE@ -c -o libzoom_la-light.o `test -f 'light.c' || echo '$(srcdir)/'`light.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libzoom_la-light.Tpo" "$(DEPDIR)/libzoom_la-light.Po"; \
@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/libzoom_la-light.Tpo"; exit 1; \
@am__fastdepCC_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='light.c' object='libzoom_la-light.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/libzoom_la-light.Po' tmpdepfile='$(DEPDIR)/libzoom_la-light.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libzoom_la_CFLAGS) $(CFLAGS) -c -o libzoom_la-light.o `test -f 'light.c' || echo '$(srcdir)/'`light.c
libzoom_la-light.obj: light.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libzoom_la_CFLAGS) $(CFLAGS) -MT libzoom_la-light.obj -MD -MP -MF "$(DEPDIR)/libzoom_la-light.Tpo" \
@am__fastdepCC_TRUE@ -c -o libzoom_la-light.obj `if test -f 'light.c'; then $(CYGPATH_W) 'light.c'; else $(CYGPATH_W) '$(srcdir)/light.c'; fi`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libzoom_la-light.Tpo" "$(DEPDIR)/libzoom_la-light.Po"; \
@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/libzoom_la-light.Tpo"; exit 1; \
@am__fastdepCC_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='light.c' object='libzoom_la-light.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/libzoom_la-light.Po' tmpdepfile='$(DEPDIR)/libzoom_la-light.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libzoom_la_CFLAGS) $(CFLAGS) -c -o libzoom_la-light.obj `if test -f 'light.c'; then $(CYGPATH_W) 'light.c'; else $(CYGPATH_W) '$(srcdir)/light.c'; fi`
libzoom_la-light.lo: light.c
@am__fastdepCC_TRUE@ if $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libzoom_la_CFLAGS) $(CFLAGS) -MT libzoom_la-light.lo -MD -MP -MF "$(DEPDIR)/libzoom_la-light.Tpo" \
@am__fastdepCC_TRUE@ -c -o libzoom_la-light.lo `test -f 'light.c' || echo '$(srcdir)/'`light.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libzoom_la-light.Tpo" "$(DEPDIR)/libzoom_la-light.Plo"; \
@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/libzoom_la-light.Tpo"; exit 1; \
@am__fastdepCC_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='light.c' object='libzoom_la-light.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/libzoom_la-light.Plo' tmpdepfile='$(DEPDIR)/libzoom_la-light.TPlo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libzoom_la_CFLAGS) $(CFLAGS) -c -o libzoom_la-light.lo `test -f 'light.c' || echo '$(srcdir)/'`light.c
mostlyclean-libtool: mostlyclean-libtool:
-rm -f *.lo -rm -f *.lo

33
init.c
View file

@ -4,16 +4,21 @@
#include <zoom/init.h> #include <zoom/init.h>
#include <zoom/texture.h> #include <zoom/texture.h>
#include <zoom/level.h> #include <zoom/level.h>
#include <zoom/light.h>
LEVEL level; LEVEL level;
GLuint sphere; GLuint sphere;
GLuint meditex_blue; GLuint meditex_blue;
LIGHT light = {LIGHT_POINT, {1.0, 1.0, 1.0}, {0.0, 0.0, 0.0}}; GLuint lightmap;
extern TEXLIST *texlist; extern TEXLIST *texlist;
int InitGame() { int InitGame() {
//GLfloat mat_ambient_and_diffuse[] = { 0.5, 0.5, 0.5, 1.0}; LIGHT light = {LIGHT_POINT, {30.0, 30.0, 30.0}, {0.0, 0.0, 0.0}};
COLOR ambient = {0.1, 0.1, 0.1};
glViewport(0, 0, 640, 480); glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
@ -24,7 +29,6 @@ int InitGame() {
glLoadIdentity(); glLoadIdentity();
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(1.0); glClearDepth(1.0);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
@ -34,28 +38,23 @@ int InitGame() {
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
//glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_and_diffuse);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
SetAmbient(ambient);
AddLight(light);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
meditex_blue = LoadTexture("medib.tex"); meditex_blue = LoadTexture("medib.tex");
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, LoadTexture("lightmap.tex"));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); lightmap = LoadTexture("lightmap.tex");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glActiveTexture(GL_TEXTURE1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
GLUquadricObj *quadric = gluNewQuadric(); GLUquadricObj *quadric = gluNewQuadric();
gluQuadricDrawStyle(quadric, GLU_FILL); gluQuadricDrawStyle(quadric, GLU_FILL);
gluQuadricTexture(quadric, GL_TRUE); gluQuadricTexture(quadric, GL_TRUE);

76
level.c
View file

@ -6,12 +6,14 @@
#include <zoom/types.h> #include <zoom/types.h>
#include <zoom/texture.h> #include <zoom/texture.h>
#include <zoom/level.h> #include <zoom/level.h>
#include <zoom/light.h>
extern GLuint sphere; extern GLuint sphere;
extern GLuint meditex_blue; extern GLuint meditex_blue;
extern float objrot; extern float objrot;
extern LIGHT light; extern LIGHT *lights;
extern int nLights;
int LoadLevel(char *filename, LEVEL *level) { int LoadLevel(char *filename, LEVEL *level) {
FILE *file; FILE *file;
@ -68,8 +70,33 @@ int LoadLevel(char *filename, LEVEL *level) {
return 1; 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; 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; int r, g;
GLfloat std_emission[] = {0.0, 0.0, 0.0, 1.0}; GLfloat std_emission[] = {0.0, 0.0, 0.0, 1.0};
GLfloat medipak100_emission[] = {1.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; float s, t, d;
MATRIX transform; MATRIX transform;
for(i = 0; i < room.nWalls; i++) 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++) { for(i = 0; i < room.nThings; i++) {
if(!room.things[i].visible) continue; if(!room.things[i].visible) continue;
switch(room.things[i].type) { switch(room.things[i].type) {
case THING_MEDIPAK100: case THING_MEDIPAK100:
glPushMatrix(); glPushMatrix();
//glBindTexture(GL_TEXTURE_2D, meditex_blue); glBindTexture(GL_TEXTURE_2D, meditex_blue);
glMaterialfv(GL_FRONT, GL_EMISSION, medipak100_emission); glMaterialfv(GL_FRONT, GL_EMISSION, medipak100_emission);
glTranslatef(room.things[i].pos.x, room.things[i].pos.y, room.things[i].pos.z); 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); 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++) { for(i = 0; i < room.nGates; i++) {
if(room.gateinfo[i].state == STATE_CLOSED) { 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); glBegin(GL_TRIANGLES);
@ -115,7 +158,7 @@ void DrawRoom(LEVEL *level, int nr) {
glEnd(); 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); glBegin(GL_TRIANGLES);
@ -150,7 +193,7 @@ void DrawRoom(LEVEL *level, int nr) {
+ t1.texcoords[2].t * (1 - room.gateinfo[i].timer/1000.0); + t1.texcoords[2].t * (1 - room.gateinfo[i].timer/1000.0);
t2.texcoords[0] = t1.texcoords[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); glBegin(GL_TRIANGLES);
@ -164,7 +207,7 @@ void DrawRoom(LEVEL *level, int nr) {
glEnd(); glEnd();
//glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]); glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
@ -194,7 +237,7 @@ void DrawRoom(LEVEL *level, int nr) {
glPushMatrix(); glPushMatrix();
transform = VectorMatrix(p1, v1, p2, v2); transform = VectorMatrix(p1, v1, p2, v2);
glMultMatrixf(transform.f); glMultMatrixf(transform.f);
DrawRoom(level, r); //DrawRoom(level, r);
glPopMatrix(); glPopMatrix();
} }
else if(room.gateinfo[i].state == STATE_CLOSING) { 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; + t1.texcoords[2].t * room.gateinfo[i].timer/1000.0;
t2.texcoords[0] = t1.texcoords[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); glBegin(GL_TRIANGLES);
@ -232,7 +275,7 @@ void DrawRoom(LEVEL *level, int nr) {
glEnd(); glEnd();
//glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]); glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
@ -262,7 +305,7 @@ void DrawRoom(LEVEL *level, int nr) {
glPushMatrix(); glPushMatrix();
transform = VectorMatrix(p1, v1, p2, v2); transform = VectorMatrix(p1, v1, p2, v2);
glMultMatrixf(transform.f); glMultMatrixf(transform.f);
DrawRoom(level, r); //DrawRoom(level, r);
glPopMatrix(); glPopMatrix();
} }
else { else {
@ -282,11 +325,11 @@ void DrawRoom(LEVEL *level, int nr) {
glPushMatrix(); glPushMatrix();
transform = VectorMatrix(p1, v1, p2, v2); transform = VectorMatrix(p1, v1, p2, v2);
glMultMatrixf(transform.f); glMultMatrixf(transform.f);
DrawRoom(level, r); //DrawRoom(level, r);
glPopMatrix(); glPopMatrix();
} }
} }
} }*/
void FreeLevel(LEVEL *level) { void FreeLevel(LEVEL *level) {
int i; int i;
@ -295,7 +338,10 @@ void FreeLevel(LEVEL *level) {
for(i = 0; i < level->nRooms; i++) { for(i = 0; i < level->nRooms; i++) {
if(level->rooms[i].nWalls) free(level->rooms[i].walls); if(level->rooms[i].nWalls) free(level->rooms[i].walls);
if(level->rooms[i].nThings) free(level->rooms[i].things); 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); free(level->rooms);
} }

45
light.c Normal file
View file

@ -0,0 +1,45 @@
#include <stdlib.h>
#include <zoom/light.h>
#include <GL/gl.h>
int nLights = 0;
LIGHT *lights;
static 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) {
if(nLights == 0)
lights = malloc(sizeof(LIGHT));
else
lights = realloc(lights, sizeof(LIGHT)*(nLights+1));
lights[nLights] = light;
nLights++;
UpdateAmbient();
}
void ResetLights() {
if(nLights > 0) {
free(lights);
nLights = 0;
UpdateAmbient();
}
}
void ApplyLightScale() {
glAccum(GL_LOAD, 1);
glAccum(GL_RETURN, nLights+1);
}

View file

@ -2,6 +2,7 @@
#include <math.h> #include <math.h>
#include <zoom/player.h> #include <zoom/player.h>
#include <zoom/level.h> #include <zoom/level.h>
#include <zoom/light.h>
#include <neofx/collision.h> #include <neofx/collision.h>
#include <neofx/math.h> #include <neofx/math.h>
@ -20,7 +21,8 @@ float rotxspeed = 0, rotyspeed = 0;
float objrot = 0; float objrot = 0;
extern LEVEL level; extern LEVEL level;
extern LIGHT light; extern int nLights;
extern LIGHT *lights;
void MouseInput(int x, int y) { void MouseInput(int x, int y) {
roty += x * 0.3; roty += x * 0.3;
@ -223,28 +225,28 @@ void DoInput(int delta) {
else i = 24000 - lightpos; else i = 24000 - lightpos;
if(i == 0) { if(i == 0) {
light.pos.x = 0.0; lights[0].pos.x = 0.0;
light.pos.y = 0.0; lights[0].pos.y = 0.0;
light.pos.z = 0.0; lights[0].pos.z = 0.0;
} }
else if(i < 4000) { else if(i < 4000) {
light.pos.x = 0.0; lights[0].pos.x = 0.0;
light.pos.y = 0.0; lights[0].pos.y = 0.0;
light.pos.z = -i * 0.001; lights[0].pos.z = -i * 0.001;
} }
else if(i < 8000) { else if(i < 8000) {
light.pos.x = (i-4000) * 0.001; lights[0].pos.x = (i-4000) * 0.001;
light.pos.y = 0.0; lights[0].pos.y = 0.0;
light.pos.z = -4.0; lights[0].pos.z = -4.0;
} }
else if(i < 12000) { else if(i < 12000) {
light.pos.x = 4.0; lights[0].pos.x = 4.0;
light.pos.y = 0.0; lights[0].pos.y = 0.0;
light.pos.z = -4.0 - (i-8000) * 0.001; lights[0].pos.z = -4.0 - (i-8000) * 0.001;
} }
else { else {
light.pos.x = 4.0; lights[0].pos.x = 4.0;
light.pos.y = 0.0; lights[0].pos.y = 0.0;
light.pos.z = -8.0; lights[0].pos.z = -8.0;
} }
} }

173
render.c
View file

@ -1,69 +1,22 @@
#include <GL/gl.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <zoom/render.h> #include <GL/gl.h>
#include <zoom/player.h>
#include <zoom/level.h>
#include <zoom/texture.h>
#include <neofx/math.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 PLAYER player;
extern LEVEL level; extern LEVEL level;
extern GLuint sphere; 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() { 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}; GLfloat std_emission[] = {0.0, 0.0, 0.0, 1.0};
MATRIX rotate = { MATRIX rotate = {
player.rotycos, 0.0, -player.rotysin, 0.0, player.rotycos, 0.0, -player.rotysin, 0.0,
@ -71,10 +24,14 @@ void Render() {
player.rotysin, 0.0, player.rotycos, 0.0, player.rotysin, 0.0, player.rotycos, 0.0,
0.0, 0.0, 0.0, 1.0 0.0, 0.0, 0.0, 1.0
}; };
COLOR color_light = {1.0, 1.0, 1.0}; POLYGON_LIST *room;
COLOR color_ambient = {0.1, 0.1, 0.1}; int i, j, k;
float d;
VECTOR v, v1, v2;
VERTEX p;
COLOR c;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); glLoadIdentity();
glRotatef(player.rotx, 1.0, 0.0, 0.0); 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); glTranslatef(-player.pos.x, -player.pos.y, -player.pos.z);
//glLightfv(GL_LIGHT0, GL_POSITION, light_position); room = DrawRoom(&level, player.room);
glPushMatrix();
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); glDisable(GL_TEXTURE_2D);
glColor3fv((GLfloat*)&color_light); glColor3f(1.0, 1.0, 1.0);
//glMaterialfv(GL_FRONT, GL_EMISSION, light_emission); glTranslatef(lights[0].pos.x, lights[0].pos.y, lights[0].pos.z);
glTranslatef(light.pos.x, light.pos.y, light.pos.z);
glScalef(0.1, 0.1, 0.1); glScalef(0.1, 0.1, 0.1);
glCallList(sphere); glCallList(sphere);
//glMaterialfv(GL_FRONT, GL_EMISSION, std_emission);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glPopMatrix(); glPopMatrix();*/
glColor3fv((GLfloat*)&color_ambient);
DrawRoom(&level, player.room);
glFlush(); glFlush();
} }

View file

@ -52,8 +52,8 @@ GLuint LoadTexture(char *filename) {
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 4, txh.w, txh.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); glTexImage2D(GL_TEXTURE_2D, 0, 4, txh.w, txh.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
free(data); free(data);

View file

@ -3,6 +3,7 @@
#include <GL/gl.h> #include <GL/gl.h>
#include <zoom/types.h> #include <zoom/types.h>
#include <zoom/render.h>
#pragma pack(push, 2) #pragma pack(push, 2)
typedef struct _LEVELHEADER { typedef struct _LEVELHEADER {
@ -40,9 +41,23 @@ typedef struct _LEVEL {
} LEVEL; } LEVEL;
#pragma pack(pop) #pragma pack(pop)
typedef struct _POLYGON {
VERTEX vertices[3];
VECTOR normal;
GLuint texture;
TEXCOORDS texcoords[3];
} POLYGON;
typedef struct _POLYGON_LIST {
int nPolygons;
POLYGON polygons[0];
} POLYGON_LIST;
int LoadLevel(char *, LEVEL *); int LoadLevel(char *, LEVEL *);
void DrawRoom(LEVEL *, int); POLYGON_LIST *DrawRoom(LEVEL *, int);
void FreeLevel(LEVEL *); void FreeLevel(LEVEL *);
#endif #endif

23
zoom/light.h Normal file
View file

@ -0,0 +1,23 @@
#ifndef ZOOM_LIGHT_H
#define ZOOM_LIGHT_H
#include <zoom/types.h>
#define LIGHT_UNKNOWN 0
#define LIGHT_POINT 1
#define LIGHT_DIRECTIONAL 2
#define LIGHT_SPOT 3
typedef struct _LIGHT {
unsigned char type;
COLOR diffuse;
VERTEX pos;
} LIGHT;
void SetAmbient(COLOR);
void AddLight(LIGHT);
void ResetLights();
void ApplyLightScale();
#endif

View file

@ -1,6 +1,13 @@
#ifndef ZOOM_RENDER_H #ifndef ZOOM_RENDER_H
#define ZOOM_RENDER_H #define ZOOM_RENDER_H
#include <zoom/types.h>
#include <zoom/light.h>
#include <GL/gl.h>
void Render(); void Render();
void RenderWall(WALL, GLuint*);
void RenderWallLight(WALL, LIGHT);
#endif #endif

View file

@ -7,11 +7,6 @@
#define TRIANGLE_WALL 1 #define TRIANGLE_WALL 1
#define TRIANGLE_FLOOR 2 #define TRIANGLE_FLOOR 2
#define LIGHT_UNKNOWN 0
#define LIGHT_POINT 1
#define LIGHT_DIRECTIONAL 2
#define LIGHT_SPOT 3
#define THING_UNKNOWN 0 #define THING_UNKNOWN 0
#define THING_MEDIPAK25 1 #define THING_MEDIPAK25 1
#define THING_MEDIPAK50 2 #define THING_MEDIPAK50 2
@ -41,16 +36,6 @@ typedef struct WALL {
TEXCOORDS texcoords[3]; TEXCOORDS texcoords[3];
} WALL; } WALL;
typedef struct _COLOR {
float r, g, b;
} COLOR;
typedef struct _LIGHT {
unsigned char type;
COLOR diffuse;
VERTEX pos;
} LIGHT;
typedef struct _THING { typedef struct _THING {
unsigned char type; unsigned char type;
unsigned char visible; unsigned char visible;