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

Author Topic: Drawing pixels  (Read 3595 times)

0 Members and 1 Guest are viewing this topic.

Noctiphobia

  • Newbie
  • *
  • Posts: 5
    • View Profile
Drawing pixels
« on: October 06, 2015, 10:38:37 pm »
Hello.
I'm making a paint-like tool in SFML. I'd like to be able to draw the canvas as a whole, while being able to change the color of single pixels - and to do it somewhat quickly. The thing is, I can't figure out a way to do this efficiently - using an Image sounded great, until I learned that I'd have to load it to a texture every time I want to change anything. Since I'd be passing millions of vertices, I doubt a VertexArray would be great - unless there's something I'm missing.
So, is there any efficient way of doing it, or am I stuck with lower level libraries?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing pixels
« Reply #1 on: October 06, 2015, 10:52:32 pm »
If all you need is direct pixel manipulation, then a pixel buffer and Texture::update is all you need. I see no reason why this would be a problem, you only have to update the texture when the user paints something, it won't happen 60 times per second (and even if it would, Texture::update can do it).

If you need more complex drawing tools, like sprites, shapes, etc. then simply use a sf::RenderTexture.
Laurent Gomila - SFML developer

Noctiphobia

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Drawing pixels
« Reply #2 on: October 06, 2015, 10:56:14 pm »
Oh, I see. I somehow overlooked Texture::update and was sure I'd have to call Texture::loadFromImage every time. I guess I should have read the documentation more carefully. Thank you for help.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Drawing pixels
« Reply #3 on: October 07, 2015, 12:28:42 am »
Laurent: I have one question, does SFML support some kind of features to work with realtime raw video stream (with no encoding, just raw pixels stream). I'm interesting in fast rendering of this stream. The stream has 50Hz frame rate and I want to apply some pixel HLSL effects for the video (color processing, filtering, etc).
I have implementation for Direct3D, where I'm using dynamic texture to render video. But Direct3D code is a little bulky. Can I do the same with SFML with more simple way?
« Last Edit: October 07, 2015, 12:43:14 am by mkalex777 »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Drawing pixels
« Reply #4 on: October 07, 2015, 12:39:27 am »
Texture::update(...) is the best way to send video data to the GPU with SFML.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor