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

Author Topic: Best way to set and get the values of individual pixels?  (Read 2573 times)

0 Members and 1 Guest are viewing this topic.

Jallen

  • Newbie
  • *
  • Posts: 40
    • View Profile
Best way to set and get the values of individual pixels?
« on: January 22, 2010, 01:06:15 pm »
Hello.

I've been using SFML for some time now but I'd like a way to start making things like ray tracers and other things which are made by manually accessing and setting the values of pixels in the window.

So really what I want is something like
Code: [Select]
sf::Color GetPixel(int x, int y);
And
Code: [Select]
void SetPixel(int x, int y, sf::Color colour);

Is there anything like that?
Many thanks in advance.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Best way to set and get the values of individual pixels?
« Reply #1 on: January 22, 2010, 01:49:37 pm »
You have these functions in sf::Image. Then all you have to do is to display your image on screen with a sprite.

If it is not fast enough, the best technique would be to work on your own array of pixels, and update the entire image with a single call to Image::LoadFromPixels (SFML 1.x) or Image::UpdatePixels (SFML 2).
Laurent Gomila - SFML developer

Jallen

  • Newbie
  • *
  • Posts: 40
    • View Profile
Best way to set and get the values of individual pixels?
« Reply #2 on: January 22, 2010, 02:22:28 pm »
Right ok cool, thats the information I needed.
Thanks :D

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Best way to set and get the values of individual pixels?
« Reply #3 on: January 22, 2010, 09:30:05 pm »
wouldn't it be better to use shaders? Well depends on the effects you're truing to archive I guess
Pluma - Plug-in Management Framework