Beleuchtung und Rendering ge?ndert, um Schatten zu erm?glichen.
This commit is contained in:
parent
79801b6b79
commit
e43bceafab
12 changed files with 340 additions and 145 deletions
|
@ -1,5 +1,5 @@
|
|||
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_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
|
||||
|
|
54
Makefile.in
54
Makefile.in
|
@ -69,6 +69,7 @@ GLU_CFLAGS = @GLU_CFLAGS@
|
|||
GLU_LIBS = @GLU_LIBS@
|
||||
GL_CFLAGS = @GL_CFLAGS@
|
||||
GL_LIBS = @GL_LIBS@
|
||||
GREP = @GREP@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
|
@ -99,12 +100,10 @@ SET_MAKE = @SET_MAKE@
|
|||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
ac_ct_AR = @ac_ct_AR@
|
||||
XMKMF = @XMKMF@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_F77 = @ac_ct_F77@
|
||||
ac_ct_RANLIB = @ac_ct_RANLIB@
|
||||
ac_ct_STRIP = @ac_ct_STRIP@
|
||||
acx_pthread_config = @acx_pthread_config@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
|
@ -120,31 +119,38 @@ build_cpu = @build_cpu@
|
|||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
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_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 = .
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
|
@ -155,7 +161,8 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
|
|||
libzoom_la_LDFLAGS =
|
||||
libzoom_la_DEPENDENCIES =
|
||||
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)
|
||||
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I.
|
||||
|
@ -163,6 +170,7 @@ depcomp = $(SHELL) $(top_srcdir)/depcomp
|
|||
am__depfiles_maybe = depfiles
|
||||
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/libzoom_la-init.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-render.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-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-render.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@
|
||||
@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:
|
||||
-rm -f *.lo
|
||||
|
||||
|
|
33
init.c
33
init.c
|
@ -4,16 +4,21 @@
|
|||
#include <zoom/init.h>
|
||||
#include <zoom/texture.h>
|
||||
#include <zoom/level.h>
|
||||
#include <zoom/light.h>
|
||||
|
||||
LEVEL level;
|
||||
GLuint sphere;
|
||||
GLuint meditex_blue;
|
||||
LIGHT light = {LIGHT_POINT, {1.0, 1.0, 1.0}, {0.0, 0.0, 0.0}};
|
||||
GLuint lightmap;
|
||||
|
||||
|
||||
extern TEXLIST *texlist;
|
||||
|
||||
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);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
@ -24,7 +29,6 @@ int InitGame() {
|
|||
glLoadIdentity();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClearDepth(1.0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
@ -34,28 +38,23 @@ int InitGame() {
|
|||
glEnable(GL_CULL_FACE);
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
//glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_and_diffuse);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
//glEnable(GL_LIGHT0);
|
||||
|
||||
SetAmbient(ambient);
|
||||
AddLight(light);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
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);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
|
||||
|
||||
lightmap = LoadTexture("lightmap.tex");
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 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();
|
||||
gluQuadricDrawStyle(quadric, GLU_FILL);
|
||||
gluQuadricTexture(quadric, GL_TRUE);
|
||||
|
|
76
level.c
76
level.c
|
@ -6,12 +6,14 @@
|
|||
#include <zoom/types.h>
|
||||
#include <zoom/texture.h>
|
||||
#include <zoom/level.h>
|
||||
#include <zoom/light.h>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
45
light.c
Normal file
45
light.c
Normal 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);
|
||||
}
|
34
player.c
34
player.c
|
@ -2,6 +2,7 @@
|
|||
#include <math.h>
|
||||
#include <zoom/player.h>
|
||||
#include <zoom/level.h>
|
||||
#include <zoom/light.h>
|
||||
#include <neofx/collision.h>
|
||||
#include <neofx/math.h>
|
||||
|
||||
|
@ -20,7 +21,8 @@ float rotxspeed = 0, rotyspeed = 0;
|
|||
float objrot = 0;
|
||||
|
||||
extern LEVEL level;
|
||||
extern LIGHT light;
|
||||
extern int nLights;
|
||||
extern LIGHT *lights;
|
||||
|
||||
void MouseInput(int x, int y) {
|
||||
roty += x * 0.3;
|
||||
|
@ -223,28 +225,28 @@ void DoInput(int delta) {
|
|||
else i = 24000 - lightpos;
|
||||
|
||||
if(i == 0) {
|
||||
light.pos.x = 0.0;
|
||||
light.pos.y = 0.0;
|
||||
light.pos.z = 0.0;
|
||||
lights[0].pos.x = 0.0;
|
||||
lights[0].pos.y = 0.0;
|
||||
lights[0].pos.z = 0.0;
|
||||
}
|
||||
else if(i < 4000) {
|
||||
light.pos.x = 0.0;
|
||||
light.pos.y = 0.0;
|
||||
light.pos.z = -i * 0.001;
|
||||
lights[0].pos.x = 0.0;
|
||||
lights[0].pos.y = 0.0;
|
||||
lights[0].pos.z = -i * 0.001;
|
||||
}
|
||||
else if(i < 8000) {
|
||||
light.pos.x = (i-4000) * 0.001;
|
||||
light.pos.y = 0.0;
|
||||
light.pos.z = -4.0;
|
||||
lights[0].pos.x = (i-4000) * 0.001;
|
||||
lights[0].pos.y = 0.0;
|
||||
lights[0].pos.z = -4.0;
|
||||
}
|
||||
else if(i < 12000) {
|
||||
light.pos.x = 4.0;
|
||||
light.pos.y = 0.0;
|
||||
light.pos.z = -4.0 - (i-8000) * 0.001;
|
||||
lights[0].pos.x = 4.0;
|
||||
lights[0].pos.y = 0.0;
|
||||
lights[0].pos.z = -4.0 - (i-8000) * 0.001;
|
||||
}
|
||||
else {
|
||||
light.pos.x = 4.0;
|
||||
light.pos.y = 0.0;
|
||||
light.pos.z = -8.0;
|
||||
lights[0].pos.x = 4.0;
|
||||
lights[0].pos.y = 0.0;
|
||||
lights[0].pos.z = -8.0;
|
||||
}
|
||||
}
|
||||
|
|
173
render.c
173
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();
|
||||
}
|
||||
|
|
|
@ -52,8 +52,8 @@ GLuint LoadTexture(char *filename) {
|
|||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
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_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
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);
|
||||
|
||||
free(data);
|
||||
|
|
17
zoom/level.h
17
zoom/level.h
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <GL/gl.h>
|
||||
#include <zoom/types.h>
|
||||
#include <zoom/render.h>
|
||||
|
||||
#pragma pack(push, 2)
|
||||
typedef struct _LEVELHEADER {
|
||||
|
@ -40,9 +41,23 @@ typedef struct _LEVEL {
|
|||
} LEVEL;
|
||||
#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 *);
|
||||
void DrawRoom(LEVEL *, int);
|
||||
POLYGON_LIST *DrawRoom(LEVEL *, int);
|
||||
void FreeLevel(LEVEL *);
|
||||
|
||||
#endif
|
||||
|
|
23
zoom/light.h
Normal file
23
zoom/light.h
Normal 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
|
|
@ -1,6 +1,13 @@
|
|||
#ifndef ZOOM_RENDER_H
|
||||
#define ZOOM_RENDER_H
|
||||
|
||||
#include <zoom/types.h>
|
||||
#include <zoom/light.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
|
||||
void Render();
|
||||
void RenderWall(WALL, GLuint*);
|
||||
void RenderWallLight(WALL, LIGHT);
|
||||
|
||||
#endif
|
||||
|
|
15
zoom/types.h
15
zoom/types.h
|
@ -7,11 +7,6 @@
|
|||
#define TRIANGLE_WALL 1
|
||||
#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_MEDIPAK25 1
|
||||
#define THING_MEDIPAK50 2
|
||||
|
@ -41,16 +36,6 @@ typedef struct WALL {
|
|||
TEXCOORDS texcoords[3];
|
||||
} WALL;
|
||||
|
||||
typedef struct _COLOR {
|
||||
float r, g, b;
|
||||
} COLOR;
|
||||
|
||||
typedef struct _LIGHT {
|
||||
unsigned char type;
|
||||
COLOR diffuse;
|
||||
VERTEX pos;
|
||||
} LIGHT;
|
||||
|
||||
typedef struct _THING {
|
||||
unsigned char type;
|
||||
unsigned char visible;
|
||||
|
|
Reference in a new issue