Subversion Repositories gelsvn

Rev

Rev 492 | Rev 601 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 492 Rev 594
Line -... Line 1...
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
1
#include <GL/glew.h>
7
#include <GL/glew.h>
2
 
8
 
3
#include "CGLA/Mat4x4f.h"
9
#include <CGLA/Mat4x4f.h>
4
#include "CGLA/Vec3d.h"
10
#include <CGLA/Vec3d.h>
5
#include "draw.h"
-
 
6
#include "HMesh/FaceCirculator.h"
11
#include <HMesh/Manifold.h>
7
 
12
 
-
 
13
#include "draw.h"
8
#include "SinglePassWireframeRenderer.h"
14
#include "SinglePassWireframeRenderer.h"
9
#include "IDBufferWireFrameRenderer.h"
15
#include "IDBufferWireFrameRenderer.h"
10
#include "SOIL.h"
16
#include "SOIL.h"
11
 
17
 
-
 
18
namespace GLGraphics
-
 
19
{
12
using namespace CGLA;
20
    using namespace CGLA;
13
using namespace HMesh;
21
    using namespace HMesh;
14
using namespace std;
22
    using namespace std;
15
 
23
    
16
namespace 
24
    namespace
Line 24... Line 32...
24
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
32
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
25
		}
33
            }
26
		else
34
            else
27
			glDisable(GL_TEXTURE_2D);
35
                glDisable(GL_TEXTURE_2D);
28
		
36
            
29
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material.ambient);
37
            glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Vec4f(material.ambient).get());
30
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material.diffuse);
38
            glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Vec4f(material.diffuse).get());
31
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular);
39
            glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Vec4f(material.specular).get());
32
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
40
            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
33
	}
41
        }
34
	
-
 
35
}
-
 
36
 
-
 
37
namespace GLGraphics
-
 
38
{
-
 
39
	
-
 
40
	void draw(Manifold& m, bool per_vertex_norms)
-
 
41
	{
-
 
42
		for(FaceIter f=m.faces_begin(); f != m.faces_end(); ++f)
-
 
43
		{
-
 
44
			FaceCirculator fc(f);
-
 
45
			if(!per_vertex_norms) 
-
 
46
				glNormal3fv(normal(f).get());
-
 
47
			if(no_edges(f)== 3) 
-
 
48
				glBegin(GL_TRIANGLES);
-
 
49
			else 
-
 
50
				glBegin(GL_POLYGON);
-
 
51
			while(!fc.end())
-
 
52
			{
-
 
53
				Vec3f n = normal(fc.get_vertex());
-
 
54
				if(per_vertex_norms) 
-
 
55
					glNormal3fv(n.get());
-
 
56
				glVertex3fv(fc.get_vertex()->pos.get());
-
 
57
				++fc;
-
 
58
			}
-
 
59
			glEnd();
-
 
60
		}
-
 
61
	}
42
    }
62
 
43
    
63
	void draw(const Geometry::IndexedFaceSet& geometry)
44
    void draw(const Geometry::IndexedFaceSet& geometry)
64
	{
45
    {
65
		glBegin(GL_TRIANGLES);
46
        glBegin(GL_TRIANGLES);
Line 137... Line 118...
137
		}
118
        }
138
	}
119
    }
139
	 
120
 
140
	/// Draw an object of type T which contains only triangles as wireframe. In practice T = Manifold or TriMesh.
121
	/// Draw an object of type T which contains only triangles as wireframe. In practice T = Manifold or TriMesh.
141
	template<typename T>
122
	template<typename T>
142
	inline void draw_triangles_in_wireframe(T& m, bool per_vertex_norms, const CGLA::Vec3f& line_color)
123
    void draw_triangles_in_wireframe(T& m, bool per_vertex_norms, const CGLA::Vec3f& line_color)
143
	{
124
	{
144
		static SinglePassWireframeRenderer swr;
125
		static SinglePassWireframeRenderer swr;
145
		swr.enable(line_color);
126
		swr.enable(line_color);
146
		draw(m, per_vertex_norms);
127
		draw(m, per_vertex_norms);
147
		swr.disable();
128
		swr.disable();
148
	}
129
	}
149
 
130
    
150
	template
131
	template
151
	inline void draw_triangles_in_wireframe(HMesh::Manifold& m, bool per_vertex_norms, const CGLA::Vec3f& line_color);
132
    void draw_triangles_in_wireframe(HMesh::Manifold& m, bool per_vertex_norms, const CGLA::Vec3f& line_color);
152
 
133
    
153
	template
134
	template
154
	inline void draw_triangles_in_wireframe(Geometry::TriMesh& m, bool per_vertex_norms, const CGLA::Vec3f& line_color);
135
    void draw_triangles_in_wireframe(Geometry::TriMesh& m, bool per_vertex_norms, const CGLA::Vec3f& line_color);
155
 
136
    
156
  template<class T>
137
    template<class T>
157
	void draw_wireframe_oldfashioned(T& m, bool per_vertex_norms, const Vec3f& line_color)
138
    void draw_wireframe_oldfashioned(const T& m, bool per_vertex_norms, const Vec3f& line_color)
158
	{
139
    {
159
		// Store state that we change
140
        // Store state that we change
160
		glPushAttrib(GL_POLYGON_BIT);
141
        glPushAttrib(GL_POLYGON_BIT);
161
		GLboolean lights_on;
142
        GLboolean lights_on;
162
		glGetBooleanv(GL_LIGHTING, &lights_on);
143
        glGetBooleanv(GL_LIGHTING, &lights_on);
Line 178... Line 159...
178
		// Put back old state
159
        // Put back old state
179
		glColor3fv(current_color.get());
160
        glColor3fv(current_color.get());
180
		if(lights_on) glEnable(GL_LIGHTING);
161
        if(lights_on) glEnable(GL_LIGHTING);
181
		glPopAttrib();
162
        glPopAttrib();
182
	}
163
    }
183
	
-
 
184
	template
164
    template
185
	void draw_wireframe_oldfashioned<HMesh::Manifold>(HMesh::Manifold& m, bool per_vertex_norms, const Vec3f& line_color);
165
    void draw_wireframe_oldfashioned(const HMesh::Manifold& m, bool per_vertex_norms, const Vec3f& line_color);
186
 
166
    
187
	template
167
    template
188
	void draw_wireframe_oldfashioned(Geometry::TriMesh& m, bool per_vertex_norms, const Vec3f& line_color);
168
    void draw_wireframe_oldfashioned(const Geometry::TriMesh& m, bool per_vertex_norms, const Vec3f& line_color);
-
 
169
    
-
 
170
    
-
 
171
    void draw(const Manifold& m, bool per_vertex_norms)
-
 
172
    {
-
 
173
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f){
-
 
174
            if(!per_vertex_norms)
-
 
175
                glNormal3dv(normal(m, *f).get());
-
 
176
            if(no_edges(m, *f)== 3)
-
 
177
                glBegin(GL_TRIANGLES);
-
 
178
            else
-
 
179
                glBegin(GL_POLYGON);
-
 
180
            
-
 
181
            for(Walker w = m.walker(*f); !w.full_circle(); w = w.circulate_face_ccw()){
-
 
182
                Vec3d n = normal(m, w.vertex());
-
 
183
                if(per_vertex_norms)
-
 
184
                    glNormal3dv(n.get());
-
 
185
                glVertex3dv(m.pos(w.vertex()).get());
-
 
186
            }
-
 
187
            glEnd();
-
 
188
        }
-
 
189
    }
-
 
190
    
189
 
191
    
190
	
192
    
191
	void draw(const Geometry::AABox& box)
193
    void draw(const Geometry::AABox& box)
192
	{
194
    {
193
		glBegin(GL_QUADS);
195
        glBegin(GL_QUADS);