Sign in to follow this  

Best way of clipping pixel

Recommended Posts

Don't forget you can also use the scissors test or do the clipping manually on the CPU. glViewport is good if you're rendering a whole scene to a subportion of a window, but not if want to clip individual items to different rectangles. There's also the hardware clip planes.

Maybe if you tell us why you're trying to do this, instead of asking a generic question whose answer depends on the context, someone could help you?

Share this post

Link to post
Share on other sites
If you're trying to clip 2D objects, an easy way is:

void TCanvas::ClipDrawing(const TRect& Rect)

double eqn0[4] = { -1.0, 0.0, 0.0, Rect.right };
double eqn1[4] = { 1.0, 0.0, 0.0, -Rect.left };
double eqn2[4] = { 0.0,-1.0, 0.0, Rect.bottom };
double eqn3[4] = { 0.0, 1.0, 0.0, };

glClipPlane(GL_CLIP_PLANE0, eqn0);
glClipPlane(GL_CLIP_PLANE1, eqn1);
glClipPlane(GL_CLIP_PLANE2, eqn2);
glClipPlane(GL_CLIP_PLANE3, eqn3);

You should be careful when setting the coordinates (the example above are for : Top-Left Screen (0, 0) Bottom-Right Screen (W, H).
I'm using this method to clip the controls of my OpenGL gui you can find here.

Share this post

Link to post
Share on other sites
Firstup, dont use glviewport() to clip, it can lead to strange results.

Also, I'm not convinced clipplanes are the best solution to the problem, apprently Nvidia dont play ball all the time (clicky) and I seem to recall something about clipplanes requireing an extra texture unit to be used....

In short, I'd have gone with the scissors test as thats what its designed for.

Share this post

Link to post
Share on other sites
Scissors is good, but setting the scissors rectangle and enabling/disabling the test can be expensive. My gui ran a lot faster when I did all my clipping in software instead of using scissors. Scissors can also potentially disrupt batching, depending how you are rendering your text/gui objects.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this