Bonjour, je viens vers vous pour avoir votre avis sur un petit soucis que j'ai..
Je développe en ce moment un petit soft de visualisation de rendu 3D et j'ai un soucis avec simplement afficher un simple triangle..
J'ai deja développé sous OPENGL auparavant mais je ne comprend pas d'ou peut venir mon problème..
Voici les fonction de ma classe mesh que j'appel pour l'affichage du rendu :
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 void Mesh::init(Shader *_shader) { glGenVertexArrays(1,&_vao); glBindVertexArray(_vao); glGenBuffers(1,&_vbo); checkGLError(); //bind des caracteristiques du mesh... glBindBuffer(GL_ARRAY_BUFFER,_vbo); checkGLError(); //On donne nos données au VBO. glBufferData(GL_ARRAY_BUFFER, sizeof(vec3) * Vertices.size(), Vertices.data(), GL_STATIC_DRAW); checkGLError(); int vertex_loc = _shader->getAttribLocation("V_position"); std::cout << "vertex_loc = " << vertex_loc << std::endl; if(vertex_loc>=0) { glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0); glEnableVertexAttribArray(vertex_loc); } int color_loc = _shader->getAttribLocation("V_color"); std::cout << "color_loc = " << color_loc << std::endl; if(color_loc>=0) { glVertexAttribPointer(color_loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)sizeof(vec3)); glEnableVertexAttribArray(color_loc); } int normal_loc = _shader->getAttribLocation("V_normal"); std::cout << "normal_loc = " << normal_loc << std::endl; if(normal_loc>=0) { glVertexAttribPointer(normal_loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(2*sizeof(vec3))); glEnableVertexAttribArray(normal_loc); } if(vertex_loc>=0) glDisableVertexAttribArray(vertex_loc); if(color_loc>=0) glDisableVertexAttribArray(color_loc); if(normal_loc>=0) glDisableVertexAttribArray(normal_loc); glBindVertexArray(0); this->_ready = true; }
Voici comment j'initialise mon screen et mon contexte OPENGL
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 void Mesh::draw(Shader *_shader) { if(!_ready) { init(_shader); std::cout << "Initialisation du mesh terminer" << std::endl; } glBindVertexArray(_vao); glDrawArrays(GL_TRIANGLES, 0,3); glBindVertexArray(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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 bool S2Viewer::init() { /* Initialize the library */ if (!glfwInit()) return -1; // Set all the required options for GLFW glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1); glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); /* Create a windowed mode window and its OpenGL context */ this->_S2viewer = glfwCreateWindow(this->_width,this-> _height, this->_nameScreen, NULL, NULL); if (!_S2viewer) { glfwTerminate(); return 0; } /* Make the window's context current */ glfwMakeContextCurrent(_S2viewer); glewExperimental = GL_TRUE; if(glew_init() == EXIT_FAILURE) { return 0; } return 1; }
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 void S2Viewer::runLoop() { /* Loop until the user closes the window */ glClearColor(1.0, 1.0, 1.0, 0.0); while (!glfwWindowShouldClose(_S2viewer)) { Shaders[0]->use(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for (std::vector<Mesh*>::iterator mesh = Meshs.begin(); mesh < Meshs.end(); mesh++) { (*mesh)->draw(Shaders[0]); } glfwSwapBuffers(_S2viewer); glfwPollEvents(); Shaders[0]->desactivate(); } glfwTerminate(); }
et voici mon main.cpp :
Mon problème de vient pas de mon shader (j'ai deja utilisé ma classe shader sur d'autre projet et elle fonctionne bien ... et plus vertex_loc =2, color_loc =1, et normal_loc = 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 int main(int argc,char** argv) { std::cout << "Hello fuck**g World" <<std::endl; S2Viewer viewer; viewer.init(); //initialisation des shaders et des mesh... Mesh mesh = Mesh("mesh"); Shader shader(DATA_DIR"/data/shader/simple.vert",DATA_DIR"/data/shader/simple.frag"); viewer.addMesh(&mesh); viewer.addShader(&shader); viewer.runLoop(); }
)
et quand j'execute mon programme l'écran s'affiche mais pas le triangle..
Merci pour vos futurs réponse
Partager