stencilFunction problem

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

stencilFunction problem

Post 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
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: stencilFunction problem

Post 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.
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: stencilFunction problem

Post 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 ...
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: stencilFunction problem

Post 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.
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: stencilFunction problem

Post 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...
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: stencilFunction problem

Post 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?
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: stencilFunction problem

Post 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.
Attachments
StencilTest.love
Old test of stencil
Old test of stencils
(57.32 KiB) Downloaded 129 times
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: stencilFunction problem

Post 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???
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest