SFML community forums

Help => Graphics => Topic started by: JeZ-l-Lee on February 06, 2009, 07:01:51 pm

Title: Is There A Function To Draw A Single Pixel ??
Post by: JeZ-l-Lee on February 06, 2009, 07:01:51 pm
Is There A Function To Draw A Single Pixel ??

Hi,

I am making a 2-d space shooter game now.

I would like to have moving stars in the background.
How would I draw a single pixel at (x,y) in a certain color to screen buffer?

Thanks

You can track the progress of this game at this URL:
http://www.silentheroproductions.com/LastDefense100PerceT.htm
Title: Is There A Function To Draw A Single Pixel ??
Post by: Daazku on February 06, 2009, 09:46:05 pm
Use OpenGl directly is the best way!

Instead you can make sprites of 1*1 and move them in the screen;
Title: Is There A Function To Draw A Single Pixel ??
Post by: Pfhreak on February 06, 2009, 10:11:44 pm
Here's what I did, I made an sf::Image the size of the renderwindow. Then I used setpixel() to set the appropriate pixels white/black when needed.
Title: Is There A Function To Draw A Single Pixel ??
Post by: Nexus on February 07, 2009, 03:18:24 am
If you are a little bit used to OpenGL, I think it's the easiest and most performant (in the last few days, I looked at the NeHe OpenGL tutorials, and at the moment I am experimenting a little... I think one learns the basics quite fast.)

Otherwise Phreak's method is probably not bad, either. Alternatively, you could use a sf::Shape to draw very small objects. The problem is, if your star has got a texture, you have to take a sprite or use OpenGL.
Title: Is There A Function To Draw A Single Pixel ??
Post by: til on January 05, 2010, 06:43:01 am
I found a way to fill a square sf::Shape (no outline) to draw a single pixel, but like the other workarounds mentioned previously, it seems more interesting than practical or efficient.

I know OpenGL isn't that hard, but that doesn't take the painful irony out of saying it to someone who wants to draw one pixel.  

I vote to put something in the API to draw a single pixel (or list of points).  Perhaps even a variation of the sf::Shape class itself, or style of outline even.

It just seems the perfect fit for SFML's level of API:  It would not be as fast as the pure OpenGL, but it would provide a speed up for the many people who expect it.

Hopefully the SFML team will agree, and not see it as lame feature creep...
Title: Is There A Function To Draw A Single Pixel ??
Post by: Laurent on January 05, 2010, 12:08:34 pm
Yep, maybe I can find a way to provide this kind of feature :)
Title: Is There A Function To Draw A Single Pixel ??
Post by: til on January 05, 2010, 07:00:46 pm
Many Thanks!  
throw Horns("sfml rocks");