Subversion Repositories gelsvn

Rev

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

Rev 370 Rev 374
Line 5... Line 5...
5
// - left mouse down + mouse motion : rotate
5
// - left mouse down + mouse motion : rotate
6
// - Scroll button and +- buttons   : zoom
6
// - Scroll button and +- buttons   : zoom
7
// - right mouse click              : centre trackball
7
// - right mouse click              : centre trackball
8
// - esc                            : exits
8
// - esc                            : exits
9
// - x,y,z buttons                  : switch trackball up axis
9
// - x,y,z buttons                  : switch trackball up axis
-
 
10
// - w                              : toggle wireframe on/off
-
 
11
// - t                              : toggle texture on/off
-
 
12
// - f                              : switch between vertex and face normals
10
// ----------------------------------------
13
// ----------------------------------------
11
 
14
 
12
#if (_MSC_VER >= 1200)
15
#if (_MSC_VER >= 1200)
13
#pragma warning (disable: 4786)
16
#pragma warning (disable: 4786)
14
#endif
17
#endif
Line 24... Line 27...
24
#endif
27
#endif
25
#include <string.h>
28
#include <string.h>
26
#include <stdlib.h>
29
#include <stdlib.h>
27
 
30
 
28
#include <iostream>
31
#include <iostream>
-
 
32
#include <vector>
29
 
33
 
30
#include <Util/ArgExtracter.h>
34
#include <Util/ArgExtracter.h>
31
#include <CGLA/Vec2i.h>
35
#include <CGLA/Vec2i.h>
32
#include <CGLA/Vec2f.h>
36
#include <CGLA/Vec2f.h>
33
#include <CGLA/Vec3f.h>
37
#include <CGLA/Vec3f.h>
Line 59... Line 63...
59
QuatTrackBall* ball;
63
QuatTrackBall* ball;
60
int spin_timer = 20;
64
int spin_timer = 20;
61
void spin(int x);
65
void spin(int x);
62
int main_window;
66
int main_window;
63
TriMesh mesh;
67
TriMesh mesh;
-
 
68
bool do_textures = true;
-
 
69
vector<bool> has_texture;
64
 
70
 
65
void enable_textures(TriMesh& tm)
71
void enable_textures(TriMesh& tm)
66
{
72
{
-
 
73
	for(unsigned int i=0;i<has_texture.size(); ++i)
-
 
74
		tm.materials[i].has_texture = has_texture[i];
-
 
75
}
-
 
76
 
-
 
77
void disable_textures(TriMesh& tm)
-
 
78
{
-
 
79
	for(unsigned int i=0;i<has_texture.size(); ++i)
-
 
80
		tm.materials[i].has_texture = false;
-
 
81
}
-
 
82
 
-
 
83
void load_textures(TriMesh& tm)
-
 
84
{
-
 
85
  has_texture.resize(tm.materials.size());
67
	for(unsigned int i=0;i<tm.materials.size(); ++i)
86
	for(unsigned int i=0;i<tm.materials.size(); ++i)
68
	{
87
	{
69
		Material& mat = tm.materials[i];
88
		Material& mat = tm.materials[i];
70
		if(mat.tex_name != "")
89
		if(mat.tex_name != "")
71
		{
90
		{
72
			string name = mat.tex_path + mat.tex_name;
91
			string name = mat.tex_path + mat.tex_name;
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);
92
			mat.tex_id = SOIL_load_OGL_texture(name.data(), 0, 0, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_POWER_OF_TWO);
-
 
93
      if(mat.tex_id)
-
 
94
        has_texture[i] = true;
74
		}
95
		}
75
	}
96
	}
76
}
97
}
77
 
98
 
78
void load_mesh(const string& fn)
99
void load_mesh(const string& fn)
Line 113... Line 134...
113
	else
134
	else
114
	{
135
	{
115
		cout << "Either the format was unrecognized or the file did not have the appropriate extension" << endl;
136
		cout << "Either the format was unrecognized or the file did not have the appropriate extension" << endl;
116
		exit(0);
137
		exit(0);
117
	}
138
	}
118
	enable_textures(mesh);	
139
  load_textures(mesh);	
119
		
140
  if(!do_textures)
-
 
141
    disable_textures(mesh);		
120
}
142
}
121
 
143
 
122
bool depth_pick(int x, int y,Vec3f& wp)
144
bool depth_pick(int x, int y,Vec3f& wp)
123
{
145
{
124
	// Enquire about the viewport dimensions
146
	// Enquire about the viewport dimensions
Line 242... Line 264...
242
    switch(key)
264
    switch(key)
243
    {
265
    {
244
		case '\033': exit(0); break;
266
		case '\033': exit(0); break;
245
		case 'w': do_wireframe = !do_wireframe; break;
267
		case 'w': do_wireframe = !do_wireframe; break;
246
		case 'f': per_vertex_normals = !per_vertex_normals; redo_display_list = true; break;
268
		case 'f': per_vertex_normals = !per_vertex_normals; redo_display_list = true; break;
-
 
269
    case 't': 
-
 
270
        do_textures = !do_textures; 
-
 
271
        if(do_textures) 
-
 
272
          enable_textures(mesh); 
-
 
273
        else 
-
 
274
          disable_textures(mesh); 
-
 
275
        redo_display_list = true; 
-
 
276
        break;
247
    }
277
    }
248
}
278
}
249
 
279
 
250
 
-
 
251
int main(int argc, char** argv)
280
int main(int argc, char** argv)
252
{
281
{
253
	Util::ArgExtracter ae(argc, argv);
282
	Util::ArgExtracter ae(argc, argv);
254
	
283
	
255
	bool redo_normals = ae.extract("-n");
284
	bool redo_normals = ae.extract("-n");