intravenous

diff src/geom.cc @ 1:3ea290d35984

it's never going to finish but wth :)
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Apr 2012 22:42:43 +0300
parents
children 94d4c60af435
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/geom.cc	Sat Apr 21 22:42:43 2012 +0300
     1.3 @@ -0,0 +1,41 @@
     1.4 +#include "opengl.h"
     1.5 +#include "geom.h"
     1.6 +
     1.7 +#ifdef SINGLE_PRECISION_MATH
     1.8 +#define ELEM_TYPE		GL_FLOAT
     1.9 +#else
    1.10 +#define ELEM_TYPE		GL_DOUBLE
    1.11 +#endif
    1.12 +
    1.13 +void draw_mesh(unsigned int prim, int num_verts, const Vertex *vbuf, const unsigned int *ibuf)
    1.14 +{
    1.15 +	glEnableClientState(GL_VERTEX_ARRAY);
    1.16 +	glVertexPointer(3, ELEM_TYPE, sizeof *vbuf, &vbuf->pos);
    1.17 +
    1.18 +	glEnableClientState(GL_NORMAL_ARRAY);
    1.19 +	glNormalPointer(ELEM_TYPE, sizeof *vbuf, &vbuf->norm);
    1.20 +
    1.21 +	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    1.22 +	glTexCoordPointer(2, ELEM_TYPE, sizeof *vbuf, &vbuf->tc);
    1.23 +
    1.24 +	if(ibuf) {
    1.25 +		glDrawElements(prim, num_verts, GL_UNSIGNED_INT, ibuf);
    1.26 +	} else {
    1.27 +		glDrawArrays(prim, 0, num_verts);
    1.28 +	}
    1.29 +
    1.30 +	glDisableClientState(GL_VERTEX_ARRAY);
    1.31 +	glDisableClientState(GL_NORMAL_ARRAY);
    1.32 +	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    1.33 +#if 0
    1.34 +	glBegin(GL_QUADS);
    1.35 +	for(int i=0; i<count; i++) {
    1.36 +		for(int j=0; j<4; j++) {
    1.37 +			const Vertex *v = vbuf + ibuf[i * 4 + j];
    1.38 +			glNormal3f(v->norm.x, v->norm.y, v->norm.z);
    1.39 +			glVertex3f(v->pos.x, v->pos.y, v->pos.z);
    1.40 +		}
    1.41 +	}
    1.42 +	glEnd();
    1.43 +#endif
    1.44 +}