# HG changeset patch # User John Tsiombikas # Date 1322630229 -7200 # Node ID c10f62b2bd566c6e371f5477f35b10fd1a44956c # Parent 777be77b6432aba8587df4cf53653c168d58779a foo diff -r 777be77b6432 -r c10f62b2bd56 firstp/Makefile.bcc --- a/firstp/Makefile.bcc Wed Nov 30 00:06:28 2011 +0200 +++ b/firstp/Makefile.bcc Wed Nov 30 07:17:09 2011 +0200 @@ -1,14 +1,18 @@ .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 +mgldir = ..\src + +obj = firstp.obj \ + $(mgldir)\vga.obj $(mgldir)\timer.obj $(mgldir)\mouse.obj \ + $(mgldir)\mingl.obj $(mgldir)\mglrast.obj $(mgldir)\mglgen.obj \ + $(mgldir)\texture.obj $(mgldir)\palman.obj \ + $(mgldir)\cvec.obj $(mgldir)\scene.obj +bin = firstp.exe CC = bcc # 286 instructions, large memory model -CFLAGS = -1 -f287 -ml -O -G -Isrc +CFLAGS = -1 -f287 -ml -O -G -I..\src $(bin): $(obj) $(CC) @&&| @@ -22,5 +26,6 @@ $(CC) $(CFLAGS) -o$@ -c $< clean: - del src\*.obj + del $(mgldir)\*.obj + del firstp.obj del $(bin) diff -r 777be77b6432 -r c10f62b2bd56 firstp/firstp.c --- a/firstp/firstp.c Wed Nov 30 00:06:28 2011 +0200 +++ b/firstp/firstp.c Wed Nov 30 07:17:09 2011 +0200 @@ -26,7 +26,7 @@ static float cam_x, cam_y, cam_z; static float cam_theta, cam_phi; -static float walk_speed = 0.1; +static float walk_speed = 0.5; static float look_speed = 1.0; static int mouse_look = 0; diff -r 777be77b6432 -r c10f62b2bd56 src/scene.c --- a/src/scene.c Wed Nov 30 00:06:28 2011 +0200 +++ b/src/scene.c Wed Nov 30 07:17:09 2011 +0200 @@ -3,6 +3,7 @@ #include #include #include +#include #include "scene.h" #include "cvec.h" #include "palman.h" @@ -159,11 +160,12 @@ vnarr = cvec_append(vnarr, &v); } else if(strcmp(tok, "vt") == 0) { - vec3_t v; + vec2_t v; - if(!rest || sscanf(rest, "%f %f %f\n", &v.x, &v.y, &v.z) != 3) { + if(!rest || sscanf(rest, "%f %f\n", &v.x, &v.y) != 2) { continue; } + v.y = 1.0 - v.y; vtarr = cvec_append(vtarr, &v); } else if(strcmp(tok, "f") == 0) { @@ -338,6 +340,45 @@ mesh_draw(m); m = m->next; } + +#if 0 + { + int i; + struct palm_color *pal = palm_palette(); + float dx = 1.8 / 256; + struct material *mtl = scn->matlist; + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + + glBegin(GL_QUADS); + for(i=0; i<255; i++) { + float x = i * dx - 0.9; + glColor3ub(pal[i].r, pal[i].g, pal[i].b); + glVertex2f(x, 0.98); + glVertex2f(x, 0.9); + glColor3ub(pal[i + 1].r, pal[i + 1].g, pal[i + 1].b); + glVertex2f(x + dx, 0.9); + glVertex2f(x + dx, 0.98); + } + glEnd(); + + glPopAttrib(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + } +#endif } /* --- material --- */ @@ -421,6 +462,7 @@ #ifdef USE_GL if(mtl->tex) { + assert(mtl->tex->pixels); glEnable(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -443,7 +485,7 @@ } #else if(mtl->tex) { - /*mgl_enable(MGL_TEXTURE_2D);*/ + mgl_enable(MGL_TEXTURE_2D); mgl_teximage(mtl->tex->width, mtl->tex->height, mtl->tex->pixels); } else { mgl_index(mtl->kd_base); diff -r 777be77b6432 -r c10f62b2bd56 src/texture.c --- a/src/texture.c Wed Nov 30 00:06:28 2011 +0200 +++ b/src/texture.c Wed Nov 30 07:17:09 2011 +0200 @@ -24,7 +24,7 @@ struct texture *load_texture(const char *fname) { - int i, num_pixels; + int i, num_pixels, hdrline = 0; struct texture *tex; long fpos; @@ -38,10 +38,45 @@ free_texture(tex); return 0; } - if(fscanf(tex->file, "P6 %d %d 255 ", &tex->width, &tex->height) != 2) { - fprintf(stderr, "invalid pixmap: %s\n", fname); - free_texture(tex); - return 0; + + while(hdrline < 3) { + char buf[64]; + if(!fgets(buf, sizeof buf, tex->file)) { + fprintf(stderr, "invalid pixmap: %s\n", fname); + free_texture(tex); + return 0; + } + + if(buf[0] == '#') { + continue; + } + + switch(hdrline) { + case 0: + if(buf[0] != 'P' || buf[1] != '6') { + fprintf(stderr, "invalid pixmap: %s\n", fname); + free_texture(tex); + return 0; + } + break; + + case 1: + if(sscanf(buf, "%d %d", &tex->width, &tex->height) != 2) { + fprintf(stderr, "invalid pixmap: %s\n", fname); + free_texture(tex); + return 0; + } + break; + + case 2: + if(atoi(buf) != 255) { + fprintf(stderr, "invalid pixmap: %s\n", fname); + free_texture(tex); + return 0; + } + break; + } + hdrline++; } fpos = ftell(tex->file);