سؤال

I wanted to display some text in my OpenGL application and was already using SFML for window & context creation. I didn't want to add another library and tried using the text rendering provided by SFML (2.0).

The text that is rendered is consisting out of white rectangles (the rectangles match the height of the char they should display roughly).

Everything else is rendered correctly after I added some methods to keep the OpenGL states the same as they were before using the SFML text. Without those methods nothing gets rendered, but the right color buffer clearing color is used.

I use GLSL for texturing and lighting(can provide source&screenshots if needed).

The code I use:

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();

//rotations for looking around & moving the camera
glRotatef(camera.rotation[0], 1.0f, 0.0f, 0.0f);
glRotatef(camera.rotation[1], 0.0f, 1.0f, 0.0f);
glRotatef(camera.rotation[2], 0.0f, 0.0f, 1.0f);
glTranslatef( -5.0f+camera.translation[0], 
                    camera.translation[1], -7.5f+camera.translation[2]);

//set OpenGL light attributes
passPosition(GL_LIGHT0, spotLight);
passSpotDirection(GL_LIGHT0, spotLight);
passPosition(GL_LIGHT1, greenLight);
passPosition(GL_LIGHT2, redLight);
passPosition(GL_LIGHT3, blueLight);

glUseProgram( shaderProg.getId() );
renderMap();
glUseProgram(0);

window.pushGLStates();//supposed to prevent OpenGL & SFML conflicts 
window.draw(testText);
window.popGLStates();

err = glGetError();//doesn't report any errors
if(err != GL_NO_ERROR)
{
    std::cout << "ERROR: " << err << std::endl;
}

window.display();

The text instance is created like this:

sf::Font fontVera;

std::cout << fontVera.loadFromFile("./res/Vera.ttf") << std::endl;
//the font is existing, output for debugging purposes(and shows no error)

sf::Text testText("hasdfas", fontVera, 32);
testText.setPosition(10,10);

I'am using a 3.3 Compatibilty Profile Context, 3.3 GLSL and 2.0 SFML(compiled from source).

هل كانت مفيدة؟

المحلول

I've switched my font-rendering to ftgl, since I didn't find any way to fix the rendering bug from SFML.

I doubt that i will switch back, because SFML-OpenGL state conflicts seem to be quite widespread:

StackOverflow: SFML OpenGL Drawing Text

SFML-Forums: Crazy bug using OpenGL lighting and RenderWindow

SFML-Forums: glCullFace makes SFML blind

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top