Setting up a pixel buffer with SFML is quite easy using the built in classes. Instead of an array you can use sf::Image which has functions for setting the colours for individual pixels. Once you finish updating the pixels for a frame, copy it to a texture using sf::Texture::update(). You can draw this texture as you normally would using sf::Sprite
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
//this is your pixel buffer
sf::Image img;
img.create(50,50);
sf::Texture tex;
tex.create(50, 50);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
//do ALL pixel buffer operations
for(auto y = 10; y < 20; ++y)
{
for(auto x = 10; x < 20; ++x)
{
img.setPixel(x, y, sf::Color::Green);
}
}
//update the texture from the pixel buffer
tex.update(img);
window.clear();
window.draw(sf::Sprite(tex));
window.display();
}
return 0;
}
You can of course use an array instead of an Image and use that to update the texture. In this case a std::vector<sf::Uint8> would do - no need to 'new' anything, the vector takes care of memory management.
The problem here is, as you point out, the pixel format. The reason the SDL code uses Uint32 is that it represents the 4 colour channels packed into a single value. SFML uses a byte for each channel which is why just a simple cast will not work. This also affects how you calculate the size of the buffer. WIDTH x HEIGHT is fine for Uint32, but when creating a buffer of Uint8 values you will need WIDTH x HEIGHT x 4.
sf::Color will take a uint32 value and convert it to bytes automatically, but as you also point out SFML expects RGBA not ARGB values. You could potentially convert these but they will be very slow operations if done on EVERY pixel, especially at higher resolutions.
sf::Uint8 r = (pixel & 0x00ff0000) >> 16;
sf::Uint8 g = (pixel & 0x0000ff00) >> 8
sf::Uint8 b = (pixel & 0x000000ff);
sf::Uint8 a = (pixel & 0xff000000) >> 24;
or to an RGBA uint32:
sf::Uint32 rgbaPixel = ((pixel & 0xff000000) >> 24) | ((pixel & 0x00ffffff) << 8);
Another tack would be to use OpenGL directly to modify the sf::Texture to accept ARGB - this would save performing any pixel conversions but would considerably complicate the setup of the pixel buffer. It would also prevent using an sf::Image.
Utlimately (as you're converting the code anyway) the best bet is to find where the pixel values are actually generated and modify the code to create RGBA output, either as packed uint32 or individual uint8 channels.