Subversion Repositories gelsvn

Rev

Rev 373 | Rev 432 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 373 Rev 396
Line -... Line 1...
-
 
1
#include <GL/glew.h>
-
 
2
 
1
#include "CGLA/Mat4x4f.h"
3
#include "CGLA/Mat4x4f.h"
2
#include "CGLA/Vec3d.h"
4
#include "CGLA/Vec3d.h"
3
#include "gel_glu.h"
-
 
4
#include "draw.h"
5
#include "draw.h"
5
#include "HMesh/FaceCirculator.h"
6
#include "HMesh/FaceCirculator.h"
6
 
7
 
-
 
8
#include "SinglePassWireframeRenderer.h"
-
 
9
#include "IDBufferWireFrameRenderer.h"
-
 
10
 
7
using namespace CGLA;
11
using namespace CGLA;
8
using namespace HMesh;
12
using namespace HMesh;
9
using namespace std;
13
using namespace std;
10
 
14
 
11
namespace 
15
namespace 
12
{
16
{
13
	void set_material(const Geometry::Material& material)
17
	void set_material(const Geometry::Material& material)
14
{
18
	{
15
		if(material.has_texture && material.tex_id >=0)
19
		if(material.has_texture && material.tex_id >=0)
16
		{
20
		{
17
			glEnable(GL_TEXTURE_2D);
21
			glEnable(GL_TEXTURE_2D);
18
			glBindTexture(GL_TEXTURE_2D, material.tex_id);
22
			glBindTexture(GL_TEXTURE_2D, material.tex_id);
19
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
23
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Line 23... Line 27...
23
		
27
		
24
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material.ambient);
28
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material.ambient);
25
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material.diffuse);
29
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material.diffuse);
26
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular);
30
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular);
27
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
31
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
28
}
32
	}
29
 
33
	
30
}
34
}
31
 
35
 
32
namespace GLGraphics
36
namespace GLGraphics
33
{
37
{
34
 
38
	
35
void draw(Manifold& m, bool per_vertex_norms)
39
	void draw(Manifold& m, bool per_vertex_norms)
36
	{
40
	{
37
		for(FaceIter f=m.faces_begin(); f != m.faces_end(); ++f)
41
		for(FaceIter f=m.faces_begin(); f != m.faces_end(); ++f)
38
		{
42
		{
39
			FaceCirculator fc(f);
43
			FaceCirculator fc(f);
40
			if(!per_vertex_norms) 
44
			if(!per_vertex_norms) 
Line 100... Line 104...
100
		}
104
		}
101
		glEnd();
105
		glEnd();
102
		glDisable(GL_TEXTURE_2D);
106
		glDisable(GL_TEXTURE_2D);
103
	}
107
	}
104
	
108
	
-
 
109
	
-
 
110
	 
-
 
111
	template<class T>
-
 
112
	void draw_wireframe_oldfashioned(T& m, bool per_vertex_norms, const Vec3f& line_color)
-
 
113
	{
-
 
114
		// Store state that we change
-
 
115
		glPushAttrib(GL_POLYGON_BIT);
-
 
116
		GLboolean lights_on;
-
 
117
		glGetBooleanv(GL_LIGHTING, &lights_on);
-
 
118
		Vec4f current_color;
-
 
119
		glGetFloatv(GL_CURRENT_COLOR, &current_color[0]);
-
 
120
		
-
 
121
		// Draw filled
-
 
122
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
 
123
		draw(m, per_vertex_norms);
-
 
124
		
-
 
125
		// Draw lines
-
 
126
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
 
127
		glDisable(GL_LIGHTING);
-
 
128
		glEnable(GL_POLYGON_OFFSET_LINE);
-
 
129
		glPolygonOffset(0,-5);
-
 
130
		glColor3fv(line_color.get());
-
 
131
		draw(m, per_vertex_norms);
-
 
132
		
-
 
133
		// Put back old state
-
 
134
		glColor3fv(current_color.get());
-
 
135
		if(lights_on) glEnable(GL_LIGHTING);
-
 
136
		glPopAttrib();
-
 
137
	}
-
 
138
	
-
 
139
	template
-
 
140
	void draw_wireframe_oldfashioned<HMesh::Manifold>(HMesh::Manifold& m, bool per_vertex_norms, const Vec3f& line_color);
-
 
141
 
-
 
142
	template
-
 
143
	void draw_wireframe_oldfashioned(Geometry::TriMesh& m, bool per_vertex_norms, const Vec3f& line_color);
-
 
144
 
-
 
145
	
105
	void draw(const Geometry::AABox& box)
146
	void draw(const Geometry::AABox& box)
106
	{
147
	{
107
		glBegin(GL_QUADS);
148
		glBegin(GL_QUADS);
108
		Vec3f norm_neg[] = {Vec3f(0,0,-1), Vec3f(-1,0,0), Vec3f(0,-1,0)};
149
		Vec3f norm_neg[] = {Vec3f(0,0,-1), Vec3f(-1,0,0), Vec3f(0,-1,0)};
109
		Vec3f norm_pos[] = {Vec3f(0,0, 1), Vec3f( 1,0,0), Vec3f(0, 1,0)};
150
		Vec3f norm_pos[] = {Vec3f(0,0, 1), Vec3f( 1,0,0), Vec3f(0, 1,0)};
Line 145... Line 186...
145
		draw(box.get_aabox());
186
		draw(box.get_aabox());
146
		glPopMatrix();
187
		glPopMatrix();
147
	}
188
	}
148
	
189
	
149
	/** Draw the tree. The first argument is the level counter, the second
190
	/** Draw the tree. The first argument is the level counter, the second
150
	argument is the level at which to stop drawing. */
191
	 argument is the level at which to stop drawing. */
151
	template <class BoxType>
192
	template <class BoxType>
152
	void draw(const Geometry::BoundingINode<BoxType>& node, int level, int max_level)
193
	void draw(const Geometry::BoundingINode<BoxType>& node, int level, int max_level)
153
	{
194
	{
154
		if(level == max_level)
195
		if(level == max_level)
155
		{
196
		{