I cannot print text and opengl primitives to screen at the same time.
In the code below simply comment out the call for drawing text to screen in order to see the triangle.
#include <stdio.h>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <GL/gl.h>
#include <GL/glu.h>
int main() {
sf::RenderWindow window(sf::VideoMode(800, 800), "SFML window");
sf::Font font;
if (!font.loadFromFile("tahoma.ttf"))
return EXIT_FAILURE;
sf::Text text("Hello SFML", font, 50);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, 2.f, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
while (window.isOpen()) {
window.setActive();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
window.close();
}
window.clear();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
. glTranslatef(0.f,0.0f,-6.0f);
//COMMENT OUT THIS LINE
window.draw(text);
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd();
window.display();
}
return EXIT_SUCCESS;
}
So if I comment out the "window.draw(text)" line, then I can see a triangle on screen. If I don't comment it out, I see the text "Hello SMFL" without a triangle on screen.
What am I doing wrong?
Fedora 15
SFML 2.0