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

Author Topic: How to draw a single pixel?  (Read 8195 times)

0 Members and 1 Guest are viewing this topic.

nbd

  • Newbie
  • *
  • Posts: 14
    • View Profile
How to draw a single pixel?
« on: March 25, 2014, 04:07:37 pm »
Is there a simple way to draw a single pixel with SFML API? Something like SetPixel() in Windows GDI API?

There is a four-year old thread on this forum where addition of such a function were considered useful:

http://en.sfml-dev.org/forums/index.php?topic=1008.msg6426#msg6426

Rhimlock

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: How to draw a single pixel?
« Reply #1 on: March 25, 2014, 04:21:37 pm »
You could use a VertexArray of Points.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: How to draw a single pixel?
« Reply #2 on: March 25, 2014, 04:23:40 pm »
What exactly are you trying to achieve?

Yes, you can use a vertex array of points.
Otherwise you could use a rectangle shape with size 1x1 or a sprite.

Depending on what you want to do, you might want to look into shaders.

And if you want to edit pixels, you could think about using an sf::Image or your own vector of sf::Uint8. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: How to draw a single pixel?
« Reply #3 on: March 25, 2014, 04:25:59 pm »
You could use a 1x1 pixel sprite, a 1x1 RectangleShape, a line with two vertices at the same position (I would guess) and maybe a shader could be used but I'm not sure.

nbd

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to draw a single pixel?
« Reply #4 on: March 25, 2014, 04:38:23 pm »
What exactly are you trying to achieve?

Yes, you can use a vertex array of points.
Otherwise you could use a rectangle shape with size 1x1 or a sprite.

Depending on what you want to do, you might want to look into shaders.

And if you want to edit pixels, you could think about using an sf::Image or your own vector of sf::Uint8. ;)

I want to draw a circle sector (arc). Is there a convenient way to do it with SFML without drawing individual pixels? In other thread for this task a Thor library was recommended:

http://en.sfml-dev.org/forums/index.php?topic=5609.msg36676#msg36676

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: How to draw a single pixel?
« Reply #5 on: March 25, 2014, 04:45:58 pm »
One way to do it would be to draw a (say white) sf::CircleShape on a black background. Then draw a black sf::ConvexShape on top of it to erase the part of the circle you don't want. If you don't want the circle to be solid, but just a "ring", then draw a smaller black sf::CircleShape with the same center as the first on top as well. End result should be what you want I believe.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: How to draw a single pixel?
« Reply #6 on: March 25, 2014, 04:57:00 pm »
Seems like the Pie shape got removed from Thor in version 2.x and using 1.1 is not really an option imho. ;)

If the arc should be 1/4 or 1/2 of the full circle you could also draw it to a render texture that has only the size of 1/4 or 1/2. Otherwise drawing points or small lines with a vertex array might work well enough.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nbd

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to draw a single pixel?
« Reply #7 on: March 25, 2014, 05:11:43 pm »
Thanks for the responses. I'll try to use a vertex array.

 

anything