Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: BGRA buffer to sf::Texture  (Read 2405 times)

0 Members and 1 Guest are viewing this topic.

EClaesson

  • Newbie
  • *
  • Posts: 13
    • MSN Messenger - emanuel.claesson@gmail.com
    • View Profile
    • Email
BGRA buffer to sf::Texture
« 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.
« Last Edit: June 18, 2013, 06:40:11 pm by EClaesson »
//Emanuel Claesson

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: BGRA buffer to sf::Texture
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: