# HG changeset patch # User John Tsiombikas # Date 1322544169 -7200 # Node ID be61704c4cc85d26316c4de9f2db67f6cf7832ea # Parent 7b574ba5758e31756c140784a5b5f96091de45e5 added initial firstp diff -r 7b574ba5758e -r be61704c4cc8 Makefile --- a/Makefile Mon Nov 28 05:12:33 2011 +0200 +++ b/Makefile Tue Nov 29 07:22:49 2011 +0200 @@ -1,6 +1,7 @@ obj = src/test.o \ src/mingl.o src/mglrast.o src/mglgen.o \ src/texture.o src/palman.o \ + src/scene.o src/cvec.o \ dosemu/dosemu.o dep = $(obj:.o=.d) bin = test diff -r 7b574ba5758e -r be61704c4cc8 firstp/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firstp/Makefile Tue Nov 29 07:22:49 2011 +0200 @@ -0,0 +1,30 @@ +mgldir = ../src +demudir = ../dosemu + +obj = firstp.o \ + $(mgldir)/mingl.o $(mgldir)/mglrast.o $(mgldir)/mglgen.o \ + $(mgldir)/texture.o $(mgldir)/palman.o \ + $(mgldir)/cvec.o $(mgldir)/scene.o \ + $(demudir)/dosemu.o +dep = $(obj:.o=.d) +bin = firstp + +CC = gcc +CFLAGS = -pedantic -Wall -g `pkg-config --cflags sdl` -I$(mgldir) -I$(demudir) +LDFLAGS = `pkg-config --libs sdl` + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +-include $(dep) + +%.d: %.c + @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ + +.PHONY: clean +clean: + rm -f $(obj) $(bin) + +.PHONY: cleandep +cleandep: + rm -f $(dep) diff -r 7b574ba5758e -r be61704c4cc8 firstp/Makefile.bcc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firstp/Makefile.bcc Tue Nov 29 07:22:49 2011 +0200 @@ -0,0 +1,26 @@ +.AUTODEPEND + +obj = src\test.obj src\vga.obj src\timer.obj src\mouse.obj \ + src\mingl.obj src\mglrast.obj src\mglgen.obj \ + src\texture.obj src\palman.obj +bin = dos3d.exe + +CC = bcc + +# 286 instructions, large memory model +CFLAGS = -1 -f287 -ml -O -G -Isrc + +$(bin): $(obj) + $(CC) @&&| +$(CFLAGS) -e$@ +$(obj) +| + +.SUFFIXES: .c .obj + +.c.obj: + $(CC) $(CFLAGS) -o$@ -c $< + +clean: + del src\*.obj + del $(bin) diff -r 7b574ba5758e -r be61704c4cc8 firstp/firstp.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firstp/firstp.c Tue Nov 29 07:22:49 2011 +0200 @@ -0,0 +1,251 @@ +#include +#include +#include +#include +#include +#include "vga.h" +#include "mingl.h" +#include "timer.h" +#include "mouse.h" +#include "texture.h" +#include "palman.h" +#include "scene.h" + +#define DEG2RAD(x) (M_PI * (x) / 180.0) + +static int init(void); +static void shutdown(void); +static void redraw(void); +static int proc_events(void); +static int keyb(int key); +static void mouse_button(int bn, int x, int y); +static void mouse_motion(int x, int y); +static void sighandler(int s); + + +static float cam_x, cam_y, cam_z = 10; +static float cam_theta, cam_phi; + +static float walk_speed = 0.1; +static float look_speed = 1.0; +static int mouse_look = 0; + +static void *fbuf; +static struct scene scn; + + +int main(void) +{ + if(init() == -1) { + return 1; + } + + while(proc_events()) { + redraw(); + } + + shutdown(); + return 0; +} + + +static int init(void) +{ + init_timer(100); + + set_video_mode(0x13); + + signal(SIGINT, sighandler); + signal(SIGSEGV, sighandler); + signal(SIGFPE, sighandler); + signal(SIGILL, sighandler); + signal(SIGABRT, sighandler); + + if(mgl_init(320, 200) == -1) { + fprintf(stderr, "mgl init failed\n"); + return -1; + } + fbuf = mgl_framebuffer(); + + mgl_enable(MGL_CULL_FACE); + mgl_enable(MGL_SMOOTH); + mgl_enable(MGL_LIGHTING); + mgl_enable(MGL_DEPTH_TEST); + + mgl_matrix_mode(MGL_PROJECTION); + mgl_load_identity(); + mgl_perspective(45.0, 320.0 / 200.0, 0.5, 200.0); + + /* setup palette */ + palm_add_color(255, 255, 255); + + scn_init(&scn); + if(scn_load(&scn, "data/hall.obj") == -1) { + return -1; + } + + palm_build(); + { + int i, palsz = palm_palette_size(); + struct palm_color *pal = palm_palette(); + + for(i=0; i 90) { + cam_phi = 90; + } + } +} + +static void sighandler(int s) +{ + set_video_mode(3); + + switch(s) { + case SIGABRT: + fprintf(stderr, "abort\n"); + break; + + case SIGILL: + fprintf(stderr, "illegal operation\n"); + break; + + case SIGSEGV: + fprintf(stderr, "segmentation fault\n"); + break; + + case SIGINT: + fprintf(stderr, "interrupted\n"); + break; + + case SIGFPE: + fprintf(stderr, "floating point exception\n"); + break; + + default: + fprintf(stderr, "unexpected signal\n"); + } + + exit(1); +} diff -r 7b574ba5758e -r be61704c4cc8 src/mglimpl.h --- a/src/mglimpl.h Mon Nov 28 05:12:33 2011 +0200 +++ b/src/mglimpl.h Tue Nov 29 07:22:49 2011 +0200 @@ -18,6 +18,8 @@ #ifndef MGL_IMPL_H_ #define MGL_IMPL_H_ +#include "vmath.h" + #define MATRIX_STACK_SIZE 8 #define MAX_LIGHTS 4 @@ -30,17 +32,6 @@ #define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5) -typedef struct { - float x, y, z, w; -} vec4_t; - -typedef struct { - float x, y, z; -} vec3_t; - -typedef struct { - float x, y; -} vec2_t; typedef float mat4_t[16];