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

Author Topic: Pixel Manipulation  (Read 8643 times)

0 Members and 1 Guest are viewing this topic.

Jalfor

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Pixel Manipulation
« 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
If a picture tells 1000 words, then a YouTube video clearly tells 1000000 making a YouTube video obviously a larger work than the Lord Of The Rings, or some other massive novel. Thus are the laws of YouTube videos.

nitrix

  • Newbie
  • *
  • Posts: 27
    • View Profile
Pixel Manipulation
« Reply #1 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]

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Pixel Manipulation
« Reply #2 on: December 08, 2011, 06:40:20 am »
What kind of manipulation? A lot of effects can be achieved with pixel/fragment shaders.

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Pixel Manipulation
« Reply #3 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Pixel Manipulation
« Reply #4 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?
Laurent Gomila - SFML developer

Jalfor

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Pixel Manipulation
« Reply #5 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?
If a picture tells 1000 words, then a YouTube video clearly tells 1000000 making a YouTube video obviously a larger work than the Lord Of The Rings, or some other massive novel. Thus are the laws of YouTube videos.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Pixel Manipulation
« Reply #6 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.
Laurent Gomila - SFML developer