SFML community forums

General => Feature requests => Topic started by: Jalfor on December 08, 2011, 05:08:19 am

Title: Pixel Manipulation
Post by: Jalfor on December 08, 2011, 05:08:19 am
I'm not sure if you consider this too high level, though it would certainly be nice to have something that would do this as I can think of quite a few examples of where it would be useful.

Thanks
Title: Pixel Manipulation
Post by: nitrix on December 08, 2011, 05:21:05 am
I don't know for SFML1.6 but the next version (SFML2) already provides you a function to update a region of a sf:Texture, maybe that's what you need?

Code: [Select]
////////////////////////////////////////////////////////////
/// \brief Update a part of the texture from an array of pixels
///
/// The size of the \a pixels array must match the \a width and
/// \a height arguments, and it must contain 32-bits RGBA pixels.
///
/// No additional check is performed on the size of the pixel
/// array or the bounds of the area to update, passing invalid
/// arguments will lead to an undefined behaviour.
///
/// This function does nothing if \a pixels is null or if the
/// texture was not previously created.
///
/// \param pixels Array of pixels to copy to the texture
/// \param width  Width of the pixel region contained in \a pixels
/// \param height Height of the pixel region contained in \a pixels
/// \param x      X offset in the texture where to copy the source pixels
/// \param y      Y offset in the texture where to copy the source pixels
///
////////////////////////////////////////////////////////////
void Update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y);


Otherwise, maybe look into sf::VertexArray, there must be an hack-ish way to draw points directly on the screen...

Laurent would answer you better than me x]
Title: Pixel Manipulation
Post by: Walker on December 08, 2011, 06:40:20 am
What kind of manipulation? A lot of effects can be achieved with pixel/fragment shaders.
Title: Pixel Manipulation
Post by: Tex Killer on December 08, 2011, 07:10:17 am
I think he meant something like:

Code: [Select]
texture.GetPixel(x, y).SetColor(sf::Color::Black);
texture.GetPixel(x, y).SetAlpha(0.5);


With the Update method suggested by nitrix that could be done as well, but it is a little bit more difficult.
Title: Pixel Manipulation
Post by: Laurent on December 08, 2011, 08:10:45 am
Quote
I'm not sure if you consider this too high level, though it would certainly be nice to have something that would do this as I can think of quite a few examples of where it would be useful.

I consider this too unclear ;)
Would you mind explaining what you have in mind?
Title: Pixel Manipulation
Post by: Jalfor on December 08, 2011, 11:45:13 am
I meant what Tex Killer said. To have something that makes lets you individually draw pixels onto a canvas/texture or whatever you want to call it.

At the moment I am making a kind of electronics thing, and each part is going to be a pixel big. (That was what I posted with my little problem sharing sf::RenderWindow() over threads). http://sfml-dev.org/forum/viewtopic.php?t=6418

EDIT: While I'm here, could I just check that this is indeed the fastest way to draw pixels onto the screen. I got it from another thread on this forum, though I can't remember how old. Oh, and I'm using SFML 1.6, if there is something in 2.0 I guess I might move over as from what I hear it is stable enough.

EDIT: http://www.sfml-dev.org/forum/viewtopic.php?t=3543&sid=46a4965fc6d11ea01a447f1dd003bce8 is where I got it from. There aren't any new, better ways of doing it are there?
Title: Pixel Manipulation
Post by: Laurent on December 08, 2011, 12:13:35 pm
Quote
http://www.sfml-dev.org/forum/viewtopic.php?t=3543&sid=46a4965fc6d11ea01a447f1dd003bce8 is where I got it from. There aren't any new, better ways of doing it are there?

It's still the best way, yes.