Can't use SFML sprite drawing and OpenGL rendering at the same time

Posted by Ken on Game Development See other posts from Game Development or by Ken
Published on 2012-10-13T17:41:26Z Indexed on 2012/10/19 23:24 UTC
Read the original article Hit count: 221

Filed under:
|

I'm using some SFML built in functions to draw sprites and text as an overlay on top of some OpenGL rending in an SFML RenderWindow. The opengl rendering appears fine until I add the code to draw the sprites or text. The sprite or text drawing causes the OpenGL stuff to disappear.

The follow code show what I'm trying to do

sf::RenderWindow window(sf::VideoMode(viewport.width,viewport.height,32), "SFML Window");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(0,viewport.width,0,viewport.height,0,1);

while (window.pollEvent(Event))
    {
    //event handling...

    //begin drawing
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
    glColor3f(col.x,col.y,col.z);
    for(int i=0;i<3;i++)
        glVertex2f(pos.x+verts[i].x,pos.y+verts[i].y);
    glEnd();


    // adding this line causes all the  previous opengl triangles not to appear
    window.draw("Sometext");


    window.display();
}

© Game Development or respective owner

Related posts about opengl

Related posts about sfml