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

Author Topic: Hatching and masking  (Read 4139 times)

0 Members and 1 Guest are viewing this topic.

raytaller

  • Newbie
  • *
  • Posts: 21
    • View Profile
Hatching and masking
« on: December 08, 2008, 01:28:49 pm »
Hello,
I need to fill some polygons with hatching. I'm sure it can be done in raw opengl, but I would like to know the most elegant solution with SFML. Is it possible to define a "mask" ? With the shader-like language, it must be possible to test the alpha channel of a mask image. Are there others options ?
Anyway, I discovered SFML recently, and it seems to be a really nice piece of software ! It's always nice to see such clean and simple C++ code, that reminds you how C++ programming can be pleasent :-)

jdindia

  • Newbie
  • *
  • Posts: 13
    • View Profile
Hatching and masking
« Reply #1 on: December 09, 2008, 01:38:21 am »
It really depends what exactly you want to do.  With shaders anything like what you described is easy.

If all you want to do is 'floodfill' a polygon with a hatching pattern, then generate a hatching texture, set texture repeat (as far as I know, not available in SFML), and draw your polygon with the texture coordinates proportional to screen space (uh, also not available in SFML).  Easy to do with OpenGL though.

raytaller

  • Newbie
  • *
  • Posts: 21
    • View Profile
Hatching and masking
« Reply #2 on: December 09, 2008, 10:15:04 am »
Thanks for answering !
I made a small code using stencil buffer in opengl... but drawing with UVs in screen space is a really good idea, simpler and cheaper.

@Wavesonics : I'm not sure I'm going to generate the map, but yes this is an option

Something reminds not clear for me, concerning opengl : does PreserveOpenGLStates(true) activate backup/restore of the states each time SFML is drawing something, or only at the beginning/end of a opengl commands sequence ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Hatching and masking
« Reply #3 on: December 09, 2008, 11:03:46 am »
Quote
Something reminds not clear for me, concerning opengl : does PreserveOpenGLStates(true) activate backup/restore of the states each time SFML is drawing something, or only at the beginning/end of a opengl commands sequence ?

Both :wink:
All you have to know is that SFML takes care of OpenGL states whenever it has to do it.
Laurent Gomila - SFML developer

raytaller

  • Newbie
  • *
  • Posts: 21
    • View Profile
Hatching and masking
« Reply #4 on: December 09, 2008, 05:06:37 pm »
Thanks for this answer :-)
My question was rather : if I PreserveOpenGLStates(true) and use pure SFML 98% of time with only a few OpenGL calls, will this impact the performance significantly ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Hatching and masking
« Reply #5 on: December 09, 2008, 07:33:25 pm »
Yes, SFML can't detect where you're going to make OpenGL calls, so it saves states whenever it changes it. But make some benchmarks before assuming anything about performances ;)
Laurent Gomila - SFML developer