Subversion Repositories gelsvn

Rev

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

Rev 394 Rev 397
Line 24... Line 24...
24
#include <Util/ArgExtracter.h>
24
#include <Util/ArgExtracter.h>
25
 
25
 
26
#include <GL/glew.h>
26
#include <GL/glew.h>
27
#include <GLGraphics/gel_glut.h>
27
#include <GLGraphics/gel_glut.h>
28
#include <GLGraphics/draw.h>
28
#include <GLGraphics/draw.h>
-
 
29
#include <GLGraphics/IDBufferWireFrameRenderer.h>
29
#include <GLGraphics/glsl_shader.h>
30
#include <GLGraphics/glsl_shader.h>
30
#include <GLGraphics/GLViewController.h>
31
#include <GLGraphics/GLViewController.h>
31
 
32
 
32
#include <HMesh/Manifold.h>
33
#include <HMesh/Manifold.h>
33
#include <HMesh/VertexCirculator.h>
34
#include <HMesh/VertexCirculator.h>
Line 60... Line 61...
60
using namespace Util;
61
using namespace Util;
61
using namespace LinAlg;
62
using namespace LinAlg;
62
 
63
 
63
int WINX=800, WINY=800;
64
int WINX=800, WINY=800;
64
 
65
 
-
 
66
template<typename T>
-
 
67
T& get_CVar_ref(const std::string& s)
-
 
68
{
-
 
69
	return *reinterpret_cast<T*> (GetCVarData(s));
-
 
70
}
-
 
71
 
-
 
72
int maximum_face_valency(HMesh::Manifold& m)
-
 
73
{
-
 
74
	int max_val = 0;
-
 
75
	for(FaceIter f = m.faces_begin(); f != m.faces_end(); ++f)
-
 
76
		max_val = max(max_val, no_edges(f));
-
 
77
    return max_val;
-
 
78
}
-
 
79
 
65
class VisObj
80
class VisObj
66
{
81
{
67
	string file;
82
	string file;
68
	GLViewController view_ctrl;
83
	GLViewController view_ctrl;
69
	GLuint display_list;
84
	GLuint display_list;
70
	bool create_display_list;
85
	bool create_display_list;
71
	Manifold mani;
86
	Manifold mani;
72
	Harmonics* harmonics;
87
	Harmonics* harmonics;
-
 
88
	IDBufferWireframeRenderer* idbuff_renderer;
73
	
89
	
74
public:
90
public:
75
	
91
	
76
	Manifold& mesh() {return mani;}
92
	Manifold& mesh() {return mani;}
77
	GLViewController& view_control() {return view_ctrl;}
93
	GLViewController& view_control() {return view_ctrl;}
Line 89... Line 105...
89
		view_ctrl.set_eye_dist(2*r);
105
		view_ctrl.set_eye_dist(2*r);
90
		return true;
106
		return true;
91
	}
107
	}
92
	
108
	
93
	VisObj():
109
	VisObj():
94
	file(""), view_ctrl(WINX,WINY, Vec3f(0), 1.0), display_list(glGenLists(1)), create_display_list(true), harmonics(0) 
110
	file(""), view_ctrl(WINX,WINY, Vec3f(0), 1.0), display_list(glGenLists(1)), create_display_list(true), harmonics(0),
-
 
111
	idbuff_renderer(0)
95
	{
112
	{
96
	}
113
	}
97
	
114
	
98
	void display(bool wire, bool harm, bool flat)
115
	void display(bool wire, bool harm, bool flat)
99
	{
116
	{
100
/*		static Timer tim;
-
 
101
		tim.start();*/
-
 
102
		if(create_display_list)
117
		if(create_display_list)
103
		{
118
		{
104
			create_display_list = false;
119
			create_display_list = false;
105
			
120
			
106
			glNewList(display_list,GL_COMPILE);
121
			glNewList(display_list,GL_COMPILE);
107
			if(wire)
122
			if(wire)
108
			{
123
			{
109
				enable_wireframe();
124
				if(idbuff_renderer)
-
 
125
				{
110
				draw(mani,false);
126
					delete idbuff_renderer;
111
				glUseProgram(0);	
127
					idbuff_renderer = 0;
-
 
128
				}
-
 
129
				if(GLEW_EXT_geometry_shader4)
-
 
130
				   {
-
 
131
					if(maximum_face_valency(mani) > 3)
-
 
132
						idbuff_renderer = new IDBufferWireframeRenderer(WINX, WINY, mani);
-
 
133
					else
-
 
134
						draw_triangles_in_wireframe(mani,!get_CVar_ref<int>("display.flatshading"), Vec3f(1,0,0));
-
 
135
				   }
-
 
136
				else
-
 
137
				   draw_wireframe_oldfashioned(mani,!get_CVar_ref<int>("display.flatshading"), Vec3f(1,0,0));
112
			}
138
			}
113
			else if(harm)
139
			else if(harm)
114
				harmonics->draw();
140
				harmonics->draw();
115
			else 
141
			else 
116
				draw(mani,!flat);
142
				draw(mani,!flat);
117
			glEndList();
143
			glEndList();
118
		}
144
		}
119
		view_ctrl.set_gl_modelview();
145
		view_ctrl.set_gl_modelview();
-
 
146
		if(wire && idbuff_renderer != 0)
-
 
147
			idbuff_renderer->draw(Vec3f(1,0,0),Vec3f(0.5)); 
120
		glCallList(display_list);
148
		glCallList(display_list);
121
		// tim.get_secs();
-
 
122
	}
149
	}
123
	
150
	
124
	
151
	
125
	void post_create_display_list()
152
	void post_create_display_list()
126
	{
153
	{
Line 846... Line 873...
846
			theConsole.StandardKeyBindings( key );
873
			theConsole.StandardKeyBindings( key );
847
		}
874
		}
848
	}
875
	}
849
}
876
}
850
 
877
 
851
template<typename T>
-
 
852
T& get_CVar_ref(const std::string& s)
-
 
853
{
-
 
854
	return *reinterpret_cast<T*> (GetCVarData(s));
-
 
855
}
-
 
856
 
878
 
857
void keyboard(unsigned char key, int x, int y) 
879
void keyboard(unsigned char key, int x, int y) 
858
{	
880
{	
859
	if(theConsole.isOpen())
881
	if(theConsole.isOpen())
860
	{
882
	{
Line 905... Line 927...
905
	}
927
	}
906
}
928
}
907
 
929
 
908
void init_glut(int argc, char** argv)
930
void init_glut(int argc, char** argv)
909
{
931
{
910
	glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
932
	glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH|GLUT_ALPHA);
911
	glutInitWindowSize(WINX, WINY);
933
	glutInitWindowSize(WINX, WINY);
912
	glutInit(&argc, argv);
934
	glutInit(&argc, argv);
913
	glutCreateWindow("Shape Harmonics");
935
	glutCreateWindow("Shape Harmonics");
914
	glutDisplayFunc(display);
936
	glutDisplayFunc(display);
915
	glutKeyboardFunc(keyboard);
937
	glutKeyboardFunc(keyboard);
Line 924... Line 946...
924
{
946
{
925
	glewInit();
947
	glewInit();
926
	glEnable(GL_LIGHTING);
948
	glEnable(GL_LIGHTING);
927
	glEnable(GL_LIGHT0);
949
	glEnable(GL_LIGHT0);
928
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
950
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
929
	
-
 
930
	initialize_wireframe_shaders();
-
 
931
	
-
 
932
	
951
 
933
	// Set the value of a uniform
952
	// Set the value of a uniform
934
	//glUniform2f(glGetUniformLocation(prog_P0,"WIN_SCALE"), win_size_x/2.0, win_size_y/2.0);
953
	//glUniform2f(glGetUniformLocation(prog_P0,"WIN_SCALE"), win_size_x/2.0, win_size_y/2.0);
935
	
954
	
936
	glMatrixMode(GL_MODELVIEW);
955
	glMatrixMode(GL_MODELVIEW);
937
	glLoadIdentity();
956
	glLoadIdentity();