Salut à tous,

Voila un problème que j'ai bien du mal à résoudre. Je débute dans l'utilisation du multitexturing et je pense que mon probleme vient de la. J'ai crée un loader de map quake3 utilisant le lightmapping. Le loader fonctionne bien mais j'ai un probleme bizarre. Regardez plutot les photos:

J'ai fait les tests sur 2 maps:
Sur l'image debug.jpg, le programme est compilé en mode debug avec visual C++ et certains objets apparaissent en bleu alors qu'ils ne le devraient pas. En mode release, la meme map et la les objets bleu sont noir(voir release.jpg). Ensuite, Je charge une autre map. Cette fois le comportement en debug et en release est le meme. En placant la camera à une position et en regardant un des objet qui etait en bleu sur l'autre map. Cette fois elle est de la bonne couleur mais suivant l'orientation de la camera, il semble que la luminosité ne soit pas la meme.

Voila le lien des photos:
http://membres.lycos.fr/ps2paradize/debug.JPG
http://membres.lycos.fr/ps2paradize/release.JPG
http://membres.lycos.fr/ps2paradize/...ere%20map2.JPG
http://membres.lycos.fr/ps2paradize/...ere%20map2.JPG

Voila le code des fonctions que j'utilise pour dessiner la map:
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
 
void BSP::Draw()
{
	UpdateDrawing();
	glFrontFace(GL_CW);
 
	//enable vertex arrays
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glClientActiveTextureARB(GL_TEXTURE0_ARB);
 
	//loop through faces
	for(int i=0; i<numTotalFaces; ++i)
	{
		//if this face is to be drawn, draw it
		if(facesToDraw.IsSet(i))
			DrawFace(i);
	}
 
	//disable vertex arrays
	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glClientActiveTextureARB(GL_TEXTURE0_ARB);
 
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
 
	glFrontFace(GL_CCW);
}
 
 
//Draw a face
void BSP::DrawFace(int faceNumber)
{
	//look this face up in the face directory
	if(faceDirectory[faceNumber].faceType==0)
		return;
 
	if(faceDirectory[faceNumber].faceType==bspPolygonFace)
		DrawPolygonFace(faceDirectory[faceNumber].typeFaceNumber);
 
	if(faceDirectory[faceNumber].faceType==bspMeshFace)
		DrawMeshFace(faceDirectory[faceNumber].typeFaceNumber);
 
	if(faceDirectory[faceNumber].faceType==bspPatch)
		DrawPatch(faceDirectory[faceNumber].typeFaceNumber);
}
 
 
//Draw a polygon face
void BSP::DrawPolygonFace(int polygonFaceNumber)
{
	//skip this face if its texture was not loaded
	if(isTextureLoaded[polygonFaces[polygonFaceNumber].textureIndex]==false)
		return;
 
	//set array pointers
	glVertexPointer(	3, GL_FLOAT, sizeof(BSP_VERTEX), &vertices[0].position);
 
	//Unit 0 - decal textures
	glTexCoordPointer(	2, GL_FLOAT, sizeof(BSP_VERTEX), &vertices[0].decalS);
 
	//Unit 1 - Lightmaps
	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glTexCoordPointer(2, GL_FLOAT, sizeof(BSP_VERTEX), &vertices[0].lightmapS);
	glClientActiveTextureARB(GL_TEXTURE0_ARB);
 
 
	//bind textures
	//unit 0 - decal texture
	glBindTexture(GL_TEXTURE_2D, decalTextures[polygonFaces[polygonFaceNumber].textureIndex]);
 
	//unit 1 - lightmap
	glActiveTextureARB(GL_TEXTURE1_ARB);
	if(polygonFaces[polygonFaceNumber].lightmapIndex>=0)	//only bind a lightmap if one exists
		glBindTexture(	GL_TEXTURE_2D,
						lightmapTextures[polygonFaces[polygonFaceNumber].lightmapIndex]);
	else
		glBindTexture(GL_TEXTURE_2D, whiteTexture);
	glActiveTextureARB(GL_TEXTURE0_ARB);
 
	//Draw face
	glDrawArrays(	GL_TRIANGLE_FAN, polygonFaces[polygonFaceNumber].firstVertexIndex,
									 polygonFaces[polygonFaceNumber].numVertices);
}
 
//Draw a mesh face
void BSP::DrawMeshFace(int meshFaceNumber)
{
	//skip this face if its texture was not loaded
	if(isTextureLoaded[meshFaces[meshFaceNumber].textureIndex]==false)
		return;
 
	//set array pointers
	glVertexPointer(	3, GL_FLOAT, sizeof(BSP_VERTEX),
						&vertices[meshFaces[meshFaceNumber].firstVertexIndex].position);
	glTexCoordPointer(	2, GL_FLOAT, sizeof(BSP_VERTEX),
						&vertices[meshFaces[meshFaceNumber].firstVertexIndex].decalS);
 
	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glTexCoordPointer(	2, GL_FLOAT, sizeof(BSP_VERTEX),
						&vertices[meshFaces[meshFaceNumber].firstVertexIndex].lightmapS);
	glClientActiveTextureARB(GL_TEXTURE0_ARB);
 
 
	//bind textures
	//unit 0 - decal texture
	glBindTexture(GL_TEXTURE_2D, decalTextures[meshFaces[meshFaceNumber].textureIndex]);
 
	//unit 1 - lightmap
	glActiveTextureARB(GL_TEXTURE1_ARB);
	if(meshFaces[meshFaceNumber].lightmapIndex>=0)	//only bind a lightmap if one exists
		glBindTexture(GL_TEXTURE_2D, lightmapTextures[meshFaces[meshFaceNumber].lightmapIndex]);
	else
		glBindTexture(GL_TEXTURE_2D, whiteTexture);
	glActiveTextureARB(GL_TEXTURE0_ARB);
 
 
	//draw the face, using meshIndices
	if(!EXT_draw_range_elements_supported)
	{
		glDrawElements(	GL_TRIANGLES, meshFaces[meshFaceNumber].numMeshIndices, GL_UNSIGNED_INT,
						&meshIndices[meshFaces[meshFaceNumber].firstMeshIndex]);
	}
	else
	{
		glDrawRangeElementsEXT(	GL_TRIANGLES, 0, meshFaces[meshFaceNumber].numVertices,
								meshFaces[meshFaceNumber].numMeshIndices, GL_UNSIGNED_INT,
								&meshIndices[meshFaces[meshFaceNumber].firstMeshIndex]);
	}
}
 
//Draw a patch
void BSP::DrawPatch(int patchNumber)
{
	//skip this patch if its texture was not loaded
	if(isTextureLoaded[patches[patchNumber].textureIndex]==false)
		return;
 
	//bind textures
	//unit 0 - decal texture
	glBindTexture(GL_TEXTURE_2D, decalTextures[patches[patchNumber].textureIndex]);
 
	//unit 1 - lightmap
	glActiveTextureARB(GL_TEXTURE1_ARB);
	if(patches[patchNumber].lightmapIndex>=0)	//only bind a lightmap if one exists
		glBindTexture(GL_TEXTURE_2D, lightmapTextures[patches[patchNumber].lightmapIndex]);
	else
		glBindTexture(GL_TEXTURE_2D, whiteTexture);
	glActiveTextureARB(GL_TEXTURE0_ARB);
 
	for(int i=0; i<patches[patchNumber].numQuadraticPatches; ++i)
		patches[patchNumber].quadraticPatches[i].Draw();
}
 
 
//Tesselate a biquadratic patch
bool BSP_BIQUADRATIC_PATCH::Tesselate(int newTesselation)
{
	int row=0;
 
	tesselation=newTesselation;
 
	float px, py;
	BSP_VERTEX temp[3];
	vertices=new BSP_VERTEX[(tesselation+1)*(tesselation+1)];
 
	for(int v=0; v<=tesselation; ++v)
	{
		px=(float)v/tesselation;
 
		vertices[v]=controlPoints[0]*((1.0f-px)*(1.0f-px))+
					controlPoints[3]*((1.0f-px)*px*2)+
					controlPoints[6]*(px*px);
	}
 
	for(int u=1; u<=tesselation; ++u)
	{
		py=(float)u/tesselation;
 
		temp[0]=controlPoints[0]*((1.0f-py)*(1.0f-py))+
				controlPoints[1]*((1.0f-py)*py*2)+
				controlPoints[2]*(py*py);
 
		temp[1]=controlPoints[3]*((1.0f-py)*(1.0f-py))+
				controlPoints[4]*((1.0f-py)*py*2)+
				controlPoints[5]*(py*py);
 
		temp[2]=controlPoints[6]*((1.0f-py)*(1.0f-py))+
				controlPoints[7]*((1.0f-py)*py*2)+
				controlPoints[8]*(py*py);
 
		for(int v=0; v<=tesselation; ++v)
		{
			px=(float)v/tesselation;
 
			vertices[u*(tesselation+1)+v]=	temp[0]*((1.0f-px)*(1.0f-px))+
											temp[1]*((1.0f-px)*px*2)+
											temp[2]*(px*px);
		}
	}
 
	//Create indices
	indices=new GLuint[tesselation*(tesselation+1)*2];
	if(!indices)
	{
		cerr << "Unable to allocate memory for surface indices" << endl;
		return false;
	}
 
	for(row=0; row<tesselation; ++row)
	{
		for(int point=0; point<=tesselation; ++point)
		{
			//calculate indices
			//reverse them to reverse winding
			indices[(row*(tesselation+1)+point)*2+1]=row*(tesselation+1)+point;
			indices[(row*(tesselation+1)+point)*2]=(row+1)*(tesselation+1)+point;
		}
	}
 
 
	//Fill in the arrays for multi_draw_arrays
	trianglesPerRow=new int[tesselation];
	rowIndexPointers=new unsigned int *[tesselation];
	if(!trianglesPerRow || !rowIndexPointers)
	{
		cerr << "Unable to allocate memory for indices for multi_draw_arrays" << endl;
		return false;
	}
 
	for(row=0; row<tesselation; ++row)
	{
		trianglesPerRow[row]=2*(tesselation+1);
		rowIndexPointers[row]=&indices[row*2*(tesselation+1)];
	}
 
	return true;
}
 
 
//Draw a biquadratic patch
void BSP_BIQUADRATIC_PATCH::Draw()
{
	//set array pointers
	glVertexPointer(3, GL_FLOAT, sizeof(BSP_VERTEX), &vertices[0].position);
 
	glTexCoordPointer(2, GL_FLOAT, sizeof(BSP_VERTEX), &vertices[0].decalS);
 
	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glTexCoordPointer(2, GL_FLOAT, sizeof(BSP_VERTEX), &vertices[0].lightmapS);
	glClientActiveTextureARB(GL_TEXTURE0_ARB);
 
	//Draw a triangle strip for each row
	if(!EXT_multi_draw_arrays_supported)
	{
		for(int row=0; row<tesselation; ++row)
		{
			glDrawElements(	GL_TRIANGLE_STRIP, 2*(tesselation+1), GL_UNSIGNED_INT,
							&indices[row*2*(tesselation+1)]);
		}
	}
	else
	{
		glMultiDrawElementsEXT(	GL_TRIANGLE_STRIP, trianglesPerRow,
								GL_UNSIGNED_INT, (const void **)rowIndexPointers,
								tesselation);
	}							
}
 
void BSP::UpdateDrawing(void)
{
	frustum.Update();
 
	glPushAttrib(GL_ALL_ATTRIB_BITS);
 
	//Set states for drawing map
	//Set up texture units
 
	//Unit 0 - replace with decal textures
	glEnable(GL_TEXTURE_2D);
 
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
	//Unit 1
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_2D);
 
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
 
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
 
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
 
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
	glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
 
	/*CamPos.x=GSECamera->GetPositionX();
	CamPos.y=GSECamera->GetPositionY();
	CamPos.z=GSECamera->GetPositionZ();*/
 
	CalculateVisibleFaces(CamPos, frustum);
}
Merci.