0% found this document useful (0 votes)
35 views

l2 Opengl API

This document discusses fundamentals of augmented and virtual reality. It begins with an overview of graphical systems and programming. It then covers topics like the Sierpinski gasket algorithm, 2D and 3D coordinate systems, OpenGL primitives and functions, and algorithms for finding convex hulls of objects. Programming concepts like primitive functions, attribute functions, viewing functions, and transformation functions are explained. Pseudocode is provided for generating the Sierpinski gasket fractal. The document aims to introduce basic computer graphics and virtual reality programming concepts.

Uploaded by

Z
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

l2 Opengl API

This document discusses fundamentals of augmented and virtual reality. It begins with an overview of graphical systems and programming. It then covers topics like the Sierpinski gasket algorithm, 2D and 3D coordinate systems, OpenGL primitives and functions, and algorithms for finding convex hulls of objects. Programming concepts like primitive functions, attribute functions, viewing functions, and transformation functions are explained. Pseudocode is provided for generating the Sierpinski gasket fractal. The document aims to introduce basic computer graphics and virtual reality programming concepts.

Uploaded by

Z
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Fundamentals of Augmented

and Virtual Reality


Adithya Balasubramanyam
Department of Computer Science and Engineering
FUNDAMENTALS OF AUGMENTED
AND VIRTUAL REALITY
Unit 1: Graphical System and Programming

Adithya Balasubramanyam, PhD (Computer Graphics and Virtual Reality)


Department of Computer Science and Engineering
Graphics Programming
Serpenski Gasket
• An interesting shape that has a long history and is of interest in
areas such as fractal geometry v3

• Sierpinski gasket is an object that can be defined recursively and


randomly, in the
• limit, however, it has properties that are not at all random p

• Basic Algorithm for Serpenski Gasket


q q2
1. Pick an initial point p = (x, y, 0) at random inside the
triangle. v1 v2
2. Select one of the three vertices at random.
3. Find the point q halfway between p and the randomly
selected vertex.
4. Display q by putting some sort of marker, such as a small
circle, at the corresponding
location on the display.
5. Replace p with q.
6. Return to step 2.
Graphics Programming
The Three Algorithms of Serpenski Gasket

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

Given a point on the 2D Plane - > there is a point on the


y
3D plane with z=0

i.e. If p= (x,y) is a point on a 2D plane


Then, p = (x,y,0) is the same point in 3D

(0,0,0)

[]
𝑥
𝑝= 𝑦
x
𝑧

z
Graphics Programming
PROGRAMMING TWO-DIMENSIONAL APPLICATIONS

Our basic model of a graphics package is a black box


A graphics system performs multiple tasks to produce output and handle user input
Graphics Programming
Categories of the APIs

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

OpenGL functions are in a single library named GL

OpenGL ExtensionWrangler (GLEW)


GLEW removes operating system dependencies.

The OpenGLUtilityToolkit(GLUT)
provides the minimum functionality that should be expected in any modern

Every function in the OpenGL library has a certain format - glSomeFunction*();


Graphics Programming
The Coordinate System

Various Coordinates system working within a graphical rendering


• World coordinate system
• Object coordinate system
• Physical-device coordinates
• Window coordinates or screen coordinates.
Graphics Programming
Primitives

We can divide primitives in two categories

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

• Points (GL_POINTS) Each vertex is displayed at a size of at least one pixel.

• 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

Simple Polygon Complex Polygon


Filled Objects Methods of displaying
a polygon.

We can render a polygon in a variety of ways:


• We can render only its edges
• We can render its interior with a solid color or a pattern
• We can render or not render the edges
Graphics Programming
Convex vs Concave objects

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

1. Let p0 be the first point (lowermost, left if tie)


2. Let { p1, p2, p3 . . . pn } be the rest of the points in lexicographic polar sorted order
3. Stack.push(p0)
4. Stack.push(p1)
5. Stack.push(p2)
6. for( int i=3; i<=m; i++ )
7. while angle from pi, stack.top, and stack.second is a non-left turn
8. Stack.pop( )
9. Stack.push(pi)
10. return the stack
Graphics Programming
Find Convex Hull
THANK YOU

Dr. Adithya Balasubramanyam


Department of Computer Science and Engineering
[email protected]
+91-900-834-2234

You might also like