21cs63 CG Vtu
21cs63 CG Vtu
OpenGL
Thaseen Bhashith
Dept of CSE
JNNCE
2D Geometric Transformations
1. Translation
2. Rotation
3. Scaling
Translation
• Translation on a single coordinate point by adding offsets to its
coordinates to generate a new coordinate position.
• Consider point( x, y ), to translate it to new point with offset (tx, ty)
Rotation
P 1= =
Scaling
• To alter the size of an object, apply a scaling transformation.
• A simple two dimensional scaling operation is performed by multiplying
object positions (x, y) by scaling factors sx and sy to produce the
transformed coordinates (x1 , y1 ):
x1 = x · sx, y1= y · sy
Rotation of a point about an arbitrary pivot position
Two-Dimensional Scaling
Matrix
A transformation
sequence for scaling
an object with respect
to a specified fixed
position using the
scaling matrix S(sx , sy )
General Two-Dimensional Composite Transformations and Computational
Efficiency
• The elements of the composite transformation matrix are
Other Two-Dimensional Transformations
1. Reflection and
2. Shear
Reflection
Mapping destination pixel areas onto a scaled array of pixel values. Scaling
factors sx = sy = 0.5 are applied relative to fixed point (x f , y f ).
OpenGL Raster Transformations
• The OpenGL functions for performing raster operations are available.
• A translation of a rectangular array of pixel-color values from one buffer area to
another can be accomplished in OpenGL using:
glCopyPixels (xmin, ymin, width, height, GL_COLOR);-→color values to be copied
• To rotate a block of pixel-color values in 90-degree increments by first saving
the block in an array, then rearranging the elements of the array and placing it
back in the refresh buffer. A block of RGB color values in a buffer can be saved
in an array with the function
glReadPixels (xmin, ymin, width, height, GL_RGB, GL_UNSIGNED_BYTE, colorArray);
OpenGL Raster Transformations
• To rotate the color values, rearrange the rows and columns of the color array, then
the rotated array is put back in the buffer with
glDrawPixels (width, height, GL_RGB, GL_UNSIGNED_BYTE, colorArray);
• The lower-left corner of this array is placed at the current raster position.
• Select the source buffer containing the original block of pixel values with
glReadBuffer(), and designate a destination buffer with glDrawBuffer().
OpenGL Functions for Two-Dimensional Geometric Transformations