volmetrics

view src/mesh.cc @ 8:928954bfefd7

added mesh (draw: immediate mode - todo: displ. list)
author Eleni Maria Stea <elene.mst@gmail.com>
date Sat, 25 Jan 2014 19:25:32 +0200
parents
children 40febfed6cff
line source
1 #include <GL/gl.h>
2 #include "mesh.h"
4 Mesh::Mesh()
5 {
6 }
8 void Mesh::add_vertex(const Vector3 &vertex)
9 {
10 vertices.push_back(vertex);
11 }
13 void Mesh::add_normal(const Vector3 &normal)
14 {
15 normals.push_back(normal);
16 }
18 void Mesh::clear()
19 {
20 vertices.clear();
21 normals.clear();
22 }
24 void Mesh::draw() const
25 {
26 size_t sz = vertices.size();
28 if(normals.size() != sz)
29 return;
31 glBegin(GL_TRIANGLES);
32 for(size_t i=0; i<sz; i++) {
33 const Vector3 &n = normals[i];
34 glNormal3f(n.x, n.y, n.z);
36 const Vector3 &v = vertices[i];
37 glVertex3f(v.x, v.y, v.z);
38 }
39 glEnd();
40 }