Bonjour,

Je vais vous exposer mon problème, mais avant tout voici un premier tuto que j'avais fait il y a quelques mois : http://www.developpez.net/forums/d12...leaux-indices/ Il expose déjà le problème très en détail.

J'essaye de me mettre à jour en OpenGL, et j'ai un problème avec les VBO. Je suis en train de recréer un loader d'objets (format .obj). Pour un objet, je dispose de structures Vertex contenant les informations de chaque point :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
struct Vertex {
    double positions[3];
    double normals[3];
    double textcoords[2];
};
Ensuite, j'utilise un tableau de Vertex, nommé Vertices :

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
void  Geometry::createVBO()
{
    // Create and bind a BO for vertex data
    glGenBuffers(1, &vbuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vbuffer);
    glBufferData(GL_ARRAY_BUFFER, (nb_vert)*sizeof(Vertex), Vertices, GL_STATIC_DRAW);
 
    // Create and bind a BO for index data
    glGenBuffers(1, &ibuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, nb_tri*3*sizeof(unsigned int), m_indices3, GL_STATIC_DRAW);
 
    glBindBuffer(GL_ARRAY_BUFFER,0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
 
    // Méthode 2 : Spécification des indices de tableaux
    glBindAttribLocation (m_shaderCouleur.getProgramID(), 0, "in_Vertex") ;
    glBindAttribLocation (m_shaderCouleur.getProgramID(), 1, "in_Normal") ;
    glBindAttribLocation (m_shaderCouleur.getProgramID(), 2, "in_TextCoord") ;
}
 
void Geometry::draw(Matrix4& projection, Matrix4& modelview) const
{
    // Activation du shader et des tableaux Vertex Attrib
    glUseProgram(m_shaderCouleur.getProgramID());
 
    glUniformMatrix4fv(glGetUniformLocation(m_shaderCouleur.getProgramID(), "projection"), 1, GL_TRUE, projection.getValeurs());
    glUniformMatrix4fv(glGetUniformLocation(m_shaderCouleur.getProgramID(), "modelview"), 1, GL_TRUE, modelview.getValeurs());
 
    // Active les Buffers
    glBindBuffer(GL_ARRAY_BUFFER, vbuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer);
 
    // Activation des tableaux génériques
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);
 
    // Envoi des vertices et des matrices
//    glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 0, 0);
 
    glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, positions)));
    glVertexAttribPointer(1, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, normals)));
    glVertexAttribPointer(2, 2, GL_DOUBLE, GL_TRUE,  sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, textcoords)));
 
//    glDrawArrays(GL_TRIANGLES,0,8);
    glDrawElements(GL_TRIANGLES, nb_tri*3, GL_UNSIGNED_INT, 0);
 
    glDisableVertexAttribArray(2);
    glDisableVertexAttribArray(1);
    glDisableVertexAttribArray(0);
 
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
 
    glUseProgram(0);
}
Voici ci dessous le contenu de mon tableau Vertices et du tableau indices : on peut donc voir que tout est ok.

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
Vertices Sructures: 
 
Vertex 1:  	  Positions (-1,-1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 2:  	  Positions (1,-1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 3:  	  Positions (1,1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 4:  	  Positions (1,1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 5:  	  Positions (-1,1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 6:  	  Positions (-1,-1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 7:  	  Positions (1,-1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 8:  	  Positions (1,-1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 9:  	  Positions (1,1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 10:  	  Positions (1,1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 11:  	  Positions (1,1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 12:  	  Positions (1,-1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 13:  	  Positions (-1,-1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 14:  	  Positions (1,-1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 15:  	  Positions (1,-1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 16:  	  Positions (1,-1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 17:  	  Positions (-1,-1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 18:  	  Positions (-1,-1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 19:  	  Positions (-1,-1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 20:  	  Positions (1,-1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 21:  	  Positions (1,1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 22:  	  Positions (1,1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 23:  	  Positions (-1,1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 24:  	  Positions (-1,-1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 25:  	  Positions (-1,-1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 26:  	  Positions (-1,-1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 27:  	  Positions (-1,1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 28:  	  Positions (-1,1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 29:  	  Positions (-1,1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 30:  	  Positions (-1,-1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 31:  	  Positions (-1,1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 32:  	  Positions (1,1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 33:  	  Positions (1,1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 34:  	  Positions (1,1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 35:  	  Positions (-1,1,-1) 	  Normals (0,0,0) 	  Textcoords (0,0)
Vertex 36:  	  Positions (-1,1,1) 	  Normals (0,0,0) 	  Textcoords (0,0)
36 Indices triangles: (0,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,)
glGetError() renvoie 1281 après l'envoi des matrices avec glUniformMatrix4fv(...), ensuite, il repasse à 0.

Certains reconnaitront peut-être le problème, j'ai du arrêté d'y travailler durant plusieurs mois, école d'ing oblige. J'ai beau vérifier les paramètres, tout semble correct, je ne vois pas où est mon erreur.

EDIT : Merci d'avance aux courageux qui se pencheront sur le problème.