Subversion Repositories gelsvn

Rev

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

Rev 368 Rev 370
Line 25... Line 25...
25
#include <string.h>
25
#include <string.h>
26
#include <stdlib.h>
26
#include <stdlib.h>
27
 
27
 
28
#include <iostream>
28
#include <iostream>
29
 
29
 
30
#include <IL/il.h>
-
 
31
#include <IL/ilu.h>
30
#include <Util/ArgExtracter.h>
32
 
-
 
33
#include <CGLA/Vec2i.h>
31
#include <CGLA/Vec2i.h>
34
#include <CGLA/Vec2f.h>
32
#include <CGLA/Vec2f.h>
35
#include <CGLA/Vec3f.h>
33
#include <CGLA/Vec3f.h>
36
#include <CGLA/Mat4x4f.h>
34
#include <CGLA/Mat4x4f.h>
37
#include "glsl_shader.h"
35
#include "GLGraphics/glsl_shader.h"
38
#include "GLGraphics/gel_glut.h"
36
#include "GLGraphics/gel_glut.h"
39
#include "GLGraphics/QuatTrackBall.h"
37
#include "GLGraphics/QuatTrackBall.h"
40
#include "GLGraphics/draw.h"
38
#include "GLGraphics/draw.h"
-
 
39
#include "GLGraphics/SOIL.h"
41
#include "Geometry/TriMesh.h"
40
#include "Geometry/TriMesh.h"
42
#include "Geometry/obj_load.h"
41
#include "Geometry/obj_load.h"
-
 
42
#include "Geometry/ply_load.h"
43
#include "HMesh/x3d_load.h"
43
#include "HMesh/x3d_load.h"
-
 
44
#include "HMesh/FaceCirculator.h"
44
#include "ply_load.h"
45
#include "wireframe.h"
45
 
46
 
46
using namespace std;
47
using namespace std;
47
using namespace CGLA;
48
using namespace CGLA;
48
using namespace Geometry;
49
using namespace Geometry;
49
using namespace HMesh;
50
using namespace HMesh;
50
using namespace GLGraphics;
51
using namespace GLGraphics;
51
 
52
 
-
 
53
int win_size_x = 800;
-
 
54
int win_size_y = 800;
-
 
55
bool per_vertex_normals = 1;
-
 
56
bool redo_display_list = 1;
-
 
57
bool do_wireframe = false;
-
 
58
Vec3f line_col = Vec3f(1,0,0);
-
 
59
QuatTrackBall* ball;
-
 
60
int spin_timer = 20;
-
 
61
void spin(int x);
-
 
62
int main_window;
52
namespace
63
TriMesh mesh;
-
 
64
 
-
 
65
void enable_textures(TriMesh& tm)
53
{
66
{
54
	int win_size_x = 800;
-
 
55
	int win_size_y = 800;
-
 
56
	bool per_vertex_normals = 1;
-
 
57
	bool redo_display_list = 1;
-
 
58
	QuatTrackBall* ball;
-
 
59
	int spin_timer = 20;
-
 
60
	void spin(int x);
-
 
61
	int main_window;
-
 
62
	TriMesh mesh;
-
 
63
  bool brute_wire = false;
-
 
64
  bool do_textures = true;
-
 
65
  vector<bool> has_texture;
-
 
66
	
-
 
67
	bool load_image_into_texture(const std::string& name, GLuint& id)
67
	for(unsigned int i=0;i<tm.materials.size(); ++i)
68
	{
68
	{
69
		unsigned char* image = 0;
-
 
70
		unsigned int bpp = 0;
-
 
71
		unsigned int size_x = 0;
-
 
72
		unsigned int size_y = 0;
-
 
73
		unsigned int load_size_x = 0;
-
 
74
		unsigned int load_size_y = 0;
-
 
75
		
-
 
76
		
-
 
77
		ILenum Error;
-
 
78
		ILuint  ImgId;
-
 
79
		
-
 
80
		static bool washere = false;
69
		Material& mat = tm.materials[i];
81
		if(!washere)
-
 
82
		{
-
 
83
			ilInit();
-
 
84
			iluInit();
-
 
85
			washere=true;
-
 
86
		}
-
 
87
		ilEnable(IL_CONV_PAL);
-
 
88
		ilEnable(IL_ORIGIN_SET);
-
 
89
		ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
-
 
90
		ilGenImages(1, &ImgId);
-
 
91
		ilBindImage(ImgId);
-
 
92
		char* name_cstr = const_cast<char*>(name.c_str());
-
 
93
		if(!ilLoadImage(name_cstr))
70
		if(mat.tex_name != "")
94
		{
-
 
95
			cout << "could not load <" << name_cstr  << ">" << endl;
-
 
96
			return false;
-
 
97
		}
-
 
98
		
-
 
99
		load_size_x = ilGetInteger(IL_IMAGE_WIDTH);
-
 
100
		load_size_y = ilGetInteger(IL_IMAGE_HEIGHT);
-
 
101
		bpp = ilGetInteger(IL_IMAGE_BITS_PER_PIXEL);
-
 
102
		
-
 
103
		if (bpp==24)
-
 
104
			ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
-
 
105
		else if (bpp==32)
-
 
106
			ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
-
 
107
		else if (bpp==8)
-
 
108
			ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
-
 
109
		else
-
 
110
			assert(0);
-
 
111
		
-
 
112
		unsigned int i;
-
 
113
		for (i=2;i<=4096 ;i*=2)
-
 
114
			if (i>=load_size_x)
-
 
115
				break;
-
 
116
		size_x = i;
-
 
117
		for (i=2;i<=4096 ;i*=2)
-
 
118
			if (i>=load_size_y)
-
 
119
				break;
-
 
120
		size_y = i;
-
 
121
		
-
 
122
		if(size_x != load_size_x || size_y != load_size_y)
-
 
123
		{
71
		{
124
			iluImageParameter(ILU_FILTER, ILU_BILINEAR);
72
			string name = mat.tex_path + mat.tex_name;
125
			iluScale(size_x, size_y, 1);
73
			mat.tex_id = SOIL_load_OGL_texture(name.data(), 0, 0, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_POWER_OF_TWO);
126
		}
74
		}
-
 
75
	}
-
 
76
}
-
 
77
 
-
 
78
void load_mesh(const string& fn)
-
 
79
{
-
 
80
	if(fn.substr(fn.length()-4,fn.length())==".obj")
-
 
81
	{
-
 
82
		obj_load(fn, mesh);
-
 
83
	}
-
 
84
	else if(fn.substr(fn.length()-4,fn.length())==".ply")
-
 
85
	{
-
 
86
		ply_load(fn, mesh);
-
 
87
	}	
-
 
88
	else if(fn.substr(fn.length()-4,fn.length())==".x3d")
-
 
89
	{
-
 
90
		Manifold m;
-
 
91
		x3d_load(fn, m);
127
		
92
		
128
		const int image_size =size_x*size_y*ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
93
		for(VertexIter v=m.vertices_begin(); v != m.vertices_end();++v)
129
		image = new unsigned char[image_size];
94
			v->touched = mesh.geometry.add_vertex(v->pos);
130
		memcpy(image, ilGetData(), image_size);
-
 
131
		ilDeleteImages(1, &ImgId);
-
 
132
		
-
 
133
		bool any_errors=false;
-
 
134
		while ((Error = ilGetError())) {
-
 
135
			cout << __LINE__ << "Error: " << iluErrorString(Error) << endl;
-
 
136
			any_errors = true;
-
 
137
		}
-
 
138
		if(any_errors) return false;
-
 
139
		
-
 
140
		GLint internalFormat=0;
-
 
141
		GLenum format=0;
-
 
142
		
95
		
143
		glGenTextures(1, &id);
96
		for(FaceIter f = m.faces_begin(); f!= m.faces_end(); ++f)
144
		switch (bpp)
-
 
145
		{
97
		{
146
			case 8:
98
			Vec3i face;
147
				internalFormat =  GL_LUMINANCE;
99
			int i=0;
148
				format = GL_LUMINANCE;
100
			for(FaceCirculator fc(f); !fc.end(); ++fc,++i)
149
				break;
101
			{
150
			case 24:
102
				if(i<2)
151
				internalFormat =  GL_RGB;
103
					face[i] = fc.get_vertex()->touched;
152
				format = GL_RGB;
-
 
153
				break;
104
				else
154
			case 32:
105
				{
-
 
106
					face[2] = fc.get_vertex()->touched;
155
				internalFormat =  GL_RGBA;
107
					mesh.geometry.add_face(face);
156
				format = GL_RGBA;
108
					face[1] = face[2];
157
				break;
109
				}
158
			default:
110
			}	
159
				return false;
-
 
160
		}
111
		}
161
		
-
 
162
		glBindTexture(GL_TEXTURE_2D, id);
-
 
163
		glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, size_x, size_y, 0,
-
 
164
					 format, GL_UNSIGNED_BYTE, image);
-
 
165
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-
 
166
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
 
167
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
 
168
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
 
169
		
-
 
170
		return true;
-
 
171
	}
112
	}
172
	
113
	else
173
	void load_textures(TriMesh& tm)
-
 
174
	{
114
	{
175
    has_texture.resize(tm.materials.size());
-
 
176
		for(unsigned int i=0;i<tm.materials.size(); ++i)
115
		cout << "Either the format was unrecognized or the file did not have the appropriate extension" << endl;
177
		{
-
 
178
			Material& mat = tm.materials[i];
-
 
179
			if(mat.tex_name != "")
-
 
180
			{
-
 
181
				string name = mat.tex_path + mat.tex_name;
-
 
182
				
-
 
183
				GLuint tex_id;
116
		exit(0);
184
				if(load_image_into_texture(name, tex_id))
-
 
185
        {
-
 
186
					mat.tex_id = tex_id;
-
 
187
          has_texture[i] = true;
-
 
188
        }
-
 
189
			}
-
 
190
		}
-
 
191
	}
117
	}
-
 
118
	enable_textures(mesh);	
-
 
119
		
-
 
120
}
-
 
121
 
-
 
122
bool depth_pick(int x, int y,Vec3f& wp)
-
 
123
{
-
 
124
	// Enquire about the viewport dimensions
-
 
125
	GLint viewport[4];
-
 
126
	glGetIntegerv(GL_VIEWPORT, viewport);
-
 
127
	
-
 
128
	// Get the minimum and maximum depth values.
-
 
129
	float minmax_depth[2];
-
 
130
	glGetFloatv(GL_DEPTH_RANGE, minmax_depth);
-
 
131
	
-
 
132
	// Read a single pixel at the position of the mouse cursor.
-
 
133
	float depth;
-
 
134
	glReadPixels(x, viewport[3]-y, 1,1, GL_DEPTH_COMPONENT,
-
 
135
				 GL_FLOAT, (void*) &depth);
-
 
136
	
-
 
137
	// If the depth corresponds to the far plane, we clicked on the
-
 
138
	// background.
-
 
139
	if(depth == minmax_depth[1])
-
 
140
		return false;
-
 
141
	
-
 
142
	// The lines below copy the viewing transformation from OpenGL
-
 
143
	// to local variables. The call to gluLookAt must have exactly
-
 
144
	// the same parameters as when the scene is drawn.
-
 
145
	glLoadIdentity();
-
 
146
	ball->set_gl_modelview();
-
 
147
	double mvmat[16];
-
 
148
	glGetDoublev(GL_MODELVIEW_MATRIX, mvmat);
-
 
149
	
-
 
150
	// Copy the projection matrix. We assume it is unchanged.
-
 
151
	double prjmat[16];
-
 
152
	glGetDoublev(GL_PROJECTION_MATRIX, prjmat);
-
 
153
	
-
 
154
	// Now unproject the point from screen to world coordinates.
-
 
155
	double ox, oy, oz;
-
 
156
	gluUnProject(x,viewport[3]-y,depth,
-
 
157
				 mvmat,prjmat,viewport,
-
 
158
				 &ox, &oy, &oz);
-
 
159
	
-
 
160
	wp = Vec3f(ox,oy,oz);
-
 
161
	
-
 
162
	return true;
-
 
163
}
-
 
164
 
-
 
165
 
192
 
166
 
193
  void enable_textures(TriMesh& tm)
167
void mouse_motion(int x, int y)
-
 
168
{
-
 
169
    ball->roll_ball(Vec2i(x,y));
-
 
170
}
-
 
171
 
-
 
172
void mouse(int btn, int state, int x, int y)
-
 
173
{
-
 
174
	if(state == GLUT_DOWN) 
194
	{
175
	{
-
 
176
		if(btn == GLUT_LEFT_BUTTON) 
-
 
177
			ball->grab_ball(ROTATE_ACTION, Vec2i(x,y));
-
 
178
		else if(btn == GLUT_MIDDLE_BUTTON) 
195
		for(unsigned int i=0;i<has_texture.size(); ++i)
179
			ball->grab_ball(ZOOM_ACTION, Vec2i(x, y));
-
 
180
		else if(btn == GLUT_RIGHT_BUTTON) 
196
			tm.materials[i].has_texture = has_texture[i];
181
			ball->grab_ball(PAN_ACTION, Vec2i(x, y));
197
	}
182
	}
-
 
183
	else if(state == GLUT_UP)
-
 
184
		ball->release_ball();	
-
 
185
}
198
 
186
 
199
  void disable_textures(TriMesh& tm)
187
void spin(int x)
200
	{
188
{
-
 
189
	ball->do_spin();
201
		for(unsigned int i=0;i<has_texture.size(); ++i)
190
	glutTimerFunc(spin_timer, spin, 0);  
-
 
191
	glutPostRedisplay();
-
 
192
}
-
 
193
 
-
 
194
void display()
-
 
195
{
-
 
196
	static unsigned int l;
-
 
197
    if(redo_display_list)
-
 
198
    {
-
 
199
        cout << "Creating display list" << endl;
-
 
200
        l = glGenLists(1);
-
 
201
        glNewList(l, GL_COMPILE);
-
 
202
        draw(mesh, per_vertex_normals);
-
 
203
        glEndList();
202
			tm.materials[i].has_texture = false;
204
        redo_display_list = false;
-
 
205
		glutTimerFunc(spin_timer, spin, 0);	
203
	}
206
	}
-
 
207
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
 
208
    glLoadIdentity();
-
 
209
    ball->set_gl_modelview();
204
	
210
	
205
	void toggle_wire()
211
	if(do_wireframe)
206
	{
212
	{
207
		static bool wire= false;
-
 
208
		static string shader_path = "/Users/jab/SrcTree/Appsrc/wireframepaper/";
-
 
209
		static GLhandleARB prog_P0;
-
 
210
		
-
 
211
    wire = !wire;
-
 
212
 
-
 
213
		static bool washere = false;
213
		if(GLEW_EXT_geometry_shader4)
214
		if(!washere)
-
 
215
		{
214
		{
216
      if(!GLEW_EXT_geometry_shader4)
-
 
217
      {
-
 
218
        brute_wire = !brute_wire;
-
 
219
        redo_display_list = true;
-
 
220
        return;
-
 
221
      }
-
 
222
      
-
 
223
      washere = true;
-
 
224
			
-
 
225
			// Create s	haders directly from file
-
 
226
			GLuint vs = create_glsl_shader(GL_VERTEX_SHADER, shader_path, "tri.vert");
-
 
227
			GLuint gs = create_glsl_shader(GL_GEOMETRY_SHADER_EXT, shader_path, "tri.geom");
-
 
228
			GLuint fs = create_glsl_shader(GL_FRAGMENT_SHADER, shader_path, "tri.frag");
-
 
229
			
-
 
230
			// Create the program
-
 
231
			prog_P0 = glCreateProgram();
215
			enable_wireframe();
232
			
-
 
233
			// Attach all shaders
216
			glCallList(l);
234
			if(vs) glAttachShader(prog_P0, vs);
-
 
235
			if(gs) glAttachShader(prog_P0, gs);
-
 
236
			if(fs) glAttachShader(prog_P0, fs);
-
 
237
			
-
 
238
			// Specify input and output for the geometry shader. Note that this must be
-
 
239
			// done before linking the program.
-
 
240
			glProgramParameteriEXT(prog_P0,GL_GEOMETRY_INPUT_TYPE_EXT,GL_TRIANGLES);
-
 
241
			glProgramParameteriEXT(prog_P0,GL_GEOMETRY_VERTICES_OUT_EXT,3);
-
 
242
			glProgramParameteriEXT(prog_P0,GL_GEOMETRY_OUTPUT_TYPE_EXT,GL_TRIANGLE_STRIP);
-
 
243
			
-
 
244
			// Link the program object and print out the info log
-
 
245
			glLinkProgram(prog_P0);
217
			glUseProgram(0);
246
		}
218
		}
247
		if(wire)
219
		else
248
		{
220
		{
-
 
221
			glDisable(GL_LIGHTING);
249
			glUseProgram(prog_P0);
222
			glColor3f(1,1,1);
-
 
223
			glCallList(l);
-
 
224
			glEnable(GL_POLYGON_OFFSET_LINE);
-
 
225
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
250
			// Set the value of a uniform
226
			glColor3fv(line_col.get());
-
 
227
			glPolygonOffset(0,-5);
-
 
228
			glCallList(l);
-
 
229
			glEnable(GL_LIGHTING);
-
 
230
			glDisable(GL_POLYGON_OFFSET_LINE);
251
			glUniform2f(glGetUniformLocation(prog_P0,"WIN_SCALE"), win_size_x/2.0, win_size_y/2.0);
231
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
252
		}
232
		}
253
		else
-
 
254
			glUseProgram(0);		
-
 
255
	}
233
	}
256
	
-
 
257
	bool depth_pick(int x, int y,Vec3f& wp)
-
 
258
	{
234
	else
259
		// Enquire about the viewport dimensions
-
 
260
		GLint viewport[4];
-
 
261
		glGetIntegerv(GL_VIEWPORT, viewport);
-
 
262
		
-
 
263
		// Get the minimum and maximum depth values.
-
 
264
		float minmax_depth[2];
-
 
265
		glGetFloatv(GL_DEPTH_RANGE, minmax_depth);
-
 
266
		
-
 
267
		// Read a single pixel at the position of the mouse cursor.
-
 
268
		float depth;
-
 
269
		glReadPixels(x, viewport[3]-y, 1,1, GL_DEPTH_COMPONENT,
-
 
270
					 GL_FLOAT, (void*) &depth);
-
 
271
		
-
 
272
		// If the depth corresponds to the far plane, we clicked on the
-
 
273
		// background.
-
 
274
		if(depth == minmax_depth[1])
-
 
275
			return false;
-
 
276
		
-
 
277
		// The lines below copy the viewing transformation from OpenGL
-
 
278
		// to local variables. The call to gluLookAt must have exactly
-
 
279
		// the same parameters as when the scene is drawn.
-
 
280
		glLoadIdentity();
235
		glCallList(l);
281
		ball->set_gl_modelview();
-
 
282
		double mvmat[16];
-
 
283
		glGetDoublev(GL_MODELVIEW_MATRIX, mvmat);
-
 
284
		
-
 
285
		// Copy the projection matrix. We assume it is unchanged.
-
 
286
		double prjmat[16];
-
 
287
		glGetDoublev(GL_PROJECTION_MATRIX, prjmat);
-
 
288
		
-
 
289
		// Now unproject the point from screen to world coordinates.
-
 
290
		double ox, oy, oz;
-
 
291
		gluUnProject(x,viewport[3]-y,depth,
-
 
292
					 mvmat,prjmat,viewport,
-
 
293
					 &ox, &oy, &oz);
-
 
294
		
-
 
295
		wp = Vec3f(ox,oy,oz);
-
 
296
		
236
		
297
		return true;
-
 
298
	}
-
 
299
	
-
 
300
  void mouse_motion(int x, int y)
-
 
301
  {
-
 
302
      ball->roll_ball(Vec2i(x,y));
-
 
303
  }
-
 
304
 
-
 
305
  void mouse(int btn, int state, int x, int y)
-
 
306
  {
-
 
307
	  if(state == GLUT_DOWN) 
-
 
308
	  {
-
 
309
		  if(btn == GLUT_LEFT_BUTTON) 
-
 
310
			  ball->grab_ball(ROTATE_ACTION, Vec2i(x,y));
-
 
311
		  else if(btn == GLUT_MIDDLE_BUTTON) 
-
 
312
			  ball->grab_ball(ZOOM_ACTION, Vec2i(x, y));
-
 
313
		  else if(btn == GLUT_RIGHT_BUTTON) 
-
 
314
			  ball->grab_ball(PAN_ACTION, Vec2i(x, y));
-
 
315
	  }
-
 
316
	  else if(state == GLUT_UP)
-
 
317
		  ball->release_ball();	
-
 
318
  }
-
 
319
 
-
 
320
  void spin(int x)
-
 
321
  {
-
 
322
	  ball->do_spin();
-
 
323
	  glutTimerFunc(spin_timer, spin, 0);  
-
 
324
	  glutPostRedisplay();
-
 
325
  }
-
 
326
 
-
 
327
  void display()
-
 
328
  {
-
 
329
	  static unsigned int l;
-
 
330
      if(redo_display_list)
-
 
331
      {
-
 
332
          cout << "Creating display list" << endl;
-
 
333
          l = glGenLists(1);
-
 
334
          glNewList(l, GL_COMPILE);
-
 
335
          draw(mesh, per_vertex_normals, brute_wire);
-
 
336
          glEndList();
-
 
337
          redo_display_list = false;
-
 
338
		  glutTimerFunc(spin_timer, spin, 0);	
-
 
339
	  }
-
 
340
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
 
341
      glLoadIdentity();
-
 
342
      ball->set_gl_modelview();
-
 
343
      glCallList(l);
-
 
344
      glutSwapBuffers();
237
    glutSwapBuffers();
345
  }
-
 
346
 
-
 
347
  void keyboard(unsigned char key, int x, int y)
-
 
348
  {
-
 
349
      switch(key)
-
 
350
      {
-
 
351
		  case '\033': exit(0);
-
 
352
		  case 'w': toggle_wire(); break;
-
 
353
		  case 'f': per_vertex_normals = !per_vertex_normals; redo_display_list = true; break;
-
 
354
      case 't': 
-
 
355
        do_textures = !do_textures; 
-
 
356
        if(do_textures) 
-
 
357
          enable_textures(mesh); 
-
 
358
        else 
-
 
359
          disable_textures(mesh); 
-
 
360
        redo_display_list = true; 
-
 
361
        break;
-
 
362
      }
-
 
363
  }
-
 
364
}
238
}
365
 
239
 
-
 
240
void keyboard(unsigned char key, int x, int y)
-
 
241
{
-
 
242
    switch(key)
-
 
243
    {
-
 
244
		case '\033': exit(0); break;
-
 
245
		case 'w': do_wireframe = !do_wireframe; break;
-
 
246
		case 'f': per_vertex_normals = !per_vertex_normals; redo_display_list = true; break;
-
 
247
    }
-
 
248
}
-
 
249
 
-
 
250
 
366
int main(int argc, char** argv)
251
int main(int argc, char** argv)
367
{
252
{
-
 
253
	Util::ArgExtracter ae(argc, argv);
-
 
254
	
-
 
255
	bool redo_normals = ae.extract("-n");
-
 
256
 
368
    // GLUT INIT
257
    // GLUT INIT
369
    glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
258
    glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
370
    glutInitWindowSize(win_size_x, win_size_y);
259
    glutInitWindowSize(win_size_x, win_size_y);
371
    glutInit(&argc, argv);
260
    glutInit(&argc, argv);
372
    main_window = glutCreateWindow("OBJ Viewer");
261
    main_window = glutCreateWindow("OBJ Viewer");
Line 374... Line 263...
374
    glutKeyboardFunc(keyboard);
263
    glutKeyboardFunc(keyboard);
375
    glutMotionFunc(mouse_motion);
264
    glutMotionFunc(mouse_motion);
376
    glutMouseFunc(mouse);
265
    glutMouseFunc(mouse);
377
    //glutIdleFunc(idle);
266
    //glutIdleFunc(idle);
378
	
267
	
379
	  glewInit();
268
	glewInit();
380
	
269
	
381
    // GL INIT
270
    // GL INIT
382
    glClearColor(.8f, 0.9f, 1.0f, 0.f);
271
    glClearColor(.8f, 0.9f, 1.0f, 0.f);
383
    glEnable(GL_DEPTH_TEST);
272
    glEnable(GL_DEPTH_TEST);
384
    glEnable(GL_LIGHTING);
273
    glEnable(GL_LIGHTING);
Line 386... Line 275...
386
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
275
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
387
    glShadeModel(GL_SMOOTH);
276
    glShadeModel(GL_SMOOTH);
388
	
277
	
389
    // LOAD OBJ
278
    // LOAD OBJ
390
    string fn;
279
    string fn;
391
    if(argc>1)
280
    if(ae.no_remaining_args())
392
        fn = argv[1];
281
        fn = ae.get_last_arg();
393
    else
282
    else
394
        fn = "../../data/head.obj";
283
        fn = "../../data/head.obj";
-
 
284
	
-
 
285
	load_mesh(fn);	
395
		
286
	
396
	if(fn.substr(fn.length()-4,fn.length())==".obj")
287
	if(!mesh.has_normals() || redo_normals)
397
	{
288
	{
-
 
289
		cout << "Computing normals" << endl;
398
		obj_load(fn, mesh);
290
		mesh.compute_normals();
399
	}
291
	}
400
	else if(fn.substr(fn.length()-4,fn.length())==".ply")
-
 
401
	{
-
 
402
		ply_load(fn, mesh);
-
 
403
	}	
-
 
404
/*	else if(fn.substr(fn.length()-4,fn.length())==".x3d")
-
 
405
	{
-
 
406
		TriMesh mesh;
-
 
407
		Manifold m;
-
 
408
		x3d_load(fn, m);
-
 
409
		for(FaceIter f = m.faces_begin(); f!= m.faces_end(); ++f)
-
 
410
			{
-
 
411
				mesh.
-
 
412
			}
-
 
413
	}	
-
 
414
	*/
-
 
415
	else
-
 
416
	{
-
 
417
		cout << "Either the format was unrecognized or the file did not have the appropriate extension" << endl;
-
 
418
		exit(0);
-
 
419
	}		
-
 
420
    load_textures(mesh);	
-
 
421
    if(!do_textures)
-
 
422
      disable_textures(mesh);
-
 
423
    if(!mesh.has_normals() || (argc > 2 && !strcmp(argv[2], "-n")))
-
 
424
    {
-
 
425
        cout << "Computing normals" << endl;
-
 
426
        mesh.compute_normals();
-
 
427
    }
-
 
428
 
-
 
429
    // Initialize Trackball
-
 
430
    Vec3f c;
-
 
431
    float r;
-
 
432
    mesh.get_bsphere(c,r);
-
 
433
    r *= 1.5;
-
 
434
    ball = new QuatTrackBall(c,r,800,800);
-
 
435
	
292
	
-
 
293
	// Initialize Trackball
-
 
294
	Vec3f c;
-
 
295
	float r;
-
 
296
	mesh.get_bsphere(c,r);
-
 
297
	r *= 1.5;
-
 
298
	ball = new QuatTrackBall(c,r,800,800);
-
 
299
	
436
    // Setup projection
300
	// Setup projection
437
    glMatrixMode(GL_PROJECTION);
301
	glMatrixMode(GL_PROJECTION);
438
    glLoadIdentity();
302
	glLoadIdentity();
439
    gluPerspective(53,1.0f,r/100.0,r*3.0);
303
	gluPerspective(53,1.0f,r/100.0,r*3.0);
440
    glMatrixMode(GL_MODELVIEW);
304
	glMatrixMode(GL_MODELVIEW);
-
 
305
	
-
 
306
	if(GLEW_EXT_geometry_shader4)
-
 
307
		initialize_wireframe_shaders();
-
 
308
			
441
	
309
	
442
    // Pass control to GLUT
310
	// Pass control to GLUT
443
    glutMainLoop();
311
	glutMainLoop();
444
	
312
	
445
    return 0;
313
	return 0;
446
}
314
}