Alors toujours dans ma quête de l'apprentissage de OpenGL 3.x, GLSL etc...
J'aimerais par exemple dessiner plusieurs rectangles à la suite du genre |Rectangle1|Rectangle2|Rectangle3| ( 3rectangle côte à côte en gros). Donc j'ai bien compris comment fonctionnait les VBO, shaders etc... donc j'ai un rectangle assez facilement avec ce code :
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 init : #define VERTICES 0 #define INDICES 1 #define NUM_BUFFERS 2 /* Define pour spécifier la taille d'un rectangle */ #define LARGEUR 10.0f #define LONGUEUR 20.0f #define EPAISSEUR 1.0f #define ORIGINE 0.0f #define BUFFER_OFFSET(a) ((GLfloat*)NULL + (a)) GLfloat vertices[48] = { ORIGINE, LARGEUR, ORIGINE, 0.20f, 0.60f, 0.60f, ORIGINE, ORIGINE, ORIGINE, 0.20f, 0.60f, 0.60f, ORIGINE, LARGEUR, EPAISSEUR, 0.20f, 0.60f, 0.60f, ORIGINE, ORIGINE, EPAISSEUR, 0.20f, 0.60f, 0.60f, LONGUEUR, LARGEUR, EPAISSEUR, 0.20f, 0.60f, 0.60f, LONGUEUR, ORIGINE, EPAISSEUR, 0.20f, 0.60f, 0.60f, LONGUEUR, LARGEUR, ORIGINE, 0.20f, 0.60f, 0.60f, LONGUEUR, ORIGINE, ORIGINE, 0.20f, 0.60f, 0.60f }; GLuint indices[36] = { 0, 1, 2, 2, 1, 3, 4, 5, 6, 6, 5, 7, 3, 1, 5, 5, 1, 7, 0, 2, 6, 6, 2, 4, 6, 7, 0, 0, 7, 1, 2, 3, 4, 4, 3, 5 }; glGenBuffers(NUM_BUFFERS, buffers); glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTICES]); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[INDICES]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);Mais ce code ne dessine qu'un rectangle on est d'accord et je ne vois pas comment faire pour dessiner plusieurs rectangles différents (donc pas situé au même endroit par contre avec le même gabarit).
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 draw : /* On active le buffer des sommets */ glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTICES]); /* On active les deux tableaux génériques */ glEnableVertexAttribArray(_positionIndex); glEnableVertexAttribArray(_colorIndex); /* On envoie les données sommets et couleurs */ glVertexAttribPointer(_positionIndex, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), BUFFER_OFFSET(0)); glVertexAttribPointer(_colorIndex, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), BUFFER_OFFSET(3)); /* Spécification l'emplacement dans lequel il est possible d'accéder * aux coordonnées spatiales */ glVertexPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), BUFFER_OFFSET(0)); glColorPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), BUFFER_OFFSET(3)); /* activation des tableaux de sommets */ glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); /* On active le buffer des indices */ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[INDICES]); /* Rendu de la géométrie */ glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0); /* Désactivation des buffers vertices et indices */ glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); /* Désactivation des tableaux génériques */ glDisableVertexAttribArray(_positionIndex); glDisableVertexAttribArray(_colorIndex);
Partager