Page 1 of 1
stencilFunction problem
Posted: Mon Jul 28, 2014 10:09 am
by elsalvador
okay so far i have learn a lot and now i want to move to better codes and saw this function
Code: Select all
myStencilFunction = function()
love.graphics.rectangle("fill", 225, 200, 350, 300)
end
love.graphics.setStencil(myStencilFunction)
for some odd reason I seriously Don't understand this code?
how does it works? i see it there but the wiki its not the best place (for me at least) to search for help..
can someone give me a simple example using this code and making a center rectangles and a circle around it and the rectangle be
blue as example and the out circle dark..
i want to get in to lighting and maybe this is best way to do it (hope it is) but to start I need to understand this process of Stencil
if someone so kind to help me with a small .love to study it nothing big just something simple no extra fancy stuff else i will get confuse
even more lol
Re: stencilFunction problem
Posted: Mon Jul 28, 2014 11:55 am
by micha
Could you make an image (for example in paint) of what you want to draw? That would make it easier to understand for us, what you want to achieve.
Re: stencilFunction problem
Posted: Mon Jul 28, 2014 6:26 pm
by elsalvador
well to start would love to know where can I get more info about stencilFunction how does it work than
go from there. wiki don't show a lot of info ...
Re: stencilFunction problem
Posted: Mon Jul 28, 2014 9:07 pm
by micha
With the setStencil you activate a stencil. If a stencil is activated, then all drawing calls can only draw to a restricted area on screen. The specific area is specified by the stencil function.
For example if you put a rectangle into the stencil function and then set the stencil, then all following drawing calls can only draw inside this rectangle. Everything outside the rectangle is ignored.
Where is this useful? Here is an example. Lets say you want to draw a person inside a house, looking through the window, partly hidden by the wall. The natural approach is to first draw the person and then the wall/window on top. With a stencil you could do the reverse. First draw the wall+window, then create a stencil that draws the shape of the window opening and then draw the person. Only the parts inside the window will be drawn.
Re: stencilFunction problem
Posted: Tue Jul 29, 2014 8:08 am
by elsalvador
okay. what your trying to say is if i make a rectangle inside it than only that part will be visible and the rest ignored?
what if i have a player waling and i want the player visible and the rest ignore?
do i need to make the function on top of everything??????
and will that affect my backgroundColor????
I am thinking of making the game and use this process on top of all to make all dark and only player visible..
am i in the right track of do you think the function doesn't work like that?
sorry I am still trying to learn it wish there was a .love example to learn from it beside the wiki and simple rec or circle...
Re: stencilFunction problem
Posted: Tue Jul 29, 2014 8:12 am
by micha
I am having difficulties understanding what you want to achieve. Could you make a fake-screenshot (using paint or gimp or photoshop?), so that I understand what you want to make?
Re: stencilFunction problem
Posted: Tue Jul 29, 2014 3:40 pm
by Ref
Why not just try the monkey-keyboard approach?
If you pound long enough, eventually you get what you want.
Try changing parameters in the attached demo.
Re: stencilFunction problem
Posted: Tue Jul 29, 2014 9:46 pm
by elsalvador
OMG.. thank you so much..... YES....AWESOMEEEEEEEEEEEEEE this is what i was looking for..
that's the example I was looking for....
here final question.. will this be enough to create lighting effect???