Cool, so I went with that first thing you mentioned. It works
However, it's a bit round-about to put all my data into the image, then update the texture from the image. I did a CPU profile and a significant amount of my "UpdateWindow" function was being spent on the Image::setPixel() function.
I tried a different approach to get a little more speed out of it. I maintain a Uint8*, update it with my emulator's buffer, then call texture::update before drawing it to the screen
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
// sf_frame_buffer is the Uint8*
int index = i * width + j * 4;
sf_frame_buffer[index + 0] = em_frame_buffer[i][j].Red;
sf_frame_buffer[index + 1] = em_frame_buffer[i][j].Green;
sf_frame_buffer[index + 2] = em_frame_buffer[i][j].Blue;
sf_frame_buffer[index + 3] = 0xFF;
}
}
window->clear();
texture->update(sf_frame_buffer);
window->draw(*rectangle, *transform);
window->display();
Hope that makes sense, what I'm trying to do.
The result ends up looking really wonky. The image looks like its squeezed vertically.
http://i.imgur.com/PJUWUdU.pngI don't see anything wrong with the code. Here's the part where I initialize all my objects:
VideoMode vm(width * integer_scale, height * integer_scale);
window = new RenderWindow(vm, title);
window->clear(Color::White);
window->display();
transform = new Transform();
transform->scale(scale_factor, scale_factor);
rectangle = new RectangleShape(Vector2f(width, height));
texture = new Texture();
texture->create(width, height);
rectangle->setTexture(texture);
// Each pixel has an 8bit R, G, B and A value. Hence 4 times the number of pixels.
sf_frame_buffer = new Uint8[4 * width * height];
Any idea what I'm doing wrong?