Salut a tous,
J'ai un problème avec ma liste d'affichage, mais je ne sais pas où, alors si quelqu'un voudrai bien m'aider...
Voila mon code :
LoaderOBJ.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef	LOADER_OBJ_H
#define LOADER_OBJ_H
 
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>	//Gestion de Fichier : General
#include <limits>	//Gestion de Fichier : Saut de ligne
 
#include "PointsOBJ.h"
 
using namespace std;
 
typedef struct obj_info	//Info sur le contenue principal du fichier
{
	int v;
	int vn;
	int vt;
	int f;
};
 
 
class ObjLoader
{
	public:
		ObjLoader(string fichier);
		~ObjLoader();
 
		static obj_info info;
		Points_obj *points;
		Points_obj *normals;
		void draw();
		static string file;
		static string name;
 
	protected:
		int vertex();
		int normal();
		int texture();
		int face();
		void obj();
		void draw_list();
		int toint(char str);
		GLuint object;
		void dessin();
};
 
#endif
LoaderOBJ.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
#include "LoaderOBJ.h"
 
string ObjLoader::file = "";
string ObjLoader::name = "";
obj_info ObjLoader::info;
 
ObjLoader::ObjLoader(string fichier)
{
	file = fichier.c_str();
	//Initialisation du Struct
	info.v = vertex();
	info.vn = normal();
	info.vt = texture();
	info.f = face();
	try
	{
		points = new Points_obj(face());
		normals = new Points_obj(face());
		/*
			Ici "PX, PY, PZ" --> s'applique au groupe de points X
			Ici "SX, SY, SZ" --> s'applique au groupe de points Y
			Ici "TX, TY, TZ" --> s'applique au groupe de points Z
		*/
	}
	catch ( const std::exception & Exp )
	{
	    cerr << "Erreur : " << Exp.what() << ".\n";
	}
 
	/*Récupération du nom de l'obj (a partie de son nome de fichier, 
	le nom DANS l'obj n'étant jamais très sûr*/
	bool OK = true;
	int count = 0;
	for(int nm = (file.length()-1); OK; nm--)
	{
		if(file[nm] != '/')
		{
			count++;
		}
		else
		{
			for(int c = ((file.length())-count); c<=(file.length()-1); c++)
			{
				name += file[c];
				OK = false;
			}
		}
	}
 
	//Lancement de la procédure d'import :
	obj();
 
}
 
ObjLoader::~ObjLoader()
{
	delete normals;
	delete points;
}
 
void ObjLoader::obj()
{
	ifstream fichier(file.c_str(), ios::in);
	int len = (file.length()-1);
 
	if(fichier == NULL)	//Si le fichier ne peut être ouvert et/ou lu.
	{
		cout<<"+=========================================+"<<endl;
		cout<<"| /!\\ LE FICHIER NE PEUT ETRE OUVERT /!\\  |"<<endl;
		cout<<"+=========================================+"<<endl;
	}
	else
	{
		if(file[len-2] != 'o' && file[len-1] != 'b' && file[len] != 'j')
		{		
			cout<<"+=========================================+"<<endl;
			cout<<"|   /!\\ LE FICHIER N'EST PAS VALIDE /!\\   |"<<endl;
			cout<<"+=========================================+"<<endl;
		}
		else
		{
			if(1)//Execution normale de la lecture
			{
					//La variable 'first' récupère le premier caractère, si c'est 'v' alors il lit
					//les coordonnées qui suivent puis les appliquent
				bool boucle = true;
				int Refx = 0;
				int Refy = 0;
				int Refz = 0;
				int Norx = 0;
				int Nory = 0;
				int Norz = 0;
				string Argx;
				string Argy;
				string Argz;
				int iboucle = 0;
				string x, y, z;
				string first;
				int nbr_v = info.v;
				int nbr_vn = info.vn;
				int nbr_f = info.f;
 
				cout<<"Vertex repertories : "<<info.v<<endl;
				cout<<"Normals repertorie : "<<info.vn<<endl;
				cout<<"Face totals : "<<info.f<<endl;
				system("PAUSE");
				float Vx[nbr_v];
				float Vy[nbr_v];
				float Vz[nbr_v];
 
				float VNx[nbr_vn];
				float VNy[nbr_vn];
				float VNz[nbr_vn];
 
				//Entrer des information Vertex dans les array précédement initialisés
				nbr_v = 0;
				nbr_vn = 0;
				fichier.clear();	//Réinitialise les 4 flags.
				fichier.seekg(0, ios::beg);	//Met le 'curseur' a 0.
				while(fichier.eof() != true)
				{
					fichier >> first;
					if(first == "v")
					{
						fichier >> Vx[nbr_v] >> Vy[nbr_v] >> Vz[nbr_v];
						nbr_v++;
					}
					if(first == "vn")
					{
						fichier >> VNx[nbr_vn] >> VNy[nbr_vn] >> VNz[nbr_vn];
						nbr_vn++;
					}
					fichier.ignore(numeric_limits<int>::max(), '\n');	//Saut de ligne
				}
 
				fichier.clear();	//Réinitialise les 4 flags.
				fichier.seekg(0, ios::beg);	//Met le 'curseur' a 0.
				int i_struct = 0;
				while(fichier.eof() != true)
				{
					Refx = 0;
					Refy = 0;
					Refz = 0;
					Norx = 0;
					Nory = 0;
					Norz = 0;
					iboucle = 0;
					boucle = true;
					fichier >> first;
					if(first == "f")
					{
					//system("PAUSE");
						fichier >> Argx >> Argy >> Argz;
						//cout<<"Args : "<<Argx<<", "<<Argy<<", "<<Argz<<"."<<endl;
 
						//========= X AND NORMAL=========
							//Vertex
							while(boucle)
							{
								if(Argx[iboucle] == '/')
								{
									boucle = false;
								}
								else
								{
									Refx = (Refx*10)+toint(Argx[iboucle]);
								}
								iboucle++;
							}
							//Normal
							boucle = true;
							while(boucle)
							{
								if(Argx[iboucle] == '/')
								{
									iboucle++;
									while(boucle)
									{
										if(Argx[iboucle] == '\0')
										{
											boucle = false;
										}
										else
										{
											Norx = (Norx*10)+toint(Argx[iboucle]);
										}
										iboucle++;
									}
								}
								iboucle++;
							}
							//Synthèse X :
								normals->value(i_struct, PX, VNx[Norx-1]);
								normals->value(i_struct, PY, VNy[Norx-1]);
								normals->value(i_struct, PZ, VNz[Norx-1]);
								points->value(i_struct, PX, Vx[Refx-1]);
								points->value(i_struct, PY, Vy[Refx-1]);
								points->value(i_struct, PZ, Vz[Refx-1]);
							//glNormal3f(VNx[Norx-1], VNy[Norx-1], VNz[Norx-1]);
							//glVertex3f(Vx[Refx-1], Vy[Refx-1], Vz[Refx-1]);
						//========= Y AND NORMAL=========
							//Vertex
							boucle = true;
							iboucle = 0;
							while(boucle)
							{
								if(Argy[iboucle] == '/')
								{
 
									boucle = false;
								}
								else
								{
									Refy = (Refy*10)+toint(Argy[iboucle]);
								}
								iboucle++;
							}
							//normal
							boucle = true;
							while(boucle)
							{
								if(Argy[iboucle] == '/')
								{
									iboucle++;
									while(boucle)
									{
										if(Argy[iboucle] == '\0')
										{
											boucle = false;
										}
										else
										{
											Nory = (Nory*10)+toint(Argy[iboucle]);
										}
										iboucle++;
									}
								}
								iboucle++;
							}
							//Synthèse Y :
								normals->value(i_struct, SX, VNx[Nory-1]);
								normals->value(i_struct, SY, VNy[Nory-1]);
								normals->value(i_struct, SZ, VNz[Nory-1]);
								points->value(i_struct, SX, Vx[Refy-1]);
								points->value(i_struct, SY, Vy[Refy-1]);
								points->value(i_struct, SZ, Vz[Refy-1]);
							//glNormal3f(VNx[Nory-1], VNy[Nory-1], VNz[Nory-1]);
							//glVertex3f(Vx[Refy-1], Vy[Refy-1], Vz[Refy-1]);
						//========= Z AND NORMAL=========
							//vertex
							boucle = true;
							iboucle = 0;
							while(boucle)
							{
 
								if(Argz[iboucle] == '/')
								{
									boucle = false;
								}
								else
								{
									Refz = (Refz*10)+toint(Argz[iboucle]);
								}
								iboucle++;
							}
							//normal
							boucle = true;
							while(boucle)
							{
								if(Argz[iboucle] == '/')
								{
									iboucle++;
									while(boucle)
									{
										if(Argz[iboucle] == '\0')
										{
											boucle = false;
										}
										else
										{
											Norz = (Norz*10)+toint(Argz[iboucle]);
										}
										iboucle++;
									}
								}
								iboucle++;
							}
							//Synthèse Z :
								normals->value(i_struct, TX, VNx[Norz-1]);
								normals->value(i_struct, TY, VNy[Norz-1]);
								normals->value(i_struct, TZ, VNz[Norz-1]);
								points->value(i_struct, TX, Vx[Refz-1]);
								points->value(i_struct, TY, Vy[Refz-1]);
								points->value(i_struct, TZ, Vz[Refz-1]);
							//glNormal3f(VNx[Norz-1], VNy[Norz-1], VNz[Norz-1]);
							//glVertex3f(Vx[Refz-1], Vy[Refz-1], Vz[Refz-1]);
						//===========END VERTEX AND NORMAL=========
						i_struct++;
					}
					fichier.ignore(numeric_limits<int>::max(), '\n');	//Saut de ligne
				}
				draw_list();
			}
		}
	}
	fichier.close();
	//points->free();
}
 
int ObjLoader::toint(char str)
{
	switch(str)
	{
		case '1':
			return 1;
			break;
		case '2':
			return 2;
			break;
		case '3':
			return 3;
			break;
		case '4':
			return 4;
			break;
		case '5':
			return 5;
			break;
		case '6':
			return 6;
			break;
		case '7':
			return 7;
			break;
		case '8':
			return 8;
			break;
		case '9':
			return 9;
			break;
		default :
		case '0':
			return 0;
			break;
	}
}
 
int ObjLoader::vertex()
{
	string lettre;
	int vertex = 0;
	//Ouverture du fichier pour obtenir le nombre de ligne Vertex
	ifstream fichier(file.c_str(), ios::in);
	int len = (file.length()-1);
 
	if(fichier == NULL)	//Si le fichier ne peut être ouvert et/ou lu.
	{
		cout<<"+=========================================+"<<endl;
		cout<<"| /!\\ LE FICHIER NE PEUT ETRE OUVERT /!\\  |"<<endl;
		cout<<"+=========================================+"<<endl;
		return 0;
	}
	else
	{
		if(file[len-2] != 'o' && file[len-1] != 'b' && file[len] != 'j')
		{		
			cout<<"+=========================================+"<<endl;
			cout<<"|   /!\\ LE FICHIER N'EST PAS VALIDE /!\\   |"<<endl;
			cout<<"+=========================================+"<<endl;
			return 0;
		}
		else
		{
			while(!fichier.eof())
			{
				fichier >> lettre;
				if(lettre == "v")
				{
					vertex++;
				}
				fichier.ignore(numeric_limits<int>::max(), '\n');	//Saut de ligne
				}
			fichier.close();
			return vertex;
		}
	}
 
 
}
 
int ObjLoader::normal()
{
	string lettre;
	int normal = 0;
	//Ouverture du fichier pour obtenir le nombre de normal
	ifstream fichier(file.c_str(), ios::in);
	int len = (file.length()-1);
 
	if(fichier == NULL)	//Si le fichier ne peut être ouvert et/ou lu.
	{
		cout<<"+=========================================+"<<endl;
		cout<<"| /!\\ LE FICHIER NE PEUT ETRE OUVERT /!\\  |"<<endl;
		cout<<"+=========================================+"<<endl;
		return 0;
	}
	else
	{
		if(file[len-2] != 'o' && file[len-1] != 'b' && file[len] != 'j')
		{		
			cout<<"+=========================================+"<<endl;
			cout<<"|   /!\\ LE FICHIER N'EST PAS VALIDE /!\\   |"<<endl;
			cout<<"+=========================================+"<<endl;
			return 0;
		}
		else
		{
			while(!fichier.eof())
			{
				fichier >> lettre;
				if(lettre == "vn")
				{
					normal++;
				}
				fichier.ignore(numeric_limits<int>::max(), '\n');	//Saut de ligne	
			}
			fichier.close();
			return normal;
		}
	}
}
 
 
int ObjLoader::texture()
{
	string lettre;
	int texture = 0;
	//Ouverture du fichier pour obtenir le nombre de normal
	ifstream fichier(file.c_str(), ios::in);
	int len = (file.length()-1);
 
	if(fichier == NULL)	//Si le fichier ne peut être ouvert et/ou lu.
	{
		cout<<"+=========================================+"<<endl;
		cout<<"| /!\\ LE FICHIER NE PEUT ETRE OUVERT /!\\  |"<<endl;
		cout<<"+=========================================+"<<endl;
		return 0;
	}
	else
	{
		if(file[len-2] != 'o' && file[len-1] != 'b' && file[len] != 'j')
		{		
			cout<<"+=========================================+"<<endl;
			cout<<"|   /!\\ LE FICHIER N'EST PAS VALIDE /!\\   |"<<endl;
			cout<<"+=========================================+"<<endl;
			return 0;
		}
		else
		{
			while(!fichier.eof())
			{
				fichier >> lettre;
				if(lettre == "vt")
				{
					texture++;
				}
				fichier.ignore(numeric_limits<int>::max(), '\n');	//Saut de ligne	
			}
			fichier.close();
			return texture;
		}
	}
}
 
int ObjLoader::face()
{
	string lettre;
	int face = 0;
	//Ouverture du fichier pour obtenir le nombre de normal
	ifstream fichier(file.c_str(), ios::in);
	int len = (file.length()-1);
 
	if(fichier == NULL)	//Si le fichier ne peut être ouvert et/ou lu.
	{
		cout<<"+=========================================+"<<endl;
		cout<<"| /!\\ LE FICHIER NE PEUT ETRE OUVERT /!\\  |"<<endl;
		cout<<"+=========================================+"<<endl;
		return 0;
	}
	else
	{
		if(file[len-2] != 'o' && file[len-1] != 'b' && file[len] != 'j')
		{		
			cout<<"+=========================================+"<<endl;
			cout<<"|   /!\\ LE FICHIER N'EST PAS VALIDE /!\\   |"<<endl;
			cout<<"+=========================================+"<<endl;
			return 0;
		}
		else
		{
			while(!fichier.eof())
			{
				fichier >> lettre;
				if(lettre == "f")
				{
					face++;
				}
				fichier.ignore(numeric_limits<int>::max(), '\n');	//Saut de ligne	
			}
			fichier.close();
			return face;
		}
	}
}
 
 
void ObjLoader::draw_list()
{
 
	/*La fonction reécupère le donné qui se trouve dans les différent tableau de la Structure
	Perso. Puis les met en application dans glNormal, glVertex,...
 
	Puis met le tout dans une Liste d'affichage qui se charge de rendre le tout fluide)
	*/
	try
	{
		object = glGenLists(1);
		cout<<object<<endl;
		glNewList(object, GL_COMPILE_AND_EXECUTE);	//Création/Début de la Liste d'affichage
			dessin();
		glEndList();	//Fin liste d'affichage
		cout<<"/*\\Le fichier, \""<<name<<"\" a ete importe avec succee /*\\"<<endl;
	}
	catch(...)
	{
		cout<<"/!\\ERREUR DANS L'IMPORT DU FICHIER : "<<name<<" /!\\"<<endl;
	}
 
}
 
void ObjLoader::draw()
{
	cout<<object<<endl;
	glCallList(object);
	cout<<"Dessin en cours"<<endl;
}
 
void ObjLoader::dessin()
{
			for(int d = 0; d<=face(); d++)
			{
				glBegin(GL_TRIANGLES);
					glNormal3f(normals->getValue(d, PX), normals->getValue(d, PY), normals->getValue(d, PZ));
					glVertex3f(points->getValue(d, PX), points->getValue(d, PY), points->getValue(d, PZ));
					glNormal3f(normals->getValue(d, SX), normals->getValue(d, SY), normals->getValue(d, SZ));
					glVertex3f(points->getValue(d, SX), points->getValue(d, SY), points->getValue(d, SZ));
					glNormal3f(normals->getValue(d, TX), normals->getValue(d, TY), normals->getValue(d, TZ));
					glVertex3f(points->getValue(d, TX), points->getValue(d, TY), points->getValue(d, TZ));
				glEnd();
			}
}
Je ne sais vraiment pas ou est le problème...(ici vous avez la classe qui importe un obj).

Je tiens a m'excuser si mon message a l'air assez "cru", mais je vous assure que ce n'est pas le cas