0

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).

genpfault
  • 51,148
  • 11
  • 85
  • 139
Brainbot
  • 365
  • 1
  • 8
  • "I'am using a 3.3 Compatibilty Profile Context, 3.3 GLSL" You're also using ARB_shader_objects, which you should ***never do***. There's no guarantee that you can get GLSL 3.30 with that. You should use core shader functionality, not the extension. I don't know if that's your problem, but it's never a good idea. – Nicol Bolas Sep 28 '12 at 17:02
  • I have replaced the ARB functions, the problem is still there though. – Brainbot Sep 28 '12 at 17:08
  • Does the font contain the characters you are trying to render? Is the font loaded successfully? – cppguy Sep 28 '12 at 18:36
  • Yes to both questions ( no error shows up at least). – Brainbot Sep 29 '12 at 08:29

1 Answers1

0

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

Community
  • 1
  • 1
Brainbot
  • 365
  • 1
  • 8