In the code, you didn't account for x and y needing to move 4 bytes, since every pixel is 4 bytes, but in your array, it's going through it byte by byte.
for(int x = 0; x < 800; x++)
{
for(int y = 0; y < 600; y++)
{
pixels[(y * x)*4] = 255; // R?
pixels[(y * x)*4 + 1] = 255; // G?
pixels[(y * x)*4+ 2] = 255; // B?
pixels[(y * x)*4 + 3] = 255; // A?
}
}
Made the minor adjustments. This may be more favourable
Doh! I guess I was tired yesterday. :oops:
The example's source code now looks like this:
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
int main(int argc, char *argv[])
{
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Test");
sf::Image image(800, 600, sf::Color(0, 0, 0));
sf::Sprite sprite;
sf::Uint8 *pixels = new sf::Uint8[800 * 600 * 4];
while(window.IsOpened())
{
for(int x = 0; x < 800; x++)
{
for(int y = 0; y < 600; y++)
{
pixels[(y * x) * 4] = 255; // R?
pixels[(y * x) * 4 + 1] = 255; // G?
pixels[(y * x) * 4 + 2] = 255; // B?
pixels[(y * x) * 4 + 3] = 255; // A?
}
}
image.LoadFromPixels(800, 600, pixels);
sprite.SetImage(image);
window.Draw(sprite);
window.Display();
}
delete [] pixels;
return 0;
}
And this is the result:
I kind of expected it to be all white now... :?
For example, if x = 2, y =17 and x=17, y =2, you'd be getting always the same colour, but you clearly don't want that.
No, it's right. I wanted to see if I can get everything to be painted white before I make the next big step (adding the array). That's why I wrote
(stupid nonsense example of what I tried follows)
But I even failed this simple test. :?