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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - sam

Pages: [1]
1
Graphics / Most efficient way to draw a picture pixel by pixel?
« on: November 13, 2010, 05:28:54 pm »
Quote from: "Laurent"
It's not (x * y * 4), but (x + y * 800) * 4.

Try your formulas with simple numbers like 0, 1, 2 ... you clearly see that the result is wrong ;)

PS: that was a nice effect :lol:
Where does the 800 come from? Is it the width? So it's (x + y * width) * 4?

2
Graphics / Most efficient way to draw a picture pixel by pixel?
« on: November 13, 2010, 03:16:35 pm »
Quote from: "Clairvoire"
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.  

Code: [Select]
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:
Code: [Select]
#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... :?



Quote from: "Xorlium"
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
Quote from: "sam"
(stupid nonsense example of what I tried follows)
But I even failed this simple test.  :?

3
Graphics / Most efficient way to draw a picture pixel by pixel?
« on: November 13, 2010, 12:57:37 am »
I don't get it (stupid nonsense example of what I tried follows)  :?

Code: [Select]
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]     = 255; // R?
      pixels[y * x + 1] = 255; // G?
      pixels[y * x + 2] = 255; // B?
      pixels[y * x + 3] = 255; // A?
    }
  }
  // ...
  image.LoadFromPixels(800, 600, pixels);
  sprite.SetImage(image);
  window.Draw(sprite);
  window.Display();
}
// ...
delete [] pixels;
// ...


Result:

4
Graphics / Most efficient way to draw a picture pixel by pixel?
« on: November 12, 2010, 07:07:22 pm »
Quote from: "Laurent"
Use your own array of pixels, and pass it to sf::Image when it's completely filled and ready to be displayed. That's the most efficient way of doing it, since all pixels will be transfered to the GPU at once.
Thank you, but how does the array have to look like?  :?

5
Graphics / Most efficient way to draw a picture pixel by pixel?
« on: November 12, 2010, 06:17:04 pm »
Hello,

in case I have a whole lot(!) of coordinates in an two-dimensional array, what would be the most efficient way to draw them on my window?

With GDI+ I used the LockBits-method like so (just in reverse). Is there anything similar in SFML?

Thanks in advance!  :oops:

Pages: [1]