gba-x3dtest

diff src/ggen.c @ 13:2070a81127f2

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Jun 2014 08:28:28 +0300
parents ecc022a21279
children c398d834d64a
line diff
     1.1 --- a/src/ggen.c	Mon Jun 23 06:44:04 2014 +0300
     1.2 +++ b/src/ggen.c	Mon Jun 23 08:28:28 2014 +0300
     1.3 @@ -10,54 +10,78 @@
     1.4  		*vptr++ = z; \
     1.5  	} while(0)
     1.6  
     1.7 +#define COLOR(r, g, b) \
     1.8 +	do { \
     1.9 +		*cptr++ = r; \
    1.10 +		*cptr++ = g; \
    1.11 +		*cptr++ = b; \
    1.12 +	} while(0)
    1.13 +
    1.14  int gen_box(struct mesh *m)
    1.15  {
    1.16 +	int i;
    1.17  	int num_faces = 8;
    1.18  	int num_verts = num_faces * 4;
    1.19  	int32_t v[8][3] = {
    1.20  		{-X1, -X1, -X1}, {X1, -X1, -X1}, {X1, -X1, X1}, {-X1, -X1, X1},
    1.21  		{-X1, X1, -X1}, {X1, X1, -X1}, {X1, X1, X1}, {-X1, X1, X1}
    1.22  	};
    1.23 -	int32_t *vptr;
    1.24 +	int32_t *vptr, *cptr;
    1.25  
    1.26  
    1.27  	m->prim = X3D_QUADS;
    1.28  	m->nverts = num_verts;
    1.29 -	if(!(m->verts = malloc(num_verts * sizeof *m->verts))) {
    1.30 +	if(!(m->verts = malloc(num_verts * 3 * sizeof *m->verts))) {
    1.31  		return -1;
    1.32  	}
    1.33  	vptr = m->verts;
    1.34  
    1.35 +	if(!(m->colors = malloc(num_verts * 3 * sizeof *m->colors))) {
    1.36 +		return -1;
    1.37 +	}
    1.38 +	cptr = m->colors;
    1.39 +
    1.40  	/* -Y */
    1.41  	VERTEX(v[0][0], v[0][1], v[0][2]);
    1.42  	VERTEX(v[1][0], v[1][1], v[1][2]);
    1.43  	VERTEX(v[2][0], v[2][1], v[2][2]);
    1.44  	VERTEX(v[3][0], v[3][1], v[3][2]);
    1.45 +	for(i=0; i<4; i++) COLOR(65536, 0, 65536);
    1.46 +
    1.47  	/* +Y */
    1.48  	VERTEX(v[4][0], v[4][1], v[4][2]);
    1.49  	VERTEX(v[5][0], v[5][1], v[5][2]);
    1.50  	VERTEX(v[6][0], v[6][1], v[6][2]);
    1.51  	VERTEX(v[7][0], v[7][1], v[7][2]);
    1.52 +	for(i=0; i<4; i++) COLOR(0, 65536, 0);
    1.53 +
    1.54  	/* -Z */
    1.55  	VERTEX(v[0][0], v[0][1], v[0][2]);
    1.56  	VERTEX(v[4][0], v[4][1], v[4][2]);
    1.57  	VERTEX(v[5][0], v[5][1], v[5][2]);
    1.58  	VERTEX(v[1][0], v[1][1], v[1][2]);
    1.59 +	for(i=0; i<4; i++) COLOR(65536, 65536, 0);
    1.60 +
    1.61  	/* +Z */
    1.62  	VERTEX(v[2][0], v[2][1], v[2][2]);
    1.63  	VERTEX(v[6][0], v[6][1], v[6][2]);
    1.64  	VERTEX(v[7][0], v[7][1], v[7][2]);
    1.65  	VERTEX(v[3][0], v[3][1], v[3][2]);
    1.66 +	for(i=0; i<4; i++) COLOR(0, 0, 65536);
    1.67 +
    1.68  	/* +X */
    1.69  	VERTEX(v[1][0], v[1][1], v[1][2]);
    1.70  	VERTEX(v[5][0], v[5][1], v[5][2]);
    1.71  	VERTEX(v[6][0], v[6][1], v[6][2]);
    1.72  	VERTEX(v[2][0], v[2][1], v[2][2]);
    1.73 +	for(i=0; i<4; i++) COLOR(65536, 0, 0);
    1.74 +
    1.75  	/* -X */
    1.76  	VERTEX(v[3][0], v[3][1], v[3][2]);
    1.77  	VERTEX(v[7][0], v[7][1], v[7][2]);
    1.78  	VERTEX(v[4][0], v[4][1], v[4][2]);
    1.79  	VERTEX(v[0][0], v[0][1], v[0][2]);
    1.80 +	for(i=0; i<4; i++) COLOR(0, 65536, 65536);
    1.81  
    1.82  	return 0;
    1.83  }