As the attached images show, when I draw into the RenderTexture, I don't apear to actually have anything drawn into the Texture. Am I doing something wrong?
I basically followed this tutorial.
// 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);
.create, .clear, .draw, .display to create the texture, .getTexture to create a sf::Texture to use on a sprite, simple enough.
so I did this, Don't worry if it looks complicated, this is mostly just copy paste from another area that I know works, that creates a std::vector of sprites, and draws each and every one of them every frame. I thought this would be a better way of managing things.
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);
}
}
I have placed breakpoints on the clear, draw and display lines to make sure my code actually runs through each step, and it does apear to be running correction, but as you can see by the attachments, it doesn't work.
am I doing something wrong?