Blender V2.61 - r43446

BSP_MeshDrawer.cpp

Go to the documentation of this file.
00001 
00028 #include "BSP_MeshDrawer.h"
00029 
00030 #include "BSP_TMesh.h"
00031 
00032 #if defined(WIN32) || defined(__APPLE__)
00033 #   ifdef WIN32
00034 #       include <windows.h>
00035 #       include <GL/gl.h>
00036 #       include <GL/glu.h>
00037 #   else // WIN32
00038 #       include <AGL/gl.h>
00039 #   endif // WIN32
00040 #else // defined(WIN32) || defined(__APPLE__)
00041 #   include <GL/gl.h>
00042 #   include <GL/glu.h>
00043 #endif // defined(WIN32) || defined(__APPLE__)
00044 
00045 #include <vector>
00046 
00047 using namespace std;
00048 
00049     void
00050 BSP_MeshDrawer::
00051 DrawMesh(
00052     BSP_TMesh &mesh,
00053     int render_mode
00054 ){
00055 
00056 
00057     if (render_mode == e_none) return;
00058 
00059     // decompose polygons into triangles.
00060 
00061     glEnable(GL_LIGHTING);
00062 
00063 
00064     if (render_mode == e_wireframe || render_mode == e_wireframe_shaded) {
00065 
00066         glColor3f(0.0, 0.0, 0.0);
00067 
00068         if (render_mode == e_wireframe) {
00069             glDisable(GL_LIGHTING);
00070         } else {
00071             glEnable(GL_LIGHTING);
00072         }
00073 
00074         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00075 
00076         glEnable(GL_POLYGON_OFFSET_FILL);
00077         glPolygonOffset(1.0,1.0);
00078 
00079         glBegin(GL_TRIANGLES);
00080             DrawPolies(mesh);
00081         glEnd();
00082 
00083         glColor3f(1.0, 1.0, 1.0);
00084         glDisable(GL_LIGHTING);
00085         glDisable(GL_POLYGON_OFFSET_FILL);
00086         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00087 
00088         glBegin(GL_TRIANGLES);
00089             DrawPolies(mesh);
00090         glEnd();
00091         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00092     } else {
00093 
00094         glEnable(GL_LIGHTING);
00095 
00096         glBegin(GL_TRIANGLES);
00097             DrawPolies(mesh);
00098         glEnd();
00099     }
00100     
00101 
00102 }
00103 
00104 
00105     void
00106 BSP_MeshDrawer::
00107 DrawPolies(
00108     BSP_TMesh &mesh
00109 ){
00110 
00111     const vector<BSP_TVertex> & verts = mesh.VertexSet();
00112     const vector<BSP_TFace> &faces = mesh.FaceSet();
00113 
00114     // just draw the edges for now.
00115 
00116     vector<BSP_TVertex>::const_iterator vertex_it = verts.begin();
00117 
00118 
00119     vector<BSP_TFace>::const_iterator faces_it = faces.begin();
00120     vector<BSP_TFace>::const_iterator faces_end = faces.end();
00121 
00122     for (;faces_it != faces_end; ++faces_it ){  
00123 
00124         glNormal3f(
00125             faces_it->m_normal.x(),
00126             faces_it->m_normal.y(),
00127             faces_it->m_normal.z()
00128         );
00129 
00130         glVertex3f(
00131             verts[faces_it->m_verts[0]].m_pos.x(),
00132             verts[faces_it->m_verts[0]].m_pos.y(),
00133             verts[faces_it->m_verts[0]].m_pos.z()
00134         );
00135         glVertex3f(
00136             verts[faces_it->m_verts[1]].m_pos.x(),
00137             verts[faces_it->m_verts[1]].m_pos.y(),
00138             verts[faces_it->m_verts[1]].m_pos.z()
00139         );
00140         glVertex3f(
00141             verts[faces_it->m_verts[2]].m_pos.x(),
00142             verts[faces_it->m_verts[2]].m_pos.y(),
00143             verts[faces_it->m_verts[2]].m_pos.z()
00144         );
00145     }
00146 }
00147     
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156