// create a 500x500 render-texture
sf::RenderTexture renderTexture;
if (!renderTexture.create(500, 500))
{
// error...
}
// drawing uses the same functions
renderTexture.clear();
renderTexture.draw(sprite); // or any other drawable
renderTexture.display();
// get the target texture (where the stuff has been drawn)
sf::Texture& texture = renderTexture.getTexture();
// draw it to the window
sf::Sprite sprite(texture);
window.draw(sprite);
void CTextObject::createtext()
{
if(font != NULL && text.size() > 0)
{
sf::IntRect rect;
destpos.x = cursor.x;
destpos.y = 0;
uint32 maxwidth = stringwidth();
uint32 maxheight = stringheight();
uint32 width = 0;
uint32 len = text.length();
uint32 i;
sf::Sprite charsprite;
charsprite.setTexture(*font);
charsprite.setColor(sf::Color(255,255,255)); // shouldn't really need this
texttexture.create(maxwidth, maxheight);
texttexture.clear();//(sf::Color(0,0,0,0)); // transparant clear // revert to black so I can see it
for(i = 0; text[i] != '\r' && text[i] != '\n' && i < len ; i++)
{
if(unispace) width += font->size().x;
else width += font->width(text[i]);
}
if(width > 0)
{
if(right) destpos.x = (float)(maxwidth - width);
if(centered) destpos.x = (float)(maxwidth - width)/2;
if(left) destpos.x = 0;
}
for(i = 0; i < len; i++)
{
if(text[i] == '\r' || text[i] == '\n')
{
destpos.x = 0;
width = 0;
if(text[i] == '\n')
{
destpos.y += font->size().y;
}
for(uint32 j = i + 1; text[j] != '\r' && text[j] != '\n' && j < len; j++)
{
if(unispace) width += font->size().x;
else width += font->width(text[j]);
}
if(width > 0)
{
if(right) destpos.x = (float)(maxwidth - width);
if(centered) destpos.x = (float)(maxwidth - width)/2;
if(left) destpos.x = 0;
}
}
else
{
rect = font->getcharrect(text[i]);
charsprite.setTextureRect(rect);
charsprite.setPosition((float)(destpos.x), (float)(destpos.y));
texttexture.draw(charsprite);
if(unispace) destpos.x += font->size().x;
else destpos.x += font->width(text[i]);
}
}
destpos.y += cursor.y;
texttexture.display();
textsprite.setTexture(texttexture.getTexture());
textsprite.setPosition(pos);
}
}
The "How it should look" is a screenshot from an output of another peice of code, as described, creating a vector array of sprites, and drawing all of them each loop.Well you then might want to clearify what you're actually trying to do. Drawing some sprites and posting some possible output doesn't help us understand what the goal of it is.
The biggest thing that kept bugging me was... "Am I drawing it inside the RenderTexture?"If you're unsure how to properly use a render texture, then try it in an isolated situation, with no other code than just the render texture. That way you can familiarize yourself and test that it actually works.
Say I want to resize my RenderTexture, how would I go about doing that? just use create(size.x, size.y) again?Yes, you simply create a larger render texture.
Because when I do that, I don't even get the black square.Well you must be doing something wrong somewhere, but it's impossible to tell from our side. ;)
Basically... it runs through this loop again to recreate everything.Because when I do that, I don't even get the black square.Well you must be doing something wrong somewhere, but it's impossible to tell from our side. ;)
#include <SFML/Graphics.hpp>
int main()
{
freopen ( "Error.log", "wt" , stderr );
sf::RenderWindow window;
window.create(sf::VideoMode(800, 533), "SFML Window", sf::Style::None);
window.setFramerateLimit(60);
window.setVerticalSyncEnabled(true);
sf::Texture traintexture;
traintexture.loadFromFile("train.png");
sf::Sprite trainsprite;
trainsprite.setTexture(traintexture);
trainsprite.setPosition(0,0);
sf::RenderTexture traintex2;
traintex2.create(800,533);
traintex2.clear();
traintex2.draw(trainsprite);
traintex2.display();
sf::Sprite trainsprite2;
trainsprite2.setTexture(traintex2.getTexture());
trainsprite2.setPosition(0,0);
sf::Event Event;
while (window.isOpen())
{
while (window.pollEvent(Event))
{
if (Event.type == sf::Event::Closed)
window.close();
if (Event.type == sf::Event::KeyPressed && Event.key.code == sf::Keyboard::Escape)
window.close();
}
window.clear(sf::Color(255,255,255));
// window.draw(trainsprite);
window.draw(trainsprite2);
window.display(); // draw the screen, probably the last thing in the main loop
}
return EXIT_SUCCESS;
}
What is your graphics card? Is your driver uptodate?Mobile Intel (R) 945 Express Chipset Family
The framerate should never be limited while VSync is active nor the other way around. It's always one or the other.
I always thought they did 2 different, independant things:Well they do different things, but you still can't combine them. ;)
Mobile Intel (R) 945 Express Chipset FamilyThis is quite a bad graphics card (had one once myself), I'm not sure if it can be fixed...
And the driver is unlikely to be up to date, I've never updated it.Well then look at your manufacturer's homepage... ;)
Unfortunately the system sleep() call is not precise enough thus the FrameRateLimit will rarely have a fully consistent framerate (+- 10fps).... so it's not unusual to get frames that last slightly more than 1/60 seconds, and thus skip the next screen refresh. Since v-sync is activated, your program will then wait for the next refresh, 1/60th of seconds later. This results in a bad 30 FPS whereas your code could run much faster. This is exactly why activating both is really a bad idea.
2/28 is called february 28, some countries use mm/dd/yyyy