Salut à tous,

J'essaye de me mettre aux développement d'application sous openGL ES 2.0.
Pour se faire je tente déjà le basique en dessinant un simple cube. Cependant j'ai en changeant le glOrtho par un glPerspective mon cube disparait et je ne comprends pas pourquoi.

Je ne comprends plus.

Y voyez vous une erreur flagrante :
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
 
 
const GLfloat cubeVertices[] = {
	// face de devant
	-0.5, 0.5, -0.5,             
	-0.5, -0.5, -0.5,           
	0.5, -0.5, -0.5,             
	0.5, 0.5, -0.5,              
 
	// haut
	-0.5, 0.5, -0.5,           
	-0.5, 0.5, 0.5,             
	0.5, 0.5, 0.5,              
	0.5, 0.5, -0.5,             
 
	// arrière
	0.5, 0.5, 0.5,         
	0.5, -0.5, 0.5,           
	-0.5, -0.5, 0.5,           
	-0.5, 0.5, 0.5,            
 
	// dessous
	-0.5, -0.5, 0.5,
	-0.5, -0.5, -0.5,
	0.5, -0.5, -0.5,
	0.5, -0.5, 0.5,
 
	// gauche
	-0.5, 0.5, -0.5,
	-0.5, 0.5, 0.5,
	-0.5, -0.5, 0.5,
	-0.5, -0.5, -0.5,
 
	// droit
	0.5, 0.5, 0.5,
	0.5, 0.5, -0.5,
	0.5, -0.5, -0.5,
	0.5, -0.5, 0.5
}; 
 
static const GLubyte squareColors[] = {
	0, 0, 204, 255,
	0, 204, 0, 255,
	204, 0, 0, 255,
	204, 0, 204, 255,
 
	0, 0, 204, 255,
	0, 204, 0, 255,
	204, 0, 0, 255,
	204, 0, 204, 255,
 
	0, 0, 204, 255,
	0, 204, 0, 255,
	204, 0, 0, 255,
	204, 0, 204, 255,
 
	0, 0, 204, 255,
	0, 204, 0, 255,
	204, 0, 0, 255,
	204, 0, 204, 255,
 
	0, 0, 204, 255,
	0, 204, 0, 255,
	204, 0, 0, 255,
	204, 0, 204, 255,
 
	0, 0, 204, 255,
	0, 204, 0, 255,
	204, 0, 0, 255,
	204, 0, 204, 255,
};
 
 
-(void)render{
 
	Mat4x4 cameraView = Camera::getInstance()->gluLookAtMatrix();
	Mat4x4 proj = Mat4x4::setPerspective((float)(768.0f/1024.0f), 60.0f, 1.0, 20.0f);
 
	//Mat4x4::setOrtho(proj, -4.0f, 4.0f, -6.0f, 6.0f, -4.0f, 4.0f);
 
 
	Mat4x4 rot,trans = Mat4x4::setTranslation(0.0f, 1.0f, 5.0f);
	rot.rotY(r_angle);
 
	Mat4x4 mvp = cameraView * proj * rot * trans;
 
 
 
 
	r_angle += 0.05f;
	glUseProgram([s_loader getProgramIdentifier]);
	glVertexAttribPointer(attribPositionOnShader, 3, GL_FLOAT, 0, 0, cubeVertices);
	glEnableVertexAttribArray(attribPositionOnShader);
	glVertexAttribPointer(attribColorOnShader, 4, GL_UNSIGNED_BYTE, 1, 0, squareColors);
	glEnableVertexAttribArray(attribColorOnShader);
	glUniformMatrix4fv(projMatOnShader, 16, GL_FALSE, mvp.toArray());
 
	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
	glDrawArrays(GL_TRIANGLE_FAN, 4, 4);
	glDrawArrays(GL_TRIANGLE_FAN, 8, 4);
	glDrawArrays(GL_TRIANGLE_FAN, 12, 4);
	glDrawArrays(GL_TRIANGLE_FAN, 16, 4);
	glDrawArrays(GL_TRIANGLE_FAN, 20, 4);
 
	glUseProgram(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
Mat4x4 Mat4x4::setPerspective(float aspect,float fov,float zFar,float zNear){
	Mat4x4 perspectiveMat;
	float f = atanf((fov * M_PI / 180) / 2);
 
	perspectiveMat[0] = f/aspect;	
	perspectiveMat[5] = f;
	perspectiveMat[10] = (zFar - zNear)/(zNear+zFar);
	perspectiveMat[11] = 2 * (zFar * zNear)/(zNear - zFar);
	perspectiveMat[14] = -1;
 
	return perspectiveMat;
 
}
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
 
Camera* Camera::getInstance(){
	if(instance == NULL){
		Point3D pt(0.0f,3.0f,-5.0f);
		Vec3 up(0.0f,1.0f,0.0f);
		Point3D to(0.0f,0.0f,0.0f);
		instance = new Camera(pt,up,to);
	}
 
	return instance;
 
}
 
 
Mat4x4 Camera::gluLookAtMatrix(){
	Vec3 vForward, vUpNorm, vSide;
	Mat4x4 result,translation = Mat4x4::setTranslation(-(*position)[0], -(*position)[1], -(*position)[2]);
	Point3D tmp = *lookAt - *position;
	vForward = tmp.ptToVec();
 
	vForward.normalize();
	vUpNorm = up->normalized();
	vSide   = vUpNorm * vForward;
	vUpNorm = vSide * vForward;
 
	result[0] = vSide[0];		result[1] = vSide[1];		result[2] = vSide[2];		result[3] = 0;
	result[4] = vUpNorm[0];		result[5] = vUpNorm[1];		result[6] = vUpNorm[2];		result[7] = 0;
	result[8] = -vForward[0];	result[9] = -vForward[1];	result[10] = -vForward[2];	result[11] = 0;
	result[12] = 0;				result[13] = 0;				result[14] = 0;				result[15] = 1;
 
 
	result *= translation;
 
	return result;
 
 
}