PDA

View Full Version : CLIPPING OBJECTS



Mukund
04-18-2010, 10:58 AM
Hello everyone.

Im working on creating simple graphic editor using OpenGL.
In my 2D drawing mode, im drawing the shapes, which lie in the same plane as my icons(the icons are bitmap images that i will be loading).

Now the problem is that the drawing shapes come over the icons as they are in the same plane.The icons are overwritten by the 2D shapes.


Now can i solve this problem in the following way:

1)Load the bitmaps in a different plane and draw the shapes in a plane behind the bitmap.ie for eg if my bitmaps are in the z = 0 plane, then draw shapes in the z = -10 plane.

OR

2)Use a suitable clipping algorithm.My drawing shapes are many in number.So i wont be able to use algorithms like Cohen Southerland.

Please suggest the best method and also how to proceed with it.
Thanks in advance..

Dark Photon
04-18-2010, 04:59 PM
#1 would be easiest. And if you don't need blending, sufficient.

However if you do need blending (e.g. icons blend on top of your shapes, not just overwrite your shapes), then you could just take the approach of drawing all your shapes first, and then drawing your icons. Because the icons are drawn last, they'll blend on top of the shapes. Further, with this approach, a shape can never "draw on top of" an icon (because the shapes are all drawn before any icons are).

Mukund
04-18-2010, 07:10 PM
Thanks for the reply Dark Photon!
The objects are drawn by the user.Im not loading the objects.Anyways i will not require blending.

So i initially load my icons at z = 0 plane and let the user draw in the z= -10 plane.

The drawing process involves keyboard and mouse interaction.So i take the input values and basically draw the object on the z = -10 plane.So the objects will appear behind the icons.THis will work right?

Dark Photon
04-20-2010, 06:42 AM
THis will work right?
Sounds like it, so long as your framebuffer has a depth buffer, and you enable depth testing/writing.

Fugitive
04-20-2010, 07:50 AM
Thanks for the reply Dark Photon!
The objects are drawn by the user.Im not loading the objects.
Yes, but your software will still draw what the user has created. What Dark Photon meant was that in each rendering pass, you always draw anything created by the user first, then you draw your own icons etc.

Mukund
04-20-2010, 01:50 PM
Thanks Fugitive,Dark Photon.

I used the method suggested by you.ie redrawing my icons.It works well and really fast too!
Thanks!