exhibit description text rendering
[laserbrain_demo] / src / geomdraw.cc
1 #include "geomdraw.h"
2 #include "opengl.h"
3 #include "logger.h"
4 #include "shader.h"
5
6 static void draw_sphere(const Sphere *sph);
7 static void draw_box(const Box *box);
8 static void draw_plane(const Plane *plane);
9
10 void draw_geom_object(const GeomObject *gobj)
11 {
12         switch(gobj->type) {
13         case GOBJ_SPHERE:
14                 draw_sphere((Sphere*)gobj);
15                 break;
16
17         case GOBJ_AABOX:
18                 {
19                         Box box = Box(*(AABox*)gobj, Mat4::identity);
20                         draw_box(&box);
21                 }
22                 break;
23
24         case GOBJ_BOX:
25                 draw_box((Box*)gobj);
26                 break;
27
28         case GOBJ_PLANE:
29                 draw_plane((Plane*)gobj);
30                 break;
31
32         default:
33                 break;
34         }
35 }
36
37 static void draw_sphere(const Sphere *sph)
38 {
39         // TODO
40         warning_log("draw_sphere unimplemented\n");
41 }
42
43 static void draw_box(const Box *box)
44 {
45         static const int edges[][2] = {
46                 {0, 1}, {1, 2}, {2, 3}, {3, 0},
47                 {4, 5}, {5, 6}, {6, 7}, {7, 4},
48                 {0, 4}, {1, 5}, {2, 6}, {3, 7}
49         };
50
51         bind_shader(0);
52
53         glPushAttrib(GL_ENABLE_BIT);
54         glDisable(GL_LIGHTING);
55         glDisable(GL_TEXTURE_2D);
56
57         glMatrixMode(GL_MODELVIEW);
58         glPushMatrix();
59         glMultMatrixf(box->xform[0]);
60
61         glLineWidth(1.0);
62         glBegin(GL_LINES);
63         glColor3f(1, 1, 0);
64         for(int i=0; i<12; i++) {
65                 Vec3 a = box->get_corner(edges[i][0]);
66                 Vec3 b = box->get_corner(edges[i][1]);
67
68                 glVertex3f(a.x, a.y, a.z);
69                 glVertex3f(b.x, b.y, b.z);
70         }
71         glEnd();
72
73         glPopMatrix();
74         glPopAttrib();
75 }
76
77 static void draw_plane(const Plane *plane)
78 {
79         // TODO
80         warning_log("draw_plane unimplemented\n");
81 }