intravenous
view src/geom.cc @ 10:8fbdc6f84f64
fixed after the change in vmath
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 31 May 2013 01:30:14 +0300 |
parents | 3ea290d35984 |
children |
line source
1 #include "opengl.h"
2 #include "geom.h"
4 #ifdef SINGLE_PRECISION_MATH
5 #define ELEM_TYPE GL_FLOAT
6 #else
7 #define ELEM_TYPE GL_DOUBLE
8 #endif
10 void draw_mesh(unsigned int prim, int num_verts, const Vertex *vbuf, const unsigned int *ibuf, int attr_tang_loc)
11 {
12 glEnableClientState(GL_VERTEX_ARRAY);
13 glVertexPointer(3, ELEM_TYPE, sizeof *vbuf, &vbuf->pos);
15 glEnableClientState(GL_NORMAL_ARRAY);
16 glNormalPointer(ELEM_TYPE, sizeof *vbuf, &vbuf->norm);
18 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
19 glTexCoordPointer(2, ELEM_TYPE, sizeof *vbuf, &vbuf->tc);
21 if(attr_tang_loc >= 0) {
22 glEnableVertexAttribArrayARB(attr_tang_loc);
23 glVertexAttribPointerARB(attr_tang_loc, 3, ELEM_TYPE, GL_FALSE, sizeof *vbuf, &vbuf->tang);
24 }
26 if(ibuf) {
27 glDrawElements(prim, num_verts, GL_UNSIGNED_INT, ibuf);
28 } else {
29 glDrawArrays(prim, 0, num_verts);
30 }
32 glDisableClientState(GL_VERTEX_ARRAY);
33 glDisableClientState(GL_NORMAL_ARRAY);
34 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
36 if(attr_tang_loc >= 0) {
37 glDisableVertexAttribArrayARB(attr_tang_loc);
38 }
39 #if 0
40 glBegin(GL_QUADS);
41 for(int i=0; i<count; i++) {
42 for(int j=0; j<4; j++) {
43 const Vertex *v = vbuf + ibuf[i * 4 + j];
44 glNormal3f(v->norm.x, v->norm.y, v->norm.z);
45 glVertex3f(v->pos.x, v->pos.y, v->pos.z);
46 }
47 }
48 glEnd();
49 #endif
50 }