# Projection and Clipping in OpenGL

Software and s/w Development

Dec 13, 2013 (4 years and 7 months ago)

144 views

Projection and Clipping in
OpenGL

Lecturer:
Jamal A. Hussein

College of Science

Computer Department

2011
-

2012

Projection in OpenGL

glMatrixMode(GL_PROJECTION);

Perspective projection

2

Perspective Viewing Volume Specified
by glFrustum()

void glFrustum(
double left, double right,

double bottom, double top,

double near, double far
);

Projection in OpenGL (2)

gluPerspective(
double fovy, double aspect,

double near, double far
);

3

Perspective Viewing Volume
Specified by gluPerspective()

Perspective Projection

Projection in OpenGL (3)

Orthographic Projection

4

Orthographic
viewing volume

void glOrtho(
double left, double right,

double bottom, double top,

double near, double far
);

void gluOrtho2D(
double left, double right,

double bottom, double top
);

Manipulating Matrix Stack

5

The

modelview

and

projection

matrices

is

actually

the

topmost

member

of

a

stack

of

matrices

Manipulating Matrix Stack (2)

6

Pushing and Poping matrix
stacks

void

glPushMatrix(void)
;

void

glPopMatrix(void)
;

In addition to the six clipping planes of the viewing volume (left, right,
top, bottom, near, and far), we can define up to six additional clipping
planes

Each plane is specified by its coefficients of its equation:

0
=
D
+
Cz
+
By
+
Ax
Plane and the Viewing
Volume

void glClipPlane(

GLenum plane,

double[] equation);

GL_CLIP_PLANE
i

Where i is an integer
specify the available
plane

The 4 coefficients of the plane
equation

The clipping plane should be enabled

glEnable(
GL_CLIP_PLANEi)

we disable a plane with

glDisable(
GL_CLIP_PLANEi)

0
=
D
+
Cz
+
By
+
Ax

9

double
eqn
[] =

{ 0.0, 1.0, 0.0, 0.0 };

double
eqn2
[] =

{ 1.0, 0.0, 0.0, 0.0 };

/* clip lower half
--

y < 0 */

gl.glClipPlane(GL.GL_CLIP_PLANE0, eqn, 0);

gl.glEnable(GL.GL_CLIP_PLANE0
);

/* clip left half
--

x < 0 */

gl.glClipPlane(GL.GL_CLIP_PLANE1, eqn2, 0);

gl.glEnable(GL.GL_CLIP_PLANE1);

References

Donald Hearn, M. Pauline Baker, Computer Graphics with
OpenGL, 3rd edition, Prentice Hall, 2004.

Chapter 5: Geometric Transformations

The OpenGL Programmer's Guide (the Redbook), 7
th

edition, 2009,