Is hope it is not normal for sf::RenderTexture:
http://youtu.be/62WJEN9u5mA
Can I fix it somehow, or what I'm doing wrong ?
Graphics Card: Radeon HD 5570
Lastest drivers.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow app(sf::VideoMode(800,600),"RT Test");
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile("cb.bmp"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
sf::RenderTexture rt;
rt.create(800,600);
sf::Sprite surface(rt.getTexture());
// Start the game loop
while (app.isOpen())
{
// Process events
sf::Event event;
while (app.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
app.close();
}
sprite.move(0.1f,0);
// app.resetGLStates(); // with this, all work
rt.clear(sf::Color::White);
rt.draw(sprite);
rt.display();
// Clear screen
app.clear();
// Draw the sprite
app.draw(surface);
// Update the window
app.display();
}
return 0;
}
Why not.
#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")
#endif // SFML_STATIC
#include <SFML/Graphics.hpp>
#include <SFML\OpenGL.hpp>
#include "include/Defaults.hpp"
#include "include/Debug.hpp"
#include "include/FPS.h"
#include "include/Timer.hpp"
#include "include/Camera.hpp"
#include "include/Animation.hpp"
#include "include/Collision.hpp"
#include "include/Object.hpp"
#include "include/Player.hpp"
#include "include/Scene.hpp"
int main()
{
sf::RenderWindow window(sf::VideoMode(Default::windowWidth, Default::widnowHeight),
Default::windowTitle, Default::windowStyle);
window.setFramerateLimit(60);
Scene test(sf::Vector2f(400,300));
sf::Texture * tex = new sf::Texture();
tex->loadFromFile("gfx/test.png");
Animation anim;
anim.setImage(tex, 64);
anim.setOrigin(32, 32);
Player hero(sf::Vector2f(64,64),anim);
test.add(&hero);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
hero.eventUpdate(event);
}
FPS::update();
window.resetGLStates();
hero.update(FPS::dt);
window.clear(sf::Color::Black);
test.draw(window);
window.display();
}
delete tex;
return 0;
}
Scene::Scene(sf::Vector2f Size)
{
previous = NULL; // previous scene pointer
next = NULL;
name = "";
this->Size = Size;
camera.setCenter(Default::windowWidth / 2, Default::widnowHeight / 2);
surface.create(Size.x,Size.y, true); // sf::RenderTexture
surfaceRenderer.setPosition(0, 0); // sprite for render sf::RenderTexture
surfaceRenderer.setTexture(surface.getTexture());
}
//...
void Scene::draw(sf::RenderWindow & window)
{
surface.clear(sf::Color::White);
surface.draw(objects.back()->getAnimation());
surface.display();
window.draw(surfaceRenderer);
}
By the way, you should not do that:
sf::Texture * tex = new sf::Texture();
... // big amount of code
delete tex;
The reason is that if you later add a return statement in between, or a function throws an exception, you will have memory leaks.
Instead, use RAII (http://www.bromeon.ch/articles/raii.html):
sf::Texture tex;
... // big amount of code