i tried to display some text on screen with simple triangle shape by using opengl but for some reasons that doesn't work with my code. how to fixed this
here my code:
#include <gl/glew.h>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "OpenGL");
window.setActive();
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
return 1;
sf::Font font;
if (!font.loadFromFile("Media/Sansation.ttf"))
return 1;
sf::Text text("test", font);
text.setPosition(5.f, 5.f);
GLuint vboID;
glGenBuffers(1, &vboID);
GLfloat Vertices[] =
{
-1, -1, 0,
0, 1, 0,
1, -1, 0,
};
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
glClearColor(0.f, 0.f, 0.f, 1.f);
while (window.isOpen())
{
sf::Event windowEvent;
while (window.pollEvent(windowEvent))
{
if (windowEvent.type == sf::Event::Closed)
window.close();
}
// opengl drawing
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
// sfml drawing : failed ???????????
window.pushGLStates();
window.draw(text);
window.popGLStates();
window.display();
}
}