a1a3150c4d44000b99d9c8e312b112168c3556b8
[blender.git] / intern / bsp / test / BSP_GhostTest / BSP_MeshDrawer.cpp
1 /**
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include "BSP_MeshDrawer.h"
29
30 #include "BSP_TMesh.h"
31
32 #if defined(WIN32) || defined(__APPLE__)
33 #       ifdef WIN32
34 #               include <windows.h>
35 #               include <GL/gl.h>
36 #               include <GL/glu.h>
37 #       else // WIN32
38 #               include <AGL/gl.h>
39 #       endif // WIN32
40 #else // defined(WIN32) || defined(__APPLE__)
41 #       include <GL/gl.h>
42 #       include <GL/glu.h>
43 #endif // defined(WIN32) || defined(__APPLE__)
44
45 #include <vector>
46
47 using namespace std;
48
49         void
50 BSP_MeshDrawer::
51 DrawMesh(
52         BSP_TMesh &mesh,
53         int render_mode
54 ){
55
56
57         if (render_mode == e_none) return;
58
59         // decompose polygons into triangles.
60
61         glEnable(GL_LIGHTING);
62
63
64         if (render_mode == e_wireframe || render_mode == e_wireframe_shaded) {
65
66                 glColor3f(0.0, 0.0, 0.0);
67
68                 if (render_mode == e_wireframe) {
69                         glDisable(GL_LIGHTING);
70                 } else {
71                         glEnable(GL_LIGHTING);
72                 }
73
74                 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
75
76                 glEnable(GL_POLYGON_OFFSET_FILL);
77                 glPolygonOffset(1.0,1.0);
78
79                 glBegin(GL_TRIANGLES);
80                         DrawPolies(mesh);
81                 glEnd();
82
83                 glColor3f(1.0, 1.0, 1.0);
84                 glDisable(GL_LIGHTING);
85                 glDisable(GL_POLYGON_OFFSET_FILL);
86                 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
87
88                 glBegin(GL_TRIANGLES);
89                         DrawPolies(mesh);
90                 glEnd();
91                 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
92         } else {
93
94                 glEnable(GL_LIGHTING);
95
96                 glBegin(GL_TRIANGLES);
97                         DrawPolies(mesh);
98                 glEnd();
99         }
100         
101
102 }
103
104
105         void
106 BSP_MeshDrawer::
107 DrawPolies(
108         BSP_TMesh &mesh
109 ){
110
111         const vector<BSP_TVertex> & verts = mesh.VertexSet();
112         const vector<BSP_TFace> &faces = mesh.FaceSet();
113
114         // just draw the edges for now.
115
116         vector<BSP_TVertex>::const_iterator vertex_it = verts.begin();
117
118
119         vector<BSP_TFace>::const_iterator faces_it = faces.begin();
120         vector<BSP_TFace>::const_iterator faces_end = faces.end();
121
122         for (;faces_it != faces_end; ++faces_it ){      
123
124                 glNormal3f(
125                         faces_it->m_normal.x(),
126                         faces_it->m_normal.y(),
127                         faces_it->m_normal.z()
128                 );
129
130                 glVertex3f(
131                         verts[faces_it->m_verts[0]].m_pos.x(),
132                         verts[faces_it->m_verts[0]].m_pos.y(),
133                         verts[faces_it->m_verts[0]].m_pos.z()
134                 );
135                 glVertex3f(
136                         verts[faces_it->m_verts[1]].m_pos.x(),
137                         verts[faces_it->m_verts[1]].m_pos.y(),
138                         verts[faces_it->m_verts[1]].m_pos.z()
139                 );
140                 glVertex3f(
141                         verts[faces_it->m_verts[2]].m_pos.x(),
142                         verts[faces_it->m_verts[2]].m_pos.y(),
143                         verts[faces_it->m_verts[2]].m_pos.z()
144                 );
145         }
146 }
147         
148
149
150
151
152
153
154
155
156