1
Graphics / BUG - Bad Text Display
« on: January 19, 2012, 12:59:30 pm »
ok, thanks for your answer
Anyway to fix it temporarily ?
Anyway to fix it temporarily ?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Quote from: "Laurent"I'll see if I can flush contexts internally, when switching contexts, and if it doesn't impact performances too much.If the performances are too reduced maybe we can do it only on Mac, or, to be more precise : only on Mac until this issue appears on other OSes.
BTW, I tried on Nvidia GPU. It might work on ATI GPU (maybe) but I can't test that.
But I don't know why it happens only on OS X... I guess that other drivers are more clever
Adding "window.Display();" before "rt.Clear();" makes it works. Still no idea why. Will spend some time on this issue ASAP (but exams first!).
Can you try to add calls to glFlush() after or before drawing to the render-texture?
I noticed you clear your rendertexture using sf::Color::Transparent. Try clearing it with a solid color or without arguments
Since it's a Mac OS X only bug, I cannot help. We'd need someone with a Mac and OpenGL/debugging skills.
Quoteby the way, I tried on 2 macbook pro with different graphic cards
And it works? Or not?
Have you tried on PCs (Linux or Windows)?
while (Window_->IsOpen())
{
sf::Event event;
while (Window_->PollEvent(event))
{
if (event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Keyboard::Escape)
{
Window_->Close();
break;
}
}
Window_->Clear();
Window_->Draw(*sprite);
Window_->Display();
}
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
int main()
{
// Adjust these two variables to your screen resolution
int Width_ = 1680;
int Height_ = 1050;
float ElapsedTime_;
// Creating the sf::RenderWindow
sf::RenderWindow *Window_ = new sf::RenderWindow(sf::VideoMode(Width_, Height_), "Title", sf::Style::Fullscreen);
sf::Clock Clock_;
sf::Texture texture;
// Loading an image in a sf::Texture
if (!(texture.LoadFromFile("./image.png")))
return -1;
// Creating the sf::Sprite from the texture, and scaling it
sf::Sprite spriteTmp(texture);
spriteTmp.Scale(Width_ / 1920.f, Height_ / 1200.f);
// Creating the sf::RenderTexture, and filling it with the scaled sprite
sf::RenderTexture *renderTexture = new sf::RenderTexture;
if (!renderTexture->Create(texture.GetWidth() * (Width_ / 1920.f), texture.GetHeight() * (Height_ / 1200.f)))
return -1;
renderTexture->Clear(sf::Color::Transparent);
renderTexture->Draw(spriteTmp);
renderTexture->Display();
// Creating the new sf::sprite with the new scaled texture
sf::Sprite *sprite = new sf::Sprite(renderTexture->GetTexture());
while (Window_->IsOpen())
{
// event
ElapsedTime_ = Clock_.GetElapsedTime();
if (ElapsedTime_ > 17)
{
Window_->Clear();
Window_->Draw(*sprite);
Window_->Display();
Clock_.Reset();
}
else
sf::Sleep(2);
}
}
g++ main.cpp -lsfml-graphics -lsfml-system -lsfml-window
#include "DisplaySfml.hh"
#define WIDTH (desktop.width())
#define HEIGHT (desktop.height())
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDesktopWidget desktop;
IDisplay* Win = new DisplaySfml();
Win->InitWindow(WIDTH, HEIGHT, "Air Type");
// Win->loadImage("Ship", "./Resources/ShipNormal.png");
// Win->loadImage("ShipForward", "./Resources/ShipForward.png");
// Win->loadImage("ShipBack", "./Resources/ShipBack.png");
// Win->loadImage("ShipLeft", "./Resources/ShipLeft.png");
// Win->loadImage("ShipRight", "./Resources/ShipRight.png");
Win->loadImage("Background", "./Resources/Background.jpg");
// Win->loadImage("FrontStars", "./Resources/FrontStars.png");
// Win->loadImage("BackStars", "./Resources/BackStars.png");
// Win->loadImage("DoubleStars", "./Resources/FrontStars.png");
// Win->getSprite("Ship")->SetPosition(WIDTH / 2, HEIGHT / 2);
Win->DisplayWindow();
return EXIT_SUCCESS;
}
#include "DisplaySfml.hh"
DisplaySfml::DisplaySfml()
:Speed_(0.01f)
{
turnSendDirection_[sf::Keyboard::Down] = &moveRight;
turnSendDirection_[sf::Keyboard::Up] = &moveLeft;
turnSendDirection_[sf::Keyboard::Left] = &moveBack;
turnSendDirection_[sf::Keyboard::Right] = &moveForward;
turnSendDirection_[sf::Keyboard::Space] = &moveSpace;
}
DisplaySfml::~DisplaySfml()
{
for (std::vector<sf::RenderTexture*>::iterator it = saveTexture_.begin(); it != saveTexture_.end(); ++it)
delete *it;
for (std::map<std::string, Sprite>::iterator it = displayImage_.begin(); it != displayImage_.end(); ++it)
delete (it->second).sprite_;
delete Window_;
}
void DisplaySfml::InitWindow(int Width, int Height, const std::string & Title)
{
Width_ = Width;
Height_ = Height;
Window_ = new sf::RenderWindow(sf::VideoMode(Width_, Height_), Title.c_str(), sf::Style::None);
Window_->EnableVerticalSync(true);
}
void DisplaySfml::loadImage(std::string const &name, std::string const & pathImage)
{
sf::RenderTexture *renderTexture = new sf::RenderTexture;
sf::Texture texture;
if (!(texture.LoadFromFile(pathImage)))
std::cerr << "Image [" << pathImage << "] is missing" << std::endl;
sf::Sprite spriteTmp(texture);
spriteTmp.Scale(Width_ / 1920.f, Height_ / 1200.f);
if (!renderTexture->Create(texture.GetWidth() * (Width_ / 1920.f), texture.GetHeight() * (Height_ / 1200.f)))
std::cerr << "RenderTexture [" << pathImage << "] failed to create" << std::endl;
renderTexture->Clear(sf::Color::Transparent);
renderTexture->Draw(spriteTmp);
renderTexture->Display();
displayImage_[name].sprite_ = new sf::Sprite(renderTexture->GetTexture());
displayImage_[name].width_ = renderTexture->GetWidth();
displayImage_[name].height_ = renderTexture->GetHeight();
displayImage_[name].loop_ = 0;
displayImage_[name].screenWidth_ = 0;
saveTexture_.push_back(renderTexture);
}
sf::Sprite *DisplaySfml::getSprite(std::string const &name)
{
return displayImage_[name].sprite_;
}
int DisplaySfml::getXSprite(std::string const &name)
{
return displayImage_[name].sprite_->GetPosition().x;
}
int DisplaySfml::getYSprite(std::string const &name)
{
return displayImage_[name].sprite_->GetPosition().y;
}
void DisplaySfml::drawImage(std::string const &name, int const &x, int const &y)
{
displayImage_[name].sprite_->SetPosition(x, y);
Window_->Draw(*(displayImage_[name].sprite_));
}
void DisplaySfml::DisplayWindow()
{
x = 0;
y = 0;
Clock_.Reset();
Window_->SetFramerateLimit(60);
while (Window_->IsOpen())
{
event();
ElapsedTime_ = Clock_.GetElapsedTime();
if (ElapsedTime_ > 17)
{
Window_->Clear();
drawImage("Background", 0, 0);
// loopSprite("Background", 3);
// loopSprite("FrontStars", 2);
// loopSprite("BackStars", 1);
// drawImage("Ship", getXSprite("Ship") + x, getYSprite("Ship") + y);
// drawImage("Ship", 500, 500);
// loopSprite("DoubleStars", 6);
Window_->Display();
Clock_.Reset();
}
}
}
void DisplaySfml::event()
{
sf::Event event;
while (Window_->PollEvent(event))
{
if (event.Type == sf::Event::KeyPressed)
{
if ((event.Key.Code == sf::Keyboard::Escape))
{
Window_->Close();
break;
}
for (std::map<sf::Keyboard::Key, setNewPos>::iterator it = turnSendDirection_.begin(); it != turnSendDirection_.end(); ++it)
{
if (sf::Keyboard::IsKeyPressed(it->first))
turnSendDirection_[it->first](x, y);
}
}
}
}
void DisplaySfml::loopSprite(const std::string name, int const speed)
{
if ((displayImage_[name]).screenWidth_ >= Width_)
(displayImage_[name]).screenWidth_ = 0;
if ((displayImage_[name]).loop_ >= (displayImage_[name]).width_)
(displayImage_[name]).loop_ = 0;
sf::IntRect leftRect((displayImage_[name]).loop_, 0,
Width_ - (displayImage_[name]).screenWidth_, Height_);
(displayImage_[name]).sprite_->SetTextureRect(leftRect);
drawImage(name, 0, 0);
if ((displayImage_[name]).loop_ + Width_ >= (displayImage_[name]).width_)
{
sf::IntRect rightRect(0 ,0, (displayImage_[name]).screenWidth_, Height_);
(displayImage_[name]).sprite_->SetTextureRect(rightRect);
drawImage(name, Width_ - (displayImage_[name]).screenWidth_, 0);
(displayImage_[name]).screenWidth_ += speed;
}
(displayImage_[name]).loop_ += speed;
}