PDA

View Full Version : Implementing clipping in 3D Space



SummertimeClothes
10-16-2012, 11:08 PM
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:


glBegin(GL_LINES);
glVertex3f(x1, y1, z1);
glVertex3f(x2, y2, z2);
glEnd();

1. Is clipping automatically done as default? If yes, how can I deactivate it to use my own algorithm?
2. 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!

thokra
10-17-2012, 12:30 AM
You can't. Clipping is fixed functionality in OpenGL.

Alfonse Reinheart
10-17-2012, 12:42 AM
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.

SummertimeClothes
10-18-2012, 08:44 AM
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.

carsten neumann
10-18-2012, 12:24 PM
Please read the Forum Posting Guidelines (http://www.opengl.org/discussion_boards/showthread.php/176139-Forum-Posting-Guidelines?p=1230021#post1230021), specifically point 6 of section "Before you post".