SFML community forums
Help => Graphics => Topic started by: bryce910 on November 21, 2015, 10:18:35 pm
-
Okay so I have been working on this for hours and I simply can not understand what I am doing wrong. All I am trying to do is generate a Triangle in my sfml application and yes I am failing miserably. Can someone explain to me what I am doing wrong?
GLenum err = glewInit();
if (err != GLEW_OK)
{
std::cout << "NOT WORKING" << std::endl;
}
GLuint vertextBuffer;
GLuint vertexArrayID;
glGenVertexArrays(1, &vertexArrayID);
glBindVertexArray(vertexArrayID);
glGenBuffers(1, &vertextBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertextBuffer);
g_vertex_buffer_data.push_back({ -1.0f, -1.0f, 0.0f });
g_vertex_buffer_data.push_back({1.0f, -1.0f, 0.0f});
g_vertex_buffer_data.push_back({ 0.0f, 1.0f, 0.0f });
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), &g_vertex_buffer_data, GL_STATIC_DRAW);
glDrawArrays(GL_TRIANGLES, 0, 3);
gameWindow.pushGLStates();
gameWindow.popGLStates();
I am not able to get anything to show up even for a simple triangle.
This is all the opengl code I use including the draw functions
-
Are you mixing gl with the graphics module? If so check the order in which you push / pop sfml's gl state
http://www.sfml-dev.org/tutorials/2.3/window-opengl.php#using-opengl-together-with-the-graphics-module
-
I have those in the code by the openGL draw sequence:
glDrawArrays(GL_TRIANGLES, 0, 3);
gameWindow.pushGLStates();
gameWindow.popGLStates();
//back to sfml graphics modale drawing
If I use
static const GLfloat g_vertex_buffer_data1[] = {
- 1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
instead of
std::vector<sf::Vector3f> g_vertex_buffer_data;
Then the triangle does draw? Are you not able to use vector3f for verticies?
-
Okay so I got it rendering now but all of the graphics modules I draw are flickering constantly behind the OpenGl object rendered
game.gameWindow.pushGLStates();
game.render(*background);
game.render(*object2);
game.render(*playMenu);
game.render(*quitMenu);
game.gameWindow.popGLStates();
glClear(GL_DEPTH_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertextBuffer);
glVertexAttribPointer(
0,
3,
GL_FLOAT,
GL_TRUE,
0,
(void *)0
);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
game.gameWindow.pushGLStates();
game.gameWindow.popGLStates();
game.gameWindow.display();
-
Hey guys!
After many long hours of working through this I ended up hiring someone to help me fix the problem. Apparently the issue was with my shader::Bind(&shader). Once I switched over to the opengl method of shading the triangle worked and the flickering stopped.