Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Constrain Gosu::Window#draw to a Gosu::Image
- - By RavensKrag Date 2011-01-14 19:13
I know there is Gosu::Window#clip_to method which allows constraining drawing to a specific area.  Is there a way to constrain the drawing to a instance of Gosu::Image instead?

I'm trying to draw shadows by overlaying a semi-transparent black circle over other images.  As a result, I can't use texplay for this as it would be too slow to process this every frame.  Feel free to correct me if I'm wrong though.

I assume that this is possible using OpenGL or something, but I was curious if it was already implemented somewhere and just was not documented, or if there was some code that someone else was working on that would point me in the right direction.
Parent - - By banister Date 2011-01-15 01:13
why not just draw a semi transparent blac, circle over images? :) just create a circle image with an alpha < 255 and draw it? :)
Parent - - By RavensKrag Date 2011-01-15 02:14
Ok, I suppose I should go into a bit more detail then.

I'm making a top-down game and thus am working with a psudo-3D environment.  I need to constrain the drawing so that, for example, if the player was jumping over a box, the shadow would only appear on the top of the box.  I would then draw another shadow on the ground.  This is so that the shadow does not show up on the sides of the box, as that would be weird.  Also, as the ground's surface is a different distance away from the player than the top surface of the box, the shadow size and opacity should be different.

Just imagine what it should look like, looking straight-down from the top and seeing a shadow resulting from light which comes straight down.  This would appear as simply a circle.  However, if you use a top-down perspective a-la the 2D Zelda games, then then just using a circle would be weird, as in this perspective you can view the top and sides of a building, box, or what-have-you in the same plane. 

Hope that's clear enough and everything makes sense >.<

If you draw out a picture of what the scene should look like as seen from directly above, and then try to draw the same thing from the typical top-down psudo-3D perspective, I think you'll see what my problem is.
Parent - By erisdiscord Date 2011-01-15 03:29
clip_to works with the other transformations like rotate and translate if that helps at all. If you could show a wee snippet of code for what you're trying to do, I might be able to figure out what needs to be done about it. If you're using a fixed perspective (no rotation or parallax) then it should be as simple as clipping to the coordinates of the tile that the player is over.
Parent - - By jlnr (dev) Date 2011-01-15 03:38
Is the box a pixel-perfect rectangle? Then you could draw the shadow on the floor, draw the box, clip to the box' top plane and draw the shadow again with an offset?

Maybe I am getting the situation wrong though :)
Parent - - By RavensKrag Date 2011-01-15 07:28
I had the exact same idea.  The problem with this is that it starts to get weird when you have non-rectangular objects, doesn't it?  For now I'm simply using pixel-perfect rectangles, but I wanted to be able to expand beyond that and have various sorts of buildings and such.

I think for some reason I thought that it would get to expensive to draw the shadow on the floor and then draw tho box on top of it.  Perhaps I just don't know what I'm talking about  ^.^;

Also, I had somehow thought that this would require some odd coding flow, but I suppose simply using the z-index would take care of ordering the drawing.

Am I just over thinking this? That does tend to happen every so often...
Parent - - By jlnr (dev) Date 2011-01-15 09:31
As long as you have rectangles (or objects that can be approximated using a few rectangles), the actual clipping and drawing will not be a problem. The Ruby overhead to find these rectangles is probably worse :)
If you want to render onto other images, that is not only tough in Gosu but probably OpenGL too. I imagine it's possible with stencil buffers, but  designing around the issue would be the smoothest solution in any case.
Parent - By RavensKrag Date 2011-01-15 20:01
Actually, as a result of the way I have the Chipmunk integrating going in my game, finding the rectangles is fairly trivial.

Alright then, I'll just try to avoid this problem for now.  Thanks for the help.  I'll try to look into stencil buffers later on.
Up Topic Gosu / Gosu Exchange / Constrain Gosu::Window#draw to a Gosu::Image

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill