So I'm playing with SFML 2.1 and trying to get a sf::RenderTexture setup and then pass it to a sprite and output it to the window.
So I ran a test and did the following:
call above int main()
sf::Sprite testing() {
//scene main texture
sf::RenderTexture scene_texture;
scene_texture.create( 800,600 );
//top menu section
sf::Texture menubg_texture;
menubg_texture.create( 800, 107 );
if( !menubg_texture.loadFromFile( "Assets/Scenes/Default/background_section.png", sf::IntRect( 0, 0, 800, 107 ) ) ) {
cout << "Couldn't load file" << endl;
}
sf::Sprite menubg_sprite( menubg_texture );
menubg_sprite.setTextureRect( sf::IntRect( 0, 0, 800, 107 ) );
menubg_sprite.setPosition( 0.f, 0.f );
//draw menu to scene
scene_texture.clear( sf::Color( 0, 255, 0 ) );
scene_texture.draw( menubg_sprite );
scene_texture.display();
//sf::Sprite scene_sprite( scene_texture.getTexture() );
sf::Sprite sprite;
sprite.setTexture( scene_texture.getTexture() );
return sprite;
}
The main.cpp main() function
int main() {
sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "Temporary Window", sf::Style::Titlebar | sf::Style::Close );
sf::RectangleShape background( sf::Vector2f(800.f, 600.f) );
background.setPosition( 0.f, 0.f );
background.setFillColor( sf::Color(255, 0, 0) );
// Start the game loop
while ( app_window.isOpen() ) {
// Process events
sf::Event event;
while ( app_window.pollEvent( event ) ) {
// Close window : exit
if ( event.type == sf::Event::Closed ) {
app_window.close();
}
// Mouse Events
if( event.type == sf::Event::MouseMoved ) {
}
if( event.type == sf::Event::MouseButtonPressed ) {
if( sf::Mouse::isButtonPressed( sf::Mouse::Left ) ) {
}
}
}
// Clear screen
app_window.clear( sf::Color( 0, 255, 0) );
//draw stuff
app_window.draw( background );
app_window.draw( testing() );
// Update the window
app_window.display();
}
return EXIT_SUCCESS;
}
So I'm like okay what's going on here. I literally copy the code from the function and replace the:
app_window.draw( testing() ); with the code from above then do: app_window.draw(sprite);
And the image texture loads perfectly. What am I doing wrong or is this a bug with SFML 2.1? About to test SFML 2.0 right now.