Subversion Repositories gelsvn

Rev

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

Rev 365 Rev 368
Line 58... Line 58...
58
	QuatTrackBall* ball;
58
	QuatTrackBall* ball;
59
	int spin_timer = 20;
59
	int spin_timer = 20;
60
	void spin(int x);
60
	void spin(int x);
61
	int main_window;
61
	int main_window;
62
	TriMesh mesh;
62
	TriMesh mesh;
63
	
-
 
-
 
63
  bool brute_wire = false;
-
 
64
  bool do_textures = true;
-
 
65
  vector<bool> has_texture;
64
	
66
	
65
	bool load_image_into_texture(const std::string& name, GLuint& id)
67
	bool load_image_into_texture(const std::string& name, GLuint& id)
66
	{
68
	{
67
		unsigned char* image = 0;
69
		unsigned char* image = 0;
68
		unsigned int bpp = 0;
70
		unsigned int bpp = 0;
Line 166... Line 168...
166
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
168
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
167
		
169
		
168
		return true;
170
		return true;
169
	}
171
	}
170
	
172
	
171
	void enable_textures(TriMesh& tm)
173
	void load_textures(TriMesh& tm)
172
	{
174
	{
-
 
175
    has_texture.resize(tm.materials.size());
173
		for(unsigned int i=0;i<tm.materials.size(); ++i)
176
		for(unsigned int i=0;i<tm.materials.size(); ++i)
174
		{
177
		{
175
			Material& mat = tm.materials[i];
178
			Material& mat = tm.materials[i];
176
			if(mat.tex_name != "")
179
			if(mat.tex_name != "")
177
			{
180
			{
178
				string name = mat.tex_path + mat.tex_name;
181
				string name = mat.tex_path + mat.tex_name;
179
				
182
				
180
				GLuint tex_id;
183
				GLuint tex_id;
181
				if(load_image_into_texture(name, tex_id))
184
				if(load_image_into_texture(name, tex_id))
-
 
185
        {
182
					mat.tex_id = tex_id;
186
					mat.tex_id = tex_id;
-
 
187
          has_texture[i] = true;
183
			}
188
        }
184
		}
189
			}
185
	}
190
		}
-
 
191
	}
-
 
192
 
-
 
193
  void enable_textures(TriMesh& tm)
-
 
194
	{
-
 
195
		for(unsigned int i=0;i<has_texture.size(); ++i)
-
 
196
			tm.materials[i].has_texture = has_texture[i];
-
 
197
	}
-
 
198
 
-
 
199
  void disable_textures(TriMesh& tm)
-
 
200
	{
-
 
201
		for(unsigned int i=0;i<has_texture.size(); ++i)
-
 
202
			tm.materials[i].has_texture = false;
-
 
203
	}
186
	
204
	
187
	void toggle_wire()
205
	void toggle_wire()
188
	{
206
	{
189
		static bool wire= false;
207
		static bool wire= false;
190
		static string shader_path = "/Users/jab/SrcTree/Appsrc/wireframepaper/";
208
		static string shader_path = "/Users/jab/SrcTree/Appsrc/wireframepaper/";
191
		static GLhandleARB prog_P0;
209
		static GLhandleARB prog_P0;
192
		
210
		
193
		wire = !wire;
211
    wire = !wire;
-
 
212
 
194
		static bool washere = false;
213
		static bool washere = false;
195
		if(!washere)
214
		if(!washere)
196
		{
215
		{
-
 
216
      if(!GLEW_EXT_geometry_shader4)
-
 
217
      {
-
 
218
        brute_wire = !brute_wire;
-
 
219
        redo_display_list = true;
-
 
220
        return;
-
 
221
      }
-
 
222
      
197
			washere = true;
223
      washere = true;
198
			
224
			
199
			// Create s	haders directly from file
225
			// Create s	haders directly from file
200
			GLuint vs = create_glsl_shader(GL_VERTEX_SHADER, shader_path, "tri.vert");
226
			GLuint vs = create_glsl_shader(GL_VERTEX_SHADER, shader_path, "tri.vert");
201
			GLuint gs = create_glsl_shader(GL_GEOMETRY_SHADER_EXT, shader_path, "tri.geom");
227
			GLuint gs = create_glsl_shader(GL_GEOMETRY_SHADER_EXT, shader_path, "tri.geom");
Line 269... Line 295...
269
		wp = Vec3f(ox,oy,oz);
295
		wp = Vec3f(ox,oy,oz);
270
		
296
		
271
		return true;
297
		return true;
272
	}
298
	}
273
	
299
	
274
 
-
 
275
 
-
 
276
void mouse_motion(int x, int y)
300
  void mouse_motion(int x, int y)
277
{
301
  {
278
    ball->roll_ball(Vec2i(x,y));
302
      ball->roll_ball(Vec2i(x,y));
279
}
303
  }
280
 
304
 
Line 306... Line 330...
306
    if(redo_display_list)
330
      if(redo_display_list)
307
    {
331
      {
308
        cout << "Creating display list" << endl;
332
          cout << "Creating display list" << endl;
309
        l = glGenLists(1);
333
          l = glGenLists(1);
310
        glNewList(l, GL_COMPILE);
334
          glNewList(l, GL_COMPILE);
311
        draw(mesh, per_vertex_normals);
335
          draw(mesh, per_vertex_normals, brute_wire);
312
        glEndList();
336
          glEndList();
313
        redo_display_list = false;
337
          redo_display_list = false;
314
		glutTimerFunc(spin_timer, spin, 0);	
338
		  glutTimerFunc(spin_timer, spin, 0);	
315
	}
339
	  }
316
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
340
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Line 322... Line 346...
322
 
346
 
323
void keyboard(unsigned char key, int x, int y)
347
  void keyboard(unsigned char key, int x, int y)
324
{
348
  {
325
    switch(key)
349
      switch(key)
326
    {
350
      {
327
		case '\033': exit(0); break;
351
		  case '\033': exit(0);
328
		case 'w': toggle_wire(); break;
352
		  case 'w': toggle_wire(); break;
329
		case 'f': per_vertex_normals = !per_vertex_normals; redo_display_list = true; 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;
330
    }
362
      }
331
}
363
  }
332
}
364
}
333
 
365
 
334
int main(int argc, char** argv)
366
int main(int argc, char** argv)
Line 383... Line 415...
383
	else
415
	else
384
	{
416
	{
385
		cout << "Either the format was unrecognized or the file did not have the appropriate extension" << endl;
417
		cout << "Either the format was unrecognized or the file did not have the appropriate extension" << endl;
386
		exit(0);
418
		exit(0);
387
	}		
419
	}		
388
    enable_textures(mesh);	
420
    load_textures(mesh);	
389
    if(!mesh.has_normals())
421
    if(!do_textures)
-
 
422
      disable_textures(mesh);
-
 
423
    if(!mesh.has_normals() || (argc > 2 && !strcmp(argv[2], "-n")))
390
    {
424
    {
391
        cout << "Computing normals" << endl;
425
        cout << "Computing normals" << endl;
392
        mesh.compute_normals();
426
        mesh.compute_normals();
393
    }
427
    }
394
 
428