dos3d
changeset 19:c10f62b2bd56
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 30 Nov 2011 07:17:09 +0200 |
parents | 777be77b6432 |
children | 9c23bfe10745 |
files | firstp/Makefile.bcc firstp/firstp.c src/scene.c src/texture.c |
diffstat | 4 files changed, 97 insertions(+), 15 deletions(-) [+] |
line diff
1.1 --- a/firstp/Makefile.bcc Wed Nov 30 00:06:28 2011 +0200 1.2 +++ b/firstp/Makefile.bcc Wed Nov 30 07:17:09 2011 +0200 1.3 @@ -1,14 +1,18 @@ 1.4 .AUTODEPEND 1.5 1.6 -obj = src\test.obj src\vga.obj src\timer.obj src\mouse.obj \ 1.7 - src\mingl.obj src\mglrast.obj src\mglgen.obj \ 1.8 - src\texture.obj src\palman.obj 1.9 -bin = dos3d.exe 1.10 +mgldir = ..\src 1.11 + 1.12 +obj = firstp.obj \ 1.13 + $(mgldir)\vga.obj $(mgldir)\timer.obj $(mgldir)\mouse.obj \ 1.14 + $(mgldir)\mingl.obj $(mgldir)\mglrast.obj $(mgldir)\mglgen.obj \ 1.15 + $(mgldir)\texture.obj $(mgldir)\palman.obj \ 1.16 + $(mgldir)\cvec.obj $(mgldir)\scene.obj 1.17 +bin = firstp.exe 1.18 1.19 CC = bcc 1.20 1.21 # 286 instructions, large memory model 1.22 -CFLAGS = -1 -f287 -ml -O -G -Isrc 1.23 +CFLAGS = -1 -f287 -ml -O -G -I..\src 1.24 1.25 $(bin): $(obj) 1.26 $(CC) @&&| 1.27 @@ -22,5 +26,6 @@ 1.28 $(CC) $(CFLAGS) -o$@ -c $< 1.29 1.30 clean: 1.31 - del src\*.obj 1.32 + del $(mgldir)\*.obj 1.33 + del firstp.obj 1.34 del $(bin)
2.1 --- a/firstp/firstp.c Wed Nov 30 00:06:28 2011 +0200 2.2 +++ b/firstp/firstp.c Wed Nov 30 07:17:09 2011 +0200 2.3 @@ -26,7 +26,7 @@ 2.4 static float cam_x, cam_y, cam_z; 2.5 static float cam_theta, cam_phi; 2.6 2.7 -static float walk_speed = 0.1; 2.8 +static float walk_speed = 0.5; 2.9 static float look_speed = 1.0; 2.10 static int mouse_look = 0; 2.11
3.1 --- a/src/scene.c Wed Nov 30 00:06:28 2011 +0200 3.2 +++ b/src/scene.c Wed Nov 30 07:17:09 2011 +0200 3.3 @@ -3,6 +3,7 @@ 3.4 #include <string.h> 3.5 #include <ctype.h> 3.6 #include <errno.h> 3.7 +#include <assert.h> 3.8 #include "scene.h" 3.9 #include "cvec.h" 3.10 #include "palman.h" 3.11 @@ -159,11 +160,12 @@ 3.12 vnarr = cvec_append(vnarr, &v); 3.13 3.14 } else if(strcmp(tok, "vt") == 0) { 3.15 - vec3_t v; 3.16 + vec2_t v; 3.17 3.18 - if(!rest || sscanf(rest, "%f %f %f\n", &v.x, &v.y, &v.z) != 3) { 3.19 + if(!rest || sscanf(rest, "%f %f\n", &v.x, &v.y) != 2) { 3.20 continue; 3.21 } 3.22 + v.y = 1.0 - v.y; 3.23 vtarr = cvec_append(vtarr, &v); 3.24 3.25 } else if(strcmp(tok, "f") == 0) { 3.26 @@ -338,6 +340,45 @@ 3.27 mesh_draw(m); 3.28 m = m->next; 3.29 } 3.30 + 3.31 +#if 0 3.32 + { 3.33 + int i; 3.34 + struct palm_color *pal = palm_palette(); 3.35 + float dx = 1.8 / 256; 3.36 + struct material *mtl = scn->matlist; 3.37 + 3.38 + glMatrixMode(GL_MODELVIEW); 3.39 + glPushMatrix(); 3.40 + glLoadIdentity(); 3.41 + glMatrixMode(GL_PROJECTION); 3.42 + glPushMatrix(); 3.43 + glLoadIdentity(); 3.44 + 3.45 + glPushAttrib(GL_ENABLE_BIT); 3.46 + glDisable(GL_LIGHTING); 3.47 + glDisable(GL_DEPTH_TEST); 3.48 + 3.49 + glBegin(GL_QUADS); 3.50 + for(i=0; i<255; i++) { 3.51 + float x = i * dx - 0.9; 3.52 + glColor3ub(pal[i].r, pal[i].g, pal[i].b); 3.53 + glVertex2f(x, 0.98); 3.54 + glVertex2f(x, 0.9); 3.55 + glColor3ub(pal[i + 1].r, pal[i + 1].g, pal[i + 1].b); 3.56 + glVertex2f(x + dx, 0.9); 3.57 + glVertex2f(x + dx, 0.98); 3.58 + } 3.59 + glEnd(); 3.60 + 3.61 + glPopAttrib(); 3.62 + 3.63 + glMatrixMode(GL_PROJECTION); 3.64 + glPopMatrix(); 3.65 + glMatrixMode(GL_MODELVIEW); 3.66 + glPopMatrix(); 3.67 + } 3.68 +#endif 3.69 } 3.70 3.71 /* --- material --- */ 3.72 @@ -421,6 +462,7 @@ 3.73 3.74 #ifdef USE_GL 3.75 if(mtl->tex) { 3.76 + assert(mtl->tex->pixels); 3.77 glEnable(GL_TEXTURE_2D); 3.78 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 3.79 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 3.80 @@ -443,7 +485,7 @@ 3.81 } 3.82 #else 3.83 if(mtl->tex) { 3.84 - /*mgl_enable(MGL_TEXTURE_2D);*/ 3.85 + mgl_enable(MGL_TEXTURE_2D); 3.86 mgl_teximage(mtl->tex->width, mtl->tex->height, mtl->tex->pixels); 3.87 } else { 3.88 mgl_index(mtl->kd_base);
4.1 --- a/src/texture.c Wed Nov 30 00:06:28 2011 +0200 4.2 +++ b/src/texture.c Wed Nov 30 07:17:09 2011 +0200 4.3 @@ -24,7 +24,7 @@ 4.4 4.5 struct texture *load_texture(const char *fname) 4.6 { 4.7 - int i, num_pixels; 4.8 + int i, num_pixels, hdrline = 0; 4.9 struct texture *tex; 4.10 long fpos; 4.11 4.12 @@ -38,10 +38,45 @@ 4.13 free_texture(tex); 4.14 return 0; 4.15 } 4.16 - if(fscanf(tex->file, "P6 %d %d 255 ", &tex->width, &tex->height) != 2) { 4.17 - fprintf(stderr, "invalid pixmap: %s\n", fname); 4.18 - free_texture(tex); 4.19 - return 0; 4.20 + 4.21 + while(hdrline < 3) { 4.22 + char buf[64]; 4.23 + if(!fgets(buf, sizeof buf, tex->file)) { 4.24 + fprintf(stderr, "invalid pixmap: %s\n", fname); 4.25 + free_texture(tex); 4.26 + return 0; 4.27 + } 4.28 + 4.29 + if(buf[0] == '#') { 4.30 + continue; 4.31 + } 4.32 + 4.33 + switch(hdrline) { 4.34 + case 0: 4.35 + if(buf[0] != 'P' || buf[1] != '6') { 4.36 + fprintf(stderr, "invalid pixmap: %s\n", fname); 4.37 + free_texture(tex); 4.38 + return 0; 4.39 + } 4.40 + break; 4.41 + 4.42 + case 1: 4.43 + if(sscanf(buf, "%d %d", &tex->width, &tex->height) != 2) { 4.44 + fprintf(stderr, "invalid pixmap: %s\n", fname); 4.45 + free_texture(tex); 4.46 + return 0; 4.47 + } 4.48 + break; 4.49 + 4.50 + case 2: 4.51 + if(atoi(buf) != 255) { 4.52 + fprintf(stderr, "invalid pixmap: %s\n", fname); 4.53 + free_texture(tex); 4.54 + return 0; 4.55 + } 4.56 + break; 4.57 + } 4.58 + hdrline++; 4.59 } 4.60 fpos = ftell(tex->file); 4.61