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