l2 Opengl API
l2 Opengl API
main( )
main( ) {
{ initialize_the_system();
initialize_the_system(); p = find_initial_point();
p = find_initial_point(); for(some_number_of_points)
for(some_number_of_points) {
{ q = generate_a_point(p);
q = generate_a_point(p); store_the_point(q);
display_the_point(q); p = q;
p = q; }
} display_all_points();
cleanup(); cleanup();
} }
Pseudocode Pseudocode - 2
Graphics Programming
The Three Algorithms of Serpenski Gasket
main( )
{
initialize_the_system();
p = find_initial_point();
for(some_number_of_points)
{
q = generate_a_point(p);
store_the_point(q);
p = q;
}
send_all_points_to_GPU();
display_data_on_GPU();
cleanup();
}
Pseudocode - 3
Graphics Programming
The Sierpinski gasket as generated with 5000 random gaskets
Graphics Programming
PROGRAMMING TWO-DIMENSIONAL APPLICATIONS
(0,0,0)
[]
𝑥
𝑝= 𝑦
x
𝑧
z
Graphics Programming
PROGRAMMING TWO-DIMENSIONAL APPLICATIONS
1. Primitive functions
(Lines, Polygons, Triangles, Quads)
2. Attribute functions
(Colors, Fills)
3. Viewing functions
(Camera View, Orthographic, Perspective Projections)
4. Transformation functions
(Rotation, Translation, Scaling, Shear)
5. Input functions
(keyboards, mice, and datatablets)
6. Control functions
(multiprocessing, multiwindow environment, error handling
Graphics Programming
The OpenGL Interface
The OpenGLUtilityToolkit(GLUT)
provides the minimum functionality that should be expected in any modern
Geometric primitives
• Points, line segments, polygons, curves, and surfaces
• Primitives pass through a geometric pipeline
• The primitive goes through geometric operations that determine whether a primitive is
visible, where on the display it appears if it is visible
• The basic OpenGL geometric primitives are specified by sets of vertices
Raster primitives
• Arrays of pixels, lack geometric properties
• Cannot be manipulated in space
• They pass through a separate parallel pipeline on their way to the frame buffer
Graphics Programming
glDrawArrays(GL_POINTS, 0, NumPoints);
• All OpenGL geometric primitives are variants of points, line segments, and triangular
polygons
• Line segments (GL_LINES) The line-segment type causes successive pairs of vertices
• to be interpreted as the endpoints of individual segments
• Polylines (GL_LINE_STRIP, GL_LINE_LOOP) Many curves can be approximated via a
suitable polyline
Graphics Programming
Polygon Basics
The performance of graphics systems is characterized by the number of polygons per second
that can be rendered
An object is convex if all points on the line segment between any two points inside the
object, or on its boundary, are inside the object.
If the above condition does not match such objects are concave
Graphics Programming
Graham’s algorithm for finding Convex Hull