Hi everyone,
I'm trying to render shapes off-screen and then to bind the resulting texture to a simple OpenGL texture.
Unfortunately despite all my efforts (and the numerous snippets I've found on the internet) I just can't make it work properly. I assume it might be an easy slip I've made somewhere and perhaps an external look could help me to sort this out.
Expected result & Current result
sf::RenderWindow window(sf::VideoMode (240, 240), "SFML window");
sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(100, 50));
rectangle.setOutlineColor(sf::Color::Red);
rectangle.setOutlineThickness(5);
rectangle.setPosition(10, 20);
sf::RenderTexture renderText;
renderText.create(240, 240);
renderText.draw(rectangle);
// The main loop - ends as soon as the window is closed
while (window.isOpen())
{
// Event processing
sf::Event event;
while (window.pollEvent(event))
{
// Request for closing the window
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.pushGLStates ();
sf::Texture::bind (&renderText.getTexture ());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, renderText.getTexture ().copyToImage ().getPixelsPtr ());
glBegin(GL_QUADS);
glTexCoord2f(0.f, 1.f);
glVertex2f(0.0f, 1.0f);
glTexCoord2f(1.f, 1.f);
glVertex2f(1.0f, 1.0f);
glTexCoord2f(1.f, 0.f);
glVertex2f(1.0f, 0.0f);
glTexCoord2f(0.f, 0.f);
glVertex2f(0.0f, 0.0f);
glEnd();
window.popGLStates ();
// End the current frame and display its contents on screen
window.display();
}
What am I doing wrong here?
Thank you!