dos3d
changeset 3:0e781cc43178
adding textures
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 21 Nov 2011 10:16:09 +0200 |
parents | 8c9a63a902d5 |
children | c3e0bccd673e |
files | Makefile Makefile.bcc src/mglgen.c src/mglimpl.h src/mglrast.c src/mingl.c src/mingl.h src/scantmpl.h src/test.c src/texture.c src/texture.h |
diffstat | 11 files changed, 297 insertions(+), 41 deletions(-) [+] |
line diff
1.1 --- a/Makefile Mon Nov 21 10:15:37 2011 +0200 1.2 +++ b/Makefile Mon Nov 21 10:16:09 2011 +0200 1.3 @@ -1,6 +1,6 @@ 1.4 obj = src/test.o \ 1.5 src/mingl.o src/mglrast.o src/mglgen.o \ 1.6 - src/palman.o \ 1.7 + src/texture.o src/palman.o \ 1.8 dosemu/dosemu.o 1.9 dep = $(obj:.o=.d) 1.10 bin = test
2.1 --- a/Makefile.bcc Mon Nov 21 10:15:37 2011 +0200 2.2 +++ b/Makefile.bcc Mon Nov 21 10:16:09 2011 +0200 2.3 @@ -2,7 +2,7 @@ 2.4 2.5 obj = src\test.obj src\vga.obj src\timer.obj src\mouse.obj \ 2.6 src\mingl.obj src\mglrast.obj src\mglgen.obj \ 2.7 - src\palman.obj 2.8 + src\texture.obj src\palman.obj 2.9 bin = dos3d.exe 2.10 2.11 CC = bcc
3.1 --- a/src/mglgen.c Mon Nov 21 10:15:37 2011 +0200 3.2 +++ b/src/mglgen.c Mon Nov 21 10:16:09 2011 +0200 3.3 @@ -27,40 +27,40 @@ 3.4 mgl_begin(MGL_QUADS); 3.5 /* front */ 3.6 mgl_normal(0, 0, 1); 3.7 - mgl_vertex3f(-hsz, hsz, hsz); 3.8 - mgl_vertex3f(-hsz, -hsz, hsz); 3.9 - mgl_vertex3f(hsz, -hsz, hsz); 3.10 - mgl_vertex3f(hsz, hsz, hsz); 3.11 + mgl_texcoord2f(0, 1); mgl_vertex3f(-hsz, hsz, hsz); 3.12 + mgl_texcoord2f(0, 0); mgl_vertex3f(-hsz, -hsz, hsz); 3.13 + mgl_texcoord2f(1, 0); mgl_vertex3f(hsz, -hsz, hsz); 3.14 + mgl_texcoord2f(1, 1); mgl_vertex3f(hsz, hsz, hsz); 3.15 /* back */ 3.16 mgl_normal(0, 0, -1); 3.17 - mgl_vertex3f(hsz, hsz, -hsz); 3.18 - mgl_vertex3f(hsz, -hsz, -hsz); 3.19 - mgl_vertex3f(-hsz, -hsz, -hsz); 3.20 - mgl_vertex3f(-hsz, hsz, -hsz); 3.21 + mgl_texcoord2f(0, 1); mgl_vertex3f(hsz, hsz, -hsz); 3.22 + mgl_texcoord2f(0, 0); mgl_vertex3f(hsz, -hsz, -hsz); 3.23 + mgl_texcoord2f(1, 0); mgl_vertex3f(-hsz, -hsz, -hsz); 3.24 + mgl_texcoord2f(1, 1); mgl_vertex3f(-hsz, hsz, -hsz); 3.25 /* right */ 3.26 mgl_normal(1, 0, 0); 3.27 - mgl_vertex3f(hsz, hsz, hsz); 3.28 - mgl_vertex3f(hsz, -hsz, hsz); 3.29 - mgl_vertex3f(hsz, -hsz, -hsz); 3.30 - mgl_vertex3f(hsz, hsz, -hsz); 3.31 + mgl_texcoord2f(0, 1); mgl_vertex3f(hsz, hsz, hsz); 3.32 + mgl_texcoord2f(0, 0); mgl_vertex3f(hsz, -hsz, hsz); 3.33 + mgl_texcoord2f(1, 0); mgl_vertex3f(hsz, -hsz, -hsz); 3.34 + mgl_texcoord2f(1, 1); mgl_vertex3f(hsz, hsz, -hsz); 3.35 /* left */ 3.36 mgl_normal(-1, 0, 0); 3.37 - mgl_vertex3f(-hsz, hsz, -hsz); 3.38 - mgl_vertex3f(-hsz, -hsz, -hsz); 3.39 - mgl_vertex3f(-hsz, -hsz, hsz); 3.40 - mgl_vertex3f(-hsz, hsz, hsz); 3.41 + mgl_texcoord2f(0, 1); mgl_vertex3f(-hsz, hsz, -hsz); 3.42 + mgl_texcoord2f(0, 0); mgl_vertex3f(-hsz, -hsz, -hsz); 3.43 + mgl_texcoord2f(1, 0); mgl_vertex3f(-hsz, -hsz, hsz); 3.44 + mgl_texcoord2f(1, 1); mgl_vertex3f(-hsz, hsz, hsz); 3.45 /* top */ 3.46 mgl_normal(0, 1, 0); 3.47 - mgl_vertex3f(-hsz, hsz, -hsz); 3.48 - mgl_vertex3f(-hsz, hsz, hsz); 3.49 - mgl_vertex3f(hsz, hsz, hsz); 3.50 - mgl_vertex3f(hsz, hsz, -hsz); 3.51 + mgl_texcoord2f(0, 1); mgl_vertex3f(-hsz, hsz, -hsz); 3.52 + mgl_texcoord2f(0, 0); mgl_vertex3f(-hsz, hsz, hsz); 3.53 + mgl_texcoord2f(1, 0); mgl_vertex3f(hsz, hsz, hsz); 3.54 + mgl_texcoord2f(1, 1); mgl_vertex3f(hsz, hsz, -hsz); 3.55 /* bottom */ 3.56 mgl_normal(0, -1, 0); 3.57 - mgl_vertex3f(hsz, -hsz, -hsz); 3.58 - mgl_vertex3f(hsz, -hsz, hsz); 3.59 - mgl_vertex3f(-hsz, -hsz, hsz); 3.60 - mgl_vertex3f(-hsz, -hsz, -hsz); 3.61 + mgl_texcoord2f(0, 1); mgl_vertex3f(hsz, -hsz, -hsz); 3.62 + mgl_texcoord2f(0, 0); mgl_vertex3f(hsz, -hsz, hsz); 3.63 + mgl_texcoord2f(1, 0); mgl_vertex3f(-hsz, -hsz, hsz); 3.64 + mgl_texcoord2f(1, 1); mgl_vertex3f(-hsz, -hsz, -hsz); 3.65 mgl_end(); 3.66 } 3.67
4.1 --- a/src/mglimpl.h Mon Nov 21 10:15:37 2011 +0200 4.2 +++ b/src/mglimpl.h Mon Nov 21 10:16:09 2011 +0200 4.3 @@ -45,6 +45,13 @@ 4.4 int cidx; 4.5 }; 4.6 4.7 +struct texture { 4.8 + int width, height; 4.9 + int xshift, yshift; 4.10 + unsigned int xmask, ymask; 4.11 + unsigned char *pixels; 4.12 +}; 4.13 + 4.14 struct state { 4.15 unsigned int flags; 4.16 int ord, frontface, cullface; 4.17 @@ -57,6 +64,8 @@ 4.18 int col_range; /* color interpolation range */ 4.19 vec3_t ldir[MAX_LIGHTS]; 4.20 float lint[MAX_LIGHTS]; 4.21 + 4.22 + struct texture tex; 4.23 }; 4.24 4.25 struct framebuffer { 4.26 @@ -65,6 +74,7 @@ 4.27 unsigned short **zbuf; /* zbuffer broken in 64k tiles */ 4.28 }; 4.29 4.30 + 4.31 int mgl_rast_init(struct state *state, struct framebuffer *fbuf); 4.32 void mgl_rast_cleanup(void); 4.33 void mgl_rast_prepare(void);
5.1 --- a/src/mglrast.c Mon Nov 21 10:15:37 2011 +0200 5.2 +++ b/src/mglrast.c Mon Nov 21 10:16:09 2011 +0200 5.3 @@ -32,6 +32,7 @@ 5.4 #define SCAN_LINE scan_line_flat 5.5 #undef INTERP_DEPTH 5.6 #undef INTERP_ENERGY 5.7 +#undef INTERP_TEX 5.8 #include "scantmpl.h" 5.9 #undef SCAN_EDGE 5.10 #undef SCAN_LINE 5.11 @@ -40,6 +41,7 @@ 5.12 #define SCAN_LINE scan_line_z 5.13 #define INTERP_DEPTH 5.14 #undef INTERP_ENERGY 5.15 +#undef INTERP_TEX 5.16 #include "scantmpl.h" 5.17 #undef SCAN_EDGE 5.18 #undef SCAN_LINE 5.19 @@ -48,6 +50,7 @@ 5.20 #define SCAN_LINE scan_line_e 5.21 #undef INTERP_DEPTH 5.22 #define INTERP_ENERGY 5.23 +#undef INTERP_TEX 5.24 #include "scantmpl.h" 5.25 #undef SCAN_EDGE 5.26 #undef SCAN_LINE 5.27 @@ -56,10 +59,48 @@ 5.28 #define SCAN_LINE scan_line_ze 5.29 #define INTERP_DEPTH 5.30 #define INTERP_ENERGY 5.31 +#undef INTERP_TEX 5.32 #include "scantmpl.h" 5.33 #undef SCAN_EDGE 5.34 #undef SCAN_LINE 5.35 5.36 +#define SCAN_EDGE scan_edge_t 5.37 +#define SCAN_LINE scan_line_t 5.38 +#undef INTERP_DEPTH 5.39 +#undef INTERP_ENERGY 5.40 +#define INTERP_TEX 5.41 +#include "scantmpl.h" 5.42 +#undef SCAN_EDGE 5.43 +#undef SCAN_LINE 5.44 + 5.45 +#define SCAN_EDGE scan_edge_zt 5.46 +#define SCAN_LINE scan_line_zt 5.47 +#define INTERP_DEPTH 5.48 +#undef INTERP_ENERGY 5.49 +#define INTERP_TEX 5.50 +#include "scantmpl.h" 5.51 +#undef SCAN_EDGE 5.52 +#undef SCAN_LINE 5.53 + 5.54 +#define SCAN_EDGE scan_edge_et 5.55 +#define SCAN_LINE scan_line_et 5.56 +#undef INTERP_DEPTH 5.57 +#define INTERP_ENERGY 5.58 +#define INTERP_TEX 5.59 +#include "scantmpl.h" 5.60 +#undef SCAN_EDGE 5.61 +#undef SCAN_LINE 5.62 + 5.63 +#define SCAN_EDGE scan_edge_zet 5.64 +#define SCAN_LINE scan_line_zet 5.65 +#define INTERP_DEPTH 5.66 +#define INTERP_ENERGY 5.67 +#define INTERP_TEX 5.68 +#include "scantmpl.h" 5.69 +#undef SCAN_EDGE 5.70 +#undef SCAN_LINE 5.71 + 5.72 + 5.73 static void (*scan_edge)(struct vertex*, struct vertex*); 5.74 static void (*scan_line)(int, unsigned char*); 5.75 5.76 @@ -91,19 +132,32 @@ 5.77 void mgl_rast_prepare(void) 5.78 { 5.79 static void (*sedge[])(struct vertex*, struct vertex*) = { 5.80 - scan_edge_flat, /* 00 */ 5.81 - scan_edge_z, /* 01 */ 5.82 - scan_edge_e, /* 10 */ 5.83 - scan_edge_ze /* 11 */ 5.84 + /* tez */ 5.85 + scan_edge_flat, /* 000 */ 5.86 + scan_edge_z, /* 001 */ 5.87 + scan_edge_e, /* 010 */ 5.88 + scan_edge_ze, /* 011 */ 5.89 + scan_edge_t, /* 100 */ 5.90 + scan_edge_zt, /* 101 */ 5.91 + scan_edge_et, /* 110 */ 5.92 + scan_edge_zet /* 111 */ 5.93 }; 5.94 static void (*sline[])(int, unsigned char*) = { 5.95 - scan_line_flat, /* 00 */ 5.96 - scan_line_z, /* 01 */ 5.97 - scan_line_e, /* 10 */ 5.98 - scan_line_ze /* 11 */ 5.99 + /* tez */ 5.100 + scan_line_flat, /* 000 */ 5.101 + scan_line_z, /* 001 */ 5.102 + scan_line_e, /* 010 */ 5.103 + scan_line_ze, /* 011 */ 5.104 + scan_line_t, /* 100 */ 5.105 + scan_line_zt, /* 101 */ 5.106 + scan_line_et, /* 110 */ 5.107 + scan_line_zet /* 111 */ 5.108 }; 5.109 int bits = 0; 5.110 5.111 + if((st->flags & MGL_TEXTURE_2D) && st->tex.pixels) { 5.112 + bits |= 4; 5.113 + } 5.114 if(st->flags & MGL_SMOOTH) { 5.115 bits |= 2; 5.116 }
6.1 --- a/src/mingl.c Mon Nov 21 10:15:37 2011 +0200 6.2 +++ b/src/mingl.c Mon Nov 21 10:16:09 2011 +0200 6.3 @@ -23,11 +23,13 @@ 6.4 #include "mingl.h" 6.5 #include "mglimpl.h" 6.6 6.7 + 6.8 #define DOT(a, b) ((a).x * (b).x + (a).y * (b).y + (a).z * (b).z) 6.9 6.10 static void transform(vec4_t *res, vec4_t *v, float *mat); 6.11 static void transform3(vec3_t *res, vec3_t *v, float *mat); 6.12 static void vertex_proc(struct vertex *vert); 6.13 +static int calc_shiftmask(int val, int *shiftp, unsigned int *maskp); 6.14 6.15 static struct state st; 6.16 static struct framebuffer fb; 6.17 @@ -106,6 +108,11 @@ 6.18 st.flags &= ~bit; 6.19 } 6.20 6.21 +int mgl_isenabled(unsigned int bit) 6.22 +{ 6.23 + return (st.flags & bit) != 0; 6.24 +} 6.25 + 6.26 void mgl_front_face(int ff) 6.27 { 6.28 st.frontface = ff; 6.29 @@ -464,3 +471,30 @@ 6.30 float x = nr * tan(vfov_rad / 2.0); 6.31 mgl_frustum(-aspect * x, aspect * x, -x, x, nr, fr); 6.32 } 6.33 + 6.34 +void mgl_teximage(int width, int height, unsigned char *pixels) 6.35 +{ 6.36 + st.tex.width = width; 6.37 + st.tex.height = height; 6.38 + st.tex.pixels = pixels; 6.39 + 6.40 + if(calc_shiftmask(width, &st.tex.xshift, &st.tex.xmask) == -1 || 6.41 + calc_shiftmask(height, &st.tex.yshift, &st.tex.ymask) == -1) { 6.42 + st.tex.pixels = 0; 6.43 + } 6.44 +} 6.45 + 6.46 +#define MAX_SHIFT 12 6.47 +static int calc_shiftmask(int val, int *shiftp, unsigned int *maskp) 6.48 +{ 6.49 + int i; 6.50 + 6.51 + for(i=0; i<MAX_SHIFT; i++) { 6.52 + if((val >> i) == 1) { 6.53 + *shiftp = i; 6.54 + *maskp = ~(0xffff << i); 6.55 + return 0; 6.56 + } 6.57 + } 6.58 + return -1; 6.59 +}
7.1 --- a/src/mingl.h Mon Nov 21 10:15:37 2011 +0200 7.2 +++ b/src/mingl.h Mon Nov 21 10:16:09 2011 +0200 7.3 @@ -23,6 +23,7 @@ 7.4 #define MGL_DEPTH_TEST 2 7.5 #define MGL_SMOOTH 4 7.6 #define MGL_LIGHTING 8 7.7 +#define MGL_TEXTURE_2D 16 7.8 7.9 /* primitives */ 7.10 #define MGL_POINTS 1 7.11 @@ -50,6 +51,7 @@ 7.12 7.13 void mgl_enable(unsigned int bit); 7.14 void mgl_disable(unsigned int bit); 7.15 +int mgl_isenabled(unsigned int bit); 7.16 7.17 void mgl_front_face(int ff); 7.18 void mgl_cull_face(int cf); 7.19 @@ -86,6 +88,8 @@ 7.20 void mgl_frustum(float left, float right, float bottom, float top, float nr, float fr); 7.21 void mgl_perspective(float vfov, float aspect, float nr, float fr); 7.22 7.23 +void mgl_teximage(int width, int height, unsigned char *pixels); 7.24 + 7.25 void mgl_cube(float sz); 7.26 void mgl_sphere(float rad, int usub, int vsub); 7.27 void mgl_sphere_part(float rad, int usub, int vsub, float umax, float vmax);
8.1 --- a/src/scantmpl.h Mon Nov 21 10:15:37 2011 +0200 8.2 +++ b/src/scantmpl.h Mon Nov 21 10:16:09 2011 +0200 8.3 @@ -25,7 +25,10 @@ 8.4 #ifdef INTERP_ENERGY 8.5 float e, de, dfde; 8.6 #endif 8.7 - float x, y; 8.8 +#ifdef INTERP_TEX 8.9 + float u, v, du, dv, dfdu, dfdv; 8.10 +#endif 8.11 + float x; 8.12 struct vertex *edge; 8.13 8.14 dy = v1->pos.y - v0->pos.y; 8.15 @@ -37,7 +40,6 @@ 8.16 dfdx = dx / dy; 8.17 8.18 #ifdef INTERP_DEPTH 8.19 - assert(fb->zbuf); 8.20 dz = v1->pos.z - v0->pos.z; 8.21 dfdz = dz / dy; 8.22 #endif 8.23 @@ -45,6 +47,12 @@ 8.24 de = v1->energy - v0->energy; 8.25 dfde = de / dy; 8.26 #endif 8.27 +#ifdef INTERP_TEX 8.28 + du = v1->tc.x - v0->tc.x; 8.29 + dv = v1->tc.y - v0->tc.y; 8.30 + dfdu = du / dy; 8.31 + dfdv = dv / dy; 8.32 +#endif 8.33 8.34 if(dy < 0.0) { 8.35 struct vertex *tmp = v0; 8.36 @@ -65,6 +73,10 @@ 8.37 #ifdef INTERP_ENERGY 8.38 e = v0->energy; 8.39 #endif 8.40 +#ifdef INTERP_TEX 8.41 + u = v0->tc.x; 8.42 + v = v0->tc.y; 8.43 +#endif 8.44 for(i=start; i<end; i++) { 8.45 edge[i].pos.x = x; 8.46 x += dfdx; 8.47 @@ -81,13 +93,21 @@ 8.48 #else 8.49 edge[i].energy = v0->energy; 8.50 #endif 8.51 + 8.52 +#ifdef INTERP_TEX 8.53 + edge[i].tc.x = u; 8.54 + edge[i].tc.y = v; 8.55 + u += dfdu; 8.56 + v += dfdv; 8.57 +#endif 8.58 } 8.59 } 8.60 8.61 static void SCAN_LINE(int y, unsigned char *sline) 8.62 { 8.63 - int i, x0, x1, len, tmp, cidx; 8.64 -#if defined(INTERP_DEPTH) || defined(INTERP_ENERGY) 8.65 + int x0, x1, len, tmp, cidx; 8.66 +#if defined(INTERP_DEPTH) || defined(INTERP_ENERGY) || defined(INTERP_TEX) 8.67 + int i; 8.68 float x, dx; 8.69 #endif 8.70 #ifdef INTERP_DEPTH 8.71 @@ -96,6 +116,10 @@ 8.72 #ifdef INTERP_ENERGY 8.73 float e, de, dfde; 8.74 #endif 8.75 +#ifdef INTERP_TEX 8.76 + int tx, ty; 8.77 + float u, v, du, dv, dfdu, dfdv; 8.78 +#endif 8.79 struct vertex *left, *right; 8.80 8.81 x0 = (int)ROUND(vleft[y].pos.x); 8.82 @@ -124,7 +148,7 @@ 8.83 assert(len >= 0); 8.84 8.85 cidx = left[y].cidx; 8.86 -#if !defined(INTERP_DEPTH) && !defined(INTERP_ENERGY) 8.87 +#if !defined(INTERP_DEPTH) && !defined(INTERP_ENERGY) && !defined(INTERP_TEX) 8.88 /* no interpolation at all, just memset the whole scanline */ 8.89 memset(sline + x0, cidx + left[y].energy * st->col_range, len); 8.90 #else 8.91 @@ -146,13 +170,36 @@ 8.92 de = right[y].energy - e; 8.93 dfde = de / dx; 8.94 #endif 8.95 +#ifdef INTERP_TEX 8.96 + u = left[y].tc.x; 8.97 + v = left[y].tc.y; 8.98 + du = right[y].tc.x - u; 8.99 + dv = right[y].tc.y - v; 8.100 + dfdu = du / dx; 8.101 + dfdv = dv / dx; 8.102 +#endif 8.103 8.104 for(i=0; i<len; i++) { 8.105 + int c = cidx; 8.106 + 8.107 +#ifdef INTERP_DEPTH 8.108 + z += dfdz; 8.109 +#endif 8.110 +#ifdef INTERP_TEX 8.111 + tx = (int)(u * st->tex.width) & st->tex.xmask; 8.112 + ty = (int)(v * st->tex.height) & st->tex.ymask; 8.113 + c = st->tex.pixels[(ty << st->tex.xshift) + tx]; 8.114 + 8.115 + u += dfdu; 8.116 + v += dfdv; 8.117 +#endif 8.118 #ifdef INTERP_ENERGY 8.119 - cidx = left[y].cidx + e * st->col_range; 8.120 + c += e * st->col_range; 8.121 e += dfde; 8.122 +#else 8.123 + c += left[y].energy * st->col_range; 8.124 #endif 8.125 - sline[x0 + i] = cidx; 8.126 + sline[x0 + i] = c; 8.127 } 8.128 #endif /* flat */ 8.129 }
9.1 --- a/src/test.c Mon Nov 21 10:15:37 2011 +0200 9.2 +++ b/src/test.c Mon Nov 21 10:16:09 2011 +0200 9.3 @@ -25,6 +25,7 @@ 9.4 #include "timer.h" 9.5 #include "mouse.h" 9.6 #include "palman.h" 9.7 +#include "texture.h" 9.8 9.9 static int init(void); 9.10 static void shutdown(void); 9.11 @@ -39,6 +40,8 @@ 9.12 9.13 static unsigned char *fbuf; 9.14 9.15 +static struct texture *tex; 9.16 + 9.17 static int white_base, red_base, green_base, blue_base; 9.18 static int grad_range; 9.19 9.20 @@ -145,6 +148,12 @@ 9.21 mgl_load_identity(); 9.22 mgl_perspective(45.0, 320.0 / 200.0, 0.5, 100.0); 9.23 9.24 + if(!(tex = tex_gen_checker(64, 64, 3, 3, red_base, blue_base))) { 9.25 + fprintf(stderr, "failed to generate texture\n"); 9.26 + return -1; 9.27 + } 9.28 + mgl_teximage(tex->width, tex->height, tex->pixels); 9.29 + 9.30 return 0; 9.31 } 9.32 9.33 @@ -245,6 +254,22 @@ 9.34 case 27: 9.35 return 0; 9.36 9.37 + case 's': 9.38 + if(mgl_isenabled(MGL_SMOOTH)) { 9.39 + mgl_disable(MGL_SMOOTH); 9.40 + } else { 9.41 + mgl_enable(MGL_SMOOTH); 9.42 + } 9.43 + break; 9.44 + 9.45 + case 't': 9.46 + if(mgl_isenabled(MGL_TEXTURE_2D)) { 9.47 + mgl_disable(MGL_TEXTURE_2D); 9.48 + } else { 9.49 + mgl_enable(MGL_TEXTURE_2D); 9.50 + } 9.51 + break; 9.52 + 9.53 case ' ': 9.54 auto_rotate = !auto_rotate; 9.55 break;
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/src/texture.c Mon Nov 21 10:16:09 2011 +0200 10.3 @@ -0,0 +1,52 @@ 10.4 +/* 10.5 +256-color 3D graphics hack for real-mode DOS. 10.6 +Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org> 10.7 + 10.8 +This program is free software: you can redistribute it and/or modify 10.9 +it under the terms of the GNU General Public License as published by 10.10 +the Free Software Foundation, either version 3 of the License, or 10.11 +(at your option) any later version. 10.12 + 10.13 +This program is distributed in the hope that it will be useful, 10.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 10.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10.16 +GNU General Public License for more details. 10.17 + 10.18 +You should have received a copy of the GNU General Public License 10.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 10.20 +*/ 10.21 + 10.22 +#include <stdlib.h> 10.23 +#include "texture.h" 10.24 +#include "palman.h" 10.25 + 10.26 +struct texture *tex_load(const char *fname) 10.27 +{ 10.28 + return 0; /* TODO */ 10.29 +} 10.30 + 10.31 +struct texture *tex_gen_checker(int xsz, int ysz, int ush, int vsh, int c1, int c2) 10.32 +{ 10.33 + int i, j; 10.34 + struct texture *tex; 10.35 + unsigned char *pptr; 10.36 + 10.37 + if(!(tex = malloc(sizeof *tex))) { 10.38 + return 0; 10.39 + } 10.40 + if(!(tex->pixels = malloc(xsz * ysz))) { 10.41 + free(tex); 10.42 + return 0; 10.43 + } 10.44 + tex->width = xsz; 10.45 + tex->height = ysz; 10.46 + 10.47 + pptr = tex->pixels; 10.48 + for(i=0; i<ysz; i++) { 10.49 + for(j=0; j<xsz; j++) { 10.50 + int c = ((i >> vsh) & 1) == ((j >> ush) & 1) ? c1 : c2; 10.51 + *pptr++ = c; 10.52 + } 10.53 + } 10.54 + return tex; 10.55 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/src/texture.h Mon Nov 21 10:16:09 2011 +0200 11.3 @@ -0,0 +1,30 @@ 11.4 +/* 11.5 +256-color 3D graphics hack for real-mode DOS. 11.6 +Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org> 11.7 + 11.8 +This program is free software: you can redistribute it and/or modify 11.9 +it under the terms of the GNU General Public License as published by 11.10 +the Free Software Foundation, either version 3 of the License, or 11.11 +(at your option) any later version. 11.12 + 11.13 +This program is distributed in the hope that it will be useful, 11.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 11.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11.16 +GNU General Public License for more details. 11.17 + 11.18 +You should have received a copy of the GNU General Public License 11.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 11.20 +*/ 11.21 +#ifndef TEXTURE_H_ 11.22 +#define TEXTURE_H_ 11.23 + 11.24 +struct texture { 11.25 + int width, height; 11.26 + unsigned char *pixels; 11.27 +}; 11.28 + 11.29 +struct texture *tex_load(const char *fname); 11.30 + 11.31 +struct texture *tex_gen_checker(int xsz, int ysz, int usub, int vsub, int c1, int c2); 11.32 + 11.33 +#endif /* TEXTURE_H_ */