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

Author Topic: Fastest way to update individual pixels  (Read 1407 times)

0 Members and 1 Guest are viewing this topic.

lampcord

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Fastest way to update individual pixels
« 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!


Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Fastest way to update individual pixels
« Reply #1 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 :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Fastest way to update individual pixels
« Reply #2 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 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. :)