SFML community forums

Help => General => Topic started by: Jallen on January 22, 2010, 01:06:15 pm

Title: Best way to set and get the values of individual pixels?
Post by: Jallen 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.
Title: Best way to set and get the values of individual pixels?
Post by: Laurent 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).
Title: Best way to set and get the values of individual pixels?
Post by: Jallen on January 22, 2010, 02:22:28 pm
Right ok cool, thats the information I needed.
Thanks :D
Title: Best way to set and get the values of individual pixels?
Post by: gsaurus 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