views:

215

answers:

2

Hey i was wondering if anyone knows to do clipping with 2D textures for a gui or menu like system.

Heres an example output i would like to produce

Have a game screen with a size of 500 x 500. With a screen behind it with a size of 1000 x 1000.

When i draw a Texture at 0, 0 with the parent screen of 500 x 500 i would like the component not to be shown

but if i draw the component at 500, 450 and the texture width and height are 100 i would expect to only see the whole width but only half the height of the component.

I was wondering if there is an easy way about doing this?

Edit:

Basically i was thinking something like a mask effect in Photoshop.

here is a picture Clipping picture

The black outline is where the other half of the texture would be drawn.

A: 

You can clip a texture. When the resulting shape is polygonal,
you can do it by simply modifying the vertices and texture coordinates.

When the clipped texture is a complicated shape, then things get trickier.

You can also clip by just drawing everything in the right order.
It may not be efficient, but it is easy.

p.s. A picture would help here.

Rhythmic Fistman
A: 

Another way to solve this problem:

Basically you have two scenes to draw: the game screen (the blue part in your picture) and the background screen (red part of your picture).

I think that you could draw the game screen and the backgrond screen in two different bitmap objects (or whatever similar you have in your graphics library).

The next step is to clip the entire background screen bitmap to the output bitmap object and then you could clip just the central part (a 500 x 500 square centered in the output screen) of the game screen.


P.S: Maybe it would be better if you could add more details about the graphics library you are using.

Alceu Costa
Well the red was suppose to be another screen behind it.
Chris Watts