Jump to content
  • Advertisement
Sign in to follow this  
The_Nerd

Best way of clipping pixel

This topic is 4972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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)
{
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);

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, -Rect.top };

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
the scissor test is the best way to clip anything to a rectangle is, is much faster than stencil or clipplanes etc

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!