I would like to implement the Cohen-Sutherland Algorithm with dynamic clipping volume in 3D Space. (i.e. with 27 regions). Assume I have somthing like this:
glVertex3f(x1, y1, z1);
glVertex3f(x2, y2, z2);
- Is clipping automatically done as default? If yes, how can I deactivate it to use my own algorithm?
- I couldn’t find an implementation for Sutherland in 3D Space. Do you know where I can find it?
Principally any algorithm would be fine as long as it does 3D clipping.
Thanks for your help!
You can’t. Clipping is fixed functionality in OpenGL.
Is clipping automatically done as default? If yes, how can I deactivate it to use my own algorithm?
Why would you want to? First, your algorithm won’t be faster. Second, OpenGL’s clipping does a different job; it’s all about clipping vertices to the viewport, which may not be the entire visible screen. Third, most hardware doesn’t even do “clipping”, using a guardband optimization to avoid the actual clipping of lines/triangles in most cases. So there’s nothing really to turn off.
Or, to put it another way, you don’t need to manually clip your lines to the viewport. You should only do clipping if you’re clipping to some other space.
I have to do this, because it is a university project. It doesn’t have to be an optimal solution, just something that works. Basically, the requirement is to check if lines are in the viewport cuboid before feeding them glVertex3f(). Hence, the algorithm for the solution has to check if there’s an intersection between the lines that should be drawn and the lines of the viewport, all in 3D space. I don’t have an idea how to implement this, as I’m a beginner to computer graphics.
Please read the Forum Posting Guidelines, specifically point 6 of section “Before you post”.