SFML community forums

Help => Graphics => Topic started by: EClaesson on June 18, 2013, 03:38:04 pm

Title: BGRA buffer to sf::Texture
Post by: EClaesson on June 18, 2013, 03:38:04 pm
I have a buffer (char*) in BGRA that i need to create a sf::Texture of.
I have a sprite that uses sprite.setTexture(renderedTexture) that gets the texture from this:

sf::Texture texture;

Awesomium::BitmapSurface* bitmap = (Awesomium::BitmapSurface*)m_views[name]->surface();

texture.create(bitmap->width(), bitmap->height());

sf::Uint8* rgba = new sf::Uint8[bitmap->width() * bitmap->height() * 4];

for(int i = 0; i < bitmap->width() * bitmap->height(); i++)
{
        rgba[(i * 4)]     = bitmap->buffer()[(i * 4) + 2];
        rgba[(i * 4) + 1] = bitmap->buffer()[(i * 4) + 1];
        rgba[(i * 4) + 2] = bitmap->buffer()[(i * 4)];
        rgba[(i * 4) + 3] = bitmap->buffer()[(i * 4) + 3];
}

texture.update(rgba);

return texture;

The texture seems to render in the correct size, but all white.

EDIT: I didn't store the texture properly so it was invalidated.
Title: Re: BGRA buffer to sf::Texture
Post by: Nexus on June 18, 2013, 11:11:28 pm
By the way, you have a memory leak.

You should really not use new[] and delete[]. Take std::vector instead.