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

Author Topic: Free hand drawing  (Read 2977 times)

0 Members and 1 Guest are viewing this topic.

cwils132

  • Newbie
  • *
  • Posts: 2
    • View Profile
Free hand drawing
« on: May 13, 2015, 11:57:32 pm »
Forgive me if this has been asked. I've been digging around for a few hours now, however, and haven't been able to turn up a lot.

I'll try to keep it brief and elaborate more if necessary. I am trying to learn how to build my own digital painting program. So far with SFML I can open a blank window, but I can't find anything that would allow me to draw free hand. The tutorials on the website appear to only work for predefined shapes.

Is there something I'm missing in the tutorials or is SFML just not equipped to handle this function? Would I be better served going with SDL2 and OpenGL?

Thanks for any and all help.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10914
    • View Profile
    • development blog
    • Email
Re: Free hand drawing
« Reply #1 on: May 14, 2015, 12:37:06 am »
You'd be better equipped in studying what you actually mean with "draw free hand".
Look at existing tools, learn how they do things and figure out how you could approach this on your own.
No library or API will just provide you a function that's called "draw_free_hand" and then all the magic will happen. ;D

In the end all that OpenGL does, is provide access to your graphics card and all that SFML or SDL does is provide a simple API for a limited feature set. How you now actually go from "input" (e.g. a wombat tablet) to something "free hand" on your screen, that's all left to the programmer to figure out and implement.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cwils132

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Free hand drawing
« Reply #2 on: May 14, 2015, 01:17:36 am »
You'd be better equipped in studying what you actually mean with "draw free hand".
Look at existing tools, learn how they do things and figure out how you could approach this on your own.
No library or API will just provide you a function that's called "draw_free_hand" and then all the magic will happen. ;D

In the end all that OpenGL does, is provide access to your graphics card and all that SFML or SDL does is provide a simple API for a limited feature set. How you now actually go from "input" (e.g. a wombat tablet) to something "free hand" on your screen, that's all left to the programmer to figure out and implement.

Sorry. I have an art background so those terms still come to me a bit more readily than programming terms.

From what I can tell I'll need to set up some situation where I draw on in a 2D array on what SFML calls a texture, and then display that. I know I'd need it to be handled by an on key press event (in this case left mouse click) which I understand. Unfortunately I'm still new enough that while I can think of the concepts, I'm having a much more difficult time implementing them.

Now from here my best guess is to do something like take in the current mouse position and continually draw in points while the button is held, but that feels like it's going to cause trouble in the long run. Another problem I'm not finding an easy solution to is that points and lines and whatnot all seem to be set at 1 pixel width. It's not a problem I feel I need to be too concerned about since I'm just getting started in figuring this all out, but it does present a future issue.

So I don't really know what I was expecting for an answer. I guess just verification that I'm on the right path or being pointed towards something that might help me out. At least it's fun to mess around while I accomplish nothing for the time being.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10914
    • View Profile
    • development blog
    • Email
AW: Free hand drawing
« Reply #3 on: May 14, 2015, 02:50:05 am »
If you think in points and lines, you're thinking about pixel perfect drawings and not what one would call "free hand drawing", because when you draw free hand, you deal with strokes and not with points and lines. Using different pencils or brushes you get different kind of strokes.

I said you should look at existing tools because then you might have realized that these "strokes" (aka brushes) are just images which would mean that one is drawing and layering colored textures of strokes and not points and lines.

Btw. if you have no experience with C++, SFML as a C++ library might not be the best choice or you'd first have to learn more C++. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3368
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Free hand drawing
« Reply #4 on: May 14, 2015, 09:38:00 pm »
...draw on in a 2D array on what SFML calls a texture, and then display that.
You should be able to draw directly to the window. At least, while drawing, then add it to the image when drawing (the current stroke) has been completed.

take in the current mouse position and continually draw in points while the button is held, but that feels like it's going to cause trouble in the long run.
Try taking mouse positions whenever the mouse moves, not continously, probably using events such as MouseMoved.

Another problem I'm not finding an easy solution to is that points and lines and whatnot all seem to be set at 1 pixel width. It's not a problem I feel I need to be too concerned about since I'm just getting started in figuring this all out, but it does present a future issue.
This depends on how you decide to draw the final stroke. Your data will be a list of coordinates in sequence. You can draw just the 1px points, 1px lines between each pair, 1px spline curves based upon the coordinates, or you could draw a shape at each point, a rectangle between each pair (thick line), or interpolate the line/curve using multiple points and draw a(n) shape/point/image at each point, which can be spaced equally if required.

So I don't really know what I was expecting for an answer. I guess just verification that I'm on the right path or being pointed towards something that might help me out.
I suggest looking into vertex arrays (use a vertex array for the current stroke i.e. while stroking) and doing it with just 1px continuous lines to start with.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*