SFML community forums

Help => Graphics => Topic started by: lampcord on May 28, 2015, 10:41:08 pm

Title: Fastest way to update individual pixels
Post by: lampcord on May 28, 2015, 10:41:08 pm
Hi all!

New to SFML.

Working on a program that paints individual pixels to the screen as opposed the the normal practice of drawing sprites or larger shapes.

What is the most efficient way to do this?

I see there are functions to draw shapes directly to the render window but nothing that I can find for individual points and drawing a line of length 0 seems like overkill.

Also, I see that you can set the individual color of a pixel in an image. Would it be faster to maintain an image in memory and set individual pixels on it and then once per frame just paste the whole image to the screen?

Any help would be greatly appreciated!

Title: Re: Fastest way to update individual pixels
Post by: Nexus on May 28, 2015, 10:45:54 pm
Probably sf::VertexArray with the sf::Points primitive.

If you want to keep the result persistent, you can use sf::RenderTexture.

By the way, please use the help section for help requests, this subforum is for general discussions about the library :)
Title: Re: Fastest way to update individual pixels
Post by: dabbertorres on May 29, 2015, 08:13:42 am
I actually did something like this somewhat recently.

I created a heightmap editor for an old game that still has a community around it.

I essentially made it so 1 pixel represented one tile of the map (thus using a sf::VertexArray of sf::Points), though, this caused problems with zooming, so much like Nexus suggested, I ended up drawing first to a sf::RenderTexture, and then applying the sf::View to the window before drawing the sf::RenderTexture to the window. Works pretty well actually.

Take a look at the code (https://github.com/dabbertorres/BZ-hgt-Editor) if you want. It was mostly produced late at night, so forgive me on some of the code quality.

Based on what you said, you'd probably be most interested in main.cpp, minus the event handling. You might find some parts of the Map class helpful. HeightZone and HeightEntry will be largely irrelevant, unless you want to see some fun bit-twiddling. :)