SlideShare a Scribd company logo
Unit -1
Introduction to OpenGL
OpenGL as a State Machine
Display Points
Lines
Polygons in OpenGL
OpenGL Geometric Drawing Primitives
Normal Vectors
Vertex Arrays
OpenGL Rendering Pipeline
OpenGL-Related Libraries Basics of GLUT.
Animations
Introduction
Animation Techniques
Animation Languages
Principles of animations
key framing: character and Facial Animation
Deformation
Motion capture.
History of OpenGL
OpenGL
• OpenGL (Open Graphics Library) is a standard
specification defining a cross language, cross platform
API for writing applications that produce 2D and 3D
computer graphics.
• In 1992, released by Silicon Graphics Inc. (SGI).
• OpenGL provides a common set of commands that can
be used to manage graphics in different applications
and on multiple platforms.
OpenGL
OpenGL
• OpenGL is a software interface to graphics hardware.
• This interface consists of about 150 distinct commands that you use to specify the objects
and operations needed to produce interactive three−dimensional applications.
• The following list briefly describes the major graphics operations which OpenGL performs
to render an image on the screen. (See "OpenGL Rendering Pipeline" for detailed
information about this order of operations.)
1. Construct shapes from geometric primitives, thereby creating mathematical
descriptions of objects. (OpenGL considers points, lines, polygons, images, and bitmaps
to be primitives.)
2. Arrange the objects in three−dimensional space and select the desired vantage point
for viewing the composed scene.
3. Calculate the color of all the objects. The color might be explicitly assigned by the
application, determined from specified lighting conditions, obtained by pasting a texture
onto the objects, or some combination of these three actions.
4. Convert the mathematical description of objects and their associated color information
to pixels on the screen. This process is called rasterization.
OpenGL Basic Features
Basic OpenGL Syntax..
• In order to write OpenGL program, there are some
things that we should know.
– Function names in the OpenGL basic library (also called
the OpenGL core library) are prefixed with gl,
– and each component word within a function name has its
first letter capitalized.
– E.g., glBegin, glClear, glCopyPixels, glPolygonMode
Basic OpenGL Syntax..
• All constants begin with the uppercase letters GL_,
– E.g., glBegin(GL_POLYGON);
– In above example component words within a constant name are
written in capital letters, and the underscore (‘_’) is used as a
separator between all component words in the name.
Data Type of OpenGL..
Suffix Data Type C Language
Type
OpenGL Type
Definition
b 8-bit integer sign char GLbyte
s 16-bit integer short GLshort
i 32-bit integer int or long GLint, GLsizei
f 32-bit floating point float GLfloat, GLclampf
d 64-bit floating point double GLdouble, GLclampd
ub 8−bit unsigned integer unsigned char GLubyte, GLboolean
us 16−bit unsigned integer unsigned short GLushort
ui 32−bit unsigned integer unsigned int or
Unsigned long
GLuint, GLenum,
GLbitfield
Data Type of OpenGL
• Note:
– The letters used as suffixes to specify these data types for ISO C
implementations of OpenGL are shown in Table, along with the
corresponding OpenGL type definitions.
– Implementations of OpenGL have scope in selecting which C data
type to use to represent OpenGL data types.
OpenGL - Related Libraries
• OpenGL provides a powerful but primitive set of rendering commands,
and all higher level drawing must be done in terms of these commands.
• A number of libraries exist to allow us to simplify our programming
tasks,
GL
GLU
GLUT
Primitives - points, line, polygons, Shading and Colour, Translation,
rotation, scaling, Viewing, Clipping, Hidden surface removal
The OpenGL Utility Library (GLU) contains several routines such tasks
as setting up matrices for specific viewing orientations and projections,
performing polygon tessellation, and rendering surfaces. This library is
provided as part of every OpenGL implementation.
The OpenGL Utility Toolkit (GLUT) is a window system independent
toolkit, written by Mark Kilgard, to hide the complexities of differing
window system APIs. Windowing toolkit (key, mouse handler, window
events)
Header Files..
• For all OpenGL applications, we want to include the gl.h header file in every
file. Almost all OpenGL applications use GLU, the OpenGL Utility Library,
which requires inclusion of the glu.h header file. So almost every OpenGL
source file begins with,
#include <GL/gl.h>
#include <GL/glu.h>
• If you are using GLUT for managing your window manager tasks, you should
include
#include <GL/glut.h>
• Note that glut.h includes gl.h, glu.h, and glx.h automatically, so including all
three files is redundant.
Header Files
• In addition, we will often need to include header files that are required by the
C / C++ code. For example,
//C Code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//C++ Code
#include <iostream>
#include <stdlib.h>
#include <math.h>
Using namespace std;
Display-Window Management using GLUT..
• To get started, Five routines perform tasks necessary to initialize a
window.
glutInit(int *argc, char **argv)
glutInitDisplayMode(unsigned int mode)
initializes GLUT and processes any command line arguments.
glutInit() should be called before any other GLUT routine
specifies whether to use an RGBA or color index color model. You
can also specify whether you want a single or double buffered
window.
//glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB |
GLUT_DEPTH)
Display-Window Management using GLUT
glutInitWindowPosition(int x, int y)
glutInitWindowSize(int width, int size)
int glutCreateWindow(char *string)
glClearColor (1.0, 1.0, 1.0, 0.0);
specifies the screen location for the upper left corner of our
window.
specifies the size, in pixels, of our window
set the background color for the display window The first three
arguments in this function set the red, green, and blue component.
Last parameter, alpha value.
creates a window with an OpenGL context. It returns a
unique identifier for the new window.
Drawing Primitive Shapes..
• Drawing a Triangle
glBegin (GL_TRIANGLES); //Start the draw triangle
glVertex2f( 2, 1);
glVertex2f(1, 1);
glVertex2f(0, 2);
glEnd() //End the draw triangle
Vertices
2- indicates Parameter counts
f- indicates float data type
glBegin(Glenum mode);
- mode is basically the type of primitive we’re drawing
Drawing Primitive Shapes..
• Drawing other shapes
glBegin(GL_POINTS);
glVertex2f( -3, 2);
glVertex2f(2, 1);
glEnd();
glBegin(GL_LINES);
glVertex2f( -2, -2);
glVertex2f(2, -1);
glEnd();
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
Installation of codebook along with OPENGL
OpenGL as a State Machine
• OpenGL is a state machine. You put it into various states (or modes) that then
remain in effect until you change them
• the current color is a state variable. You can set the current color to white, red,
or any other color, and thereafter every object is drawn with that color until you
set the current color to something else
• The current color is only one of many state variables that OpenGL maintains.
• Others control such things as the current viewing and projection
transformations, line and polygon stipple patterns, polygon drawing modes,
pixel-packing conventions, positions and characteristics of lights, and
material properties of the objects being drawn.
• Many state variables refer to modes that are enabled or disabled with the
command glEnable() or glDisable().
OpenGL as a State Machine
• OpenGL is by itself a large state machine: a collection of variables that
define how OpenGL should currently operate.
• The state of OpenGL is commonly referred to as the OpenGL context.
• When using OpenGL, we often change its state by setting some options,
manipulating some buffers and then render using the current context.
• When working in OpenGL we will come across several state-changing
functions that change the context and several state-using functions that
perform some operations based on the current state of OpenGL.
OpenGL as a State Machine
• Each state variable or mode has a default value, and at any
point you can query the system for each variable's current
value
• six following commands to do this
• glGetBooleanv(),
• glGetDoublev(),
• glGetFloatv(),
• glGetIntegerv(),
• glGetPointerv(),
• or glIsEnabled()
OpenGL as a State Machine
• can save a collection of state variables on an attribute stack
with glPushAttrib() or glPushClientAttrib()
• temporarily modify them, and later restore the values
with glPopAttrib() or glPopClientAttrib().
OpenGL Rendering Pipeline
• Step 1 - Vertex Specification
• The programmer can not make any changes or
interventions in Vertex Specification.
• For example, we want to draw a triangle on the monitor.
• Each corner point of the triangle to be drawn is called a
vertex and each vertex has x, y and z coordinates data in
the drawing area.
• Simple shapes drawn using vertices are called primitives.
For example, the triangle shape that we wanted to draw is
a primitive.
• The vertices data are set as a bit series for the
primitive/primitives that will be rendered in Vertex
Specification.
• Step 2 - Vertex Processing
• Points called vertex in the previous step begin
to be processed for rendering in this step.
This step consists of several sub-steps. in this
step, programmers can directly modify or
intervene in the processing of vertexes with
these sub-steps.
• Step 2.1 - Vertex Shader
• The programmer can make some changes or interventions in Vertex Shader.
• The aim of Vertex Shader is to geometrically calculate the position and features of
the 2D/3D model to be created by using vertices.
Some interventions are made using GLSL commands in this step.
The vertex data sent from the previous step to this step comes as a data series of
bit type.
The type of the bit data can be labeled when writing GLSL commands in this step.
For example, “layout(location=0)” command is used to indicate that the vertex data
received in the previous step is a location data.
• Moreover, the vector sent in the previous step is transformed from a 3-element
vector (x, y, z coordinates) to a 4-element vector in this step. The 1 number is
added to the end of the vertex data to do this transformation. In this way, the new
vector is converted to [x, y, z, 1].
• The purpose of this vector transformation is so that the matrix multiplication can
be done correctly in the next steps.
• The reason for adding 1 to the end of the vertices data is that the number 1 is an
ineffective element in the multiplication process.
• In other words, the purpose is that the matrix multiplications for the next steps
can be done without distorting the original data.
• Step 2.2 - Tessellation
• The programmer can make some changes or
interventions in Tessellation.
• The data sent from the previous step can
be converted into smaller primitives in this
step because more detail and complexity can
be added dynamically to 3D surfaces by
breaking the primitives into smaller pieces.
• The model/shape that we wanted to create
can be converted to more realistic in this way.
• Step 2.3 - Geometry Shader
• The programmer can make some changes or
interventions in Geometry Shader.
• Geometry Shader is logically similar to Vertex
Shader.
More complex and new primitives are created by
using the primitives sent from the previous step in
the Geometry Shader, just like geometric shapes
are created by using vertices in the Vertex Shader.
• For example, a hexagon is created by using triangle
shapes.
• Step 3 - Vertex Post-Processing
• The programmer can not make any changes or
interventions in Vertex Post-Processing.
• Values calculated in Vertex and Geometry Shader
can be saved in this step if wish.
• Sometimes, the drawing area that contains the
shape wanted to create can be larger than the
monitor on which the shape will be
displayed. Unnecessary calculations are prevented
by removing primitives that cannot be displayed on
the monitor from the drawing screen in this step.
• This processing is called clipping.
• Step 4 - Primitive Assembly
• The programmer can not make any changes or
interventions in the Primitive Assembly.
• Vertices are processed as a series and new shapes
are rendered from these series in this step.
For example, drawing 3 triangles from a 9-element
vertex series.
• In addition, Face Culling is done in this step.
Face Culling processing means that invisible or too
far to be seen in perspective primitives are in our
drawing area removed from the drawing area.
• Step 5 - Rasterization
• The programmer can not make any changes or
interventions in Rasterization.
• Geometric shapes created in the previous
step are converted into pixels called fragment
data in this step.
• Information such as the color and depth of
each pixel of the shape/model to be wanted
drawing is stored in the fragment data for the
next step.
• Step 6 - Fragment Shader
• The programmer can make some changes or
interventions in Fragment Shader.
• Pixels named as fragment data in the previous step are
processed in this step. In particular, the coloring of
each pixel of the created shape/model is done at this
stage.
• In addition to coloring the pixels in this step, operations
such as shading and lighting of each pixel are also
processed.
• GLSL commands are used at this stage, just like in
Vertex Shader to perform the operations mentioned
above.
• Step 7 - Per-Sample Operations
• The programmer can not make any changes or interventions in
Per-Sample Operations.
• First of all, the Depth Test is performed in this step. The Depth
Test is the stage of whether the fragment data wanted
drawing will be drawn or not.
For example; If there is another fragment of data in front of the
fragment data to be wanted drawing, the fragment data to be
drawn will fail for the depth test.
• Moreover, Color Blending is performed in this step. Using the
operations described in the previous steps, the colors in the
fragment data are mixed with each other and interact with
overlapping fragment data in this stage.
• As a result of all these steps, the rendering process of the scene
is completed and the final 2D/3D shape is created.
OpenGL-Related Libraries
• OpenGL provides a powerful but primitive set of rendering
commands.
• All higher-level drawing must be done in terms of these
commands.
• A number of libraries exist to allow you to simplify your
programming tasks, including the following:
The OpenGL Utility Library (GLU) contains several routines
that use lower-level OpenGL commands to perform such tasks as
setting up matrices for specific viewing orientations and
projections, performing polygon tessellation, and rendering
surfaces.
OpenGL-Related Libraries
• For every window system, there is a library that extends the
functionality of that window system to support OpenGL
rendering.
• For machines that use the X Window System, the OpenGL
Extension to the X Window System (GLX) is provided as
an adjunct to OpenGL
• GLX routines use the prefix glX
• For Microsoft Windows, the WGL routines provide the
Windows to OpenGL interface.
• All WGL routines use the prefix wgl.
OpenGL-Related Libraries
• The OpenGL Utility Toolkit (GLUT) is a window system-
independent toolkit, written by Mark Kilgard.
• GLUT routines use the prefix glut
• Open Inventor is an object-oriented toolkit based on OpenGL
which provides objects and methods for creating interactive three-
dimensional graphics applications.
• Open Inventor, which is written in C++, provides prebuilt objects
and a built-in event model for user interaction, high-level
application components for creating and editing three-dimensional
scenes, and the ability to print objects and exchange data in other
graphics formats.
• Open Inventor is separate from OpenGL.
OpenGL-Related Libraries
• OpenGL Utility Toolkit (GLUT)
• OpenGL drawing commands are limited to those that generate
simple geometric primitives (points, lines, and polygons).
• GLUT includes several routines that create more complicated
three-dimensional objects such as a sphere, a torus, and a
teapot.
• OpenGL Utility Library, GLU, also has quadrics routines that
create some of the same three-dimensional objects as GLUT,
such as a sphere, cylinder, or cone.
OpenGL-Related Libraries
OpenGL Utility Toolkit (GLUT)
Window Management-Five routines perform tasks necessary to initialize a
window.
• glutInit(int *argc, char **argv) initializes GLUT and processes any command line arguments (for X, this
would be options like -display and -geometry). glutInit() should be called before any other GLUT routine.
• glutInitDisplayMode(unsigned int mode) specifies whether to use an RGBA or color-index color model. You
can also specify whether you want a single- or double-buffered window. (If you're working in color-index
mode, you'll want to load certain colors into the color map; use glutSetColor() to do this.) Finally, you can
use this routine to indicate that you want the window to have an associated depth, stencil, and/or accumulation
buffer. For example, if you want a window with double buffering, the RGBA color model, and a depth buffer,
you might call glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH).
• glutInitWindowPosition(int x, int y) specifies the screen location for the upper-left corner of your window.
• glutInitWindowSize(int width, int size) specifies the size, in pixels, of your window.
• int glutCreateWindow(char *string) creates a window with an OpenGL context. It returns a unique identifier
for the new window. Be warned: Until glutMainLoop() is called (see next section), the window is not yet
displayed.
OpenGL-Related Libraries
OpenGL Utility Toolkit (GLUT)
The Display Callback-
• glutDisplayFunc(void (*func)(void)) is the first and most important event
callback function. Whenever GLUT determines the contents of the window
need to be redisplayed, the callback function registered
by glutDisplayFunc() is executed. Therefore, you should put all the
routines you need to redraw the scene in the display callback function.
• If your program changes the contents of the window, sometimes you will
have to call glutPostRedisplay(void), which gives glutMainLoop() a
nudge to call the registered display callback at its next opportunity.
• Running the Program
OpenGL-Related Libraries
OpenGL Utility Toolkit (GLUT)
Running the Program-
• The very last thing you must do is call glutMainLoop(void).
• All windows that have been created are now shown, and
rendering to those windows is now effective.
• Event processing begins, and the registered display callback is
triggered.
• Once this loop is entered, it is never exited.
Input Data
You must provide several types of input data to
the OpenGL pipeline:
• Vertices - Vertices describe the shape of the
desired geometric object. To specify vertices,
you use glVertex*() commands in conjunction
with glBegin() and glEnd() to create a point,
line, or polygon. You can also use glRect*() to
describe an entire rectangle at once.
Input Data
You must provide several types of input data to
the OpenGL pipeline:
• Edge flag - Edge flag - By default, all edges of
polygons are boundary edges. Use the
glEdgeFlag*() command to explicitly set the
edge flag.
• Current raster position- Specified with
glRasterPos*(), the current raster position is
used to determine raster coordinates for pixel
and bitmap drawing operations.
Input Data
You must provide several types of input data to the
OpenGL pipeline:
• Current normal -A normal vector associated with a
particular vertex determines how a surface at that
vertex is oriented in three-dimensional space; this in
turn affects how much light that particular vertex
receives. Use glNormal*() to specify a normal vector.
• Current color - The color of a vertex, together with
the lighting conditions, determine the final,lit color.
Color is specified with glColor*() if in RGBA mode or
with glIndex*() if in colorindex mode.
Input Data
You must provide several types of input data to the
OpenGL pipeline:
• Current texture coordinates - Specified with
glTexCoord*(), texture coordinates determine the
location in a texture map that should be associated with
a vertex of an object.
• When glVertex*() is called, the resulting vertex inherits
the current edge flag, normal, color, and texture
coordinates. Therefore, glEdgeFlag*(), glNormal*(),
glColor*(), and glTexCoord*() must be called before
glVertex*() if they are to affect the resulting vertex.
Vertex Array Objects (VAOs)
If you are using OpenGL ES 3 or higher, you should use
Vertex Array Objects (or "VAOs") to store your vertex
attribute state.
• Using a VAO allows the drivers to compile the vertex description format
for repeated use. In addition, this frees you from having to cache the vertex
format needed for glVertexAttribPointer.
• Instead you specify individual vertex data in immediate mode (between
glBegin() and glEnd() pairs), you can store vertex data in a set of arrays
including vertex positions, normals, texture coordinates and color
information. And you can draw only a selection of geometric primitives by
dereferencing the array elements with array indices.
VAO’S
Take a look the following code to draw a cube with immediate mode.
Each face needs 6 times of glVertex*() calls to make 2 triangles, for
example, the front face has v0-v1-v2 and v2-v3-v0 triangles. A cube
has 6 faces, so the total number of glVertex*() calls is 36. If you also
specify normals, texture coordinates and colors to the corresponding
vertices, it increases the number of OpenGL function calls.
The other thing that you should notice is the vertex "v0" is shared
with 3 adjacent faces; front, right and top face. In immediate mode,
you have to provide this shared vertex 6 times, twice for each side as
shown in the code.
VAO’S
• glBegin(GL_TRIANGLES); // draw a cube with 12 triangles
• // front face =================
• glVertex3fv(v0); // v0-v1-v2
• glVertex3fv(v1);
• glVertex3fv(v2);
• glVertex3fv(v2); // v2-v3-v0
• glVertex3fv(v3);
• glVertex3fv(v0);
• // right face =================
• glVertex3fv(v0); // v0-v3-v4
• glVertex3fv(v3);
• glVertex3fv(v4);
• glVertex3fv(v4); // v4-v5-v0
• glVertex3fv(v5);
• glVertex3fv(v0);
• // top face ===================
• glVertex3fv(v0); // v0-v5-v6
• glVertex3fv(v5);
• glVertex3fv(v6);
• glVertex3fv(v6); // v6-v1-v0
• glVertex3fv(v1);
• glVertex3fv(v0); ...
• // draw other 3 faces
• glEnd();
VAO’S
Using vertex arrays reduces the number of function calls and redundant usage
of shared vertices. Therefore, you may increase the performance of rendering.
Here, 3 different OpenGL functions are explained to use vertex arrays;
glDrawArrays(), glDrawElements() and glDrawRangeElements(). Although,
better approach is using vertex buffer objects (VBO) or display lists.
• https://www.glprogramming.com/red/chapter0
1.html
• https://www3.ntu.edu.sg/home/ehchua/
programming/opengl/cg_introduction.html
OpenGL Functions
• A software API consisting of around several
hundred functions that allow you to talk to
your graphics hardware.
• It is cross-platform and the most commonly
used in professional graphics applications
OpenGL Functions
• 1.Primitive functions
• 2.Attribute functions
• 3.Viewing functions
• 4.Transformation functions
• 5.Input functions
• 6.Control functions
• 7.query functions.
• Primitive functions
OpenGL Functions
• Primitive functions-To perform operations ranging from choosing the
color with which we display a line segment.
• Depending on the API,the primitives can include points, line, segments,
polygons, pixels, text , and various type of curves and surfaces.
• Example
glBegin(GL_POINTS);
glVertex2f(100.0,200.0);
glEnd();
OpenGL Functions
glVertex2d, glVertex2f, glVertex2i,
glVertex2s,
glVertex3d, glVertex3f, glVertex3i,
glVertex3s,
glVertex4d, glVertex4f, glVertex4i,
glVertex4s,
glVertex2dv, glVertex2fv, glVertex2iv,
glVertex2sv,
glVertex3dv, glVertex3fv, glVertex3iv,
glVertex3sv,
glVertex4dv, glVertex4fv, glVertex4iv,
glVertex4sv
OpenGL Functions
• The postfix specifies the format of parameters used by each
function:
• 2 means a 2D point x, y.
• 3 means a 3D point x, y, and z.
• 4 means a 3D point in homogeneous coordinates x, y, z, and w.
[Homogeneous coordinates will be discussed in the lecture on Chapter 5.]
• d means double type.
• f means float type.
• i means integer type.
• s means short type.
• v means vector type.
• u[bsi] means unsigned version of that type
OpenGL Functions
Example: using vector type parameter
double P1[2], P2[2], P3[2];
/* set values to P1, P2, P3. */
P1[0] = 1.5; P1[1] = -0.3;
......
glBegin(GL_POINTS);
glVertex2dv(P1);
glVertex2dv(P2);
glVertex2dv(&P3[0]); /* This is equivalent. */
glEnd()
OpenGL Functions
• OpenGL lines
• Three different line primitives can be created:
• GL_LINES-draws a line segment for each pair of vertices.
• GL_LINE_STRIP-draws a connected group of line segments from
vertex v0to vn connecting a line between each vertex and the
next in the order given.
• GL_LINE_LOOPSimilar to GL_LINE_STRIP, except it closes the
line fromvn to v0, defining a loop.
glBegin(GL_LINE_LOOP); //make it a connected close line segment
glVertex2f(0.0f, 2.0f); //note 2D form
glVertex2f(1.0f, 2.0f);
glVertex2f(0.0f, -2.0f);
glVertex2f(-1.0f, 0.0f);
glEnd();
OpenGL Functions
OpenGL Functions
• OpenGL polygons
• Front faces, back faces and rendering modes
• glCullFace() -- specify whether front- or back-facing sides (faces) should
be drawn
• glFrontFace( ) -- define front- and back-facing polygons
• glPolygonMode( ) -- select a polygon rasterization mode
• Polygon Types
• GL_POLYGON -- draws a polygon from vertex v0 to vn-1
• GL_QUADS -- draws a series of separate four-sided polygons
• GL_TRIANGLES -- draws a series of separate three-sided polygons
• GL_QUAD_STRIP -- draws a strip of connected quadrilaterals
• GL_TRIANGLE_STRIP -- draws a strip of connected triangles
• GL_TRIANGLE_FAN -- draws a strip of triangles connected about a
common origin
OpenGL Functions
• OpenGL polygons
The following code constructs a filled in
parallelogram on the x-y plane:
glBegin(GL_POLYGON);
glVertex2f(0.0f, 2.0f); //note 2D form
glVertex2f(1.0f, 2.0f);
glVertex2f(0.0f, -2.0f);
glVertex2f(-1.0f, 0.0f);
glEnd();
OpenGL Functions
• The following draws a rectangle:
glRectf(0f, 0f, 1f, 1f); // x0,
y0, x1, y1: two opposite corners
// of the rectangle.
glBegin(GL_QUADS);
glVertex2f(0.0f, 0.0f); //note 2D form
glVertex2f(1.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
glVertex2f(0.0f, 1.0f);
glEnd();
OpenGL Functions
• Attribute functions-Define the low
level objects or atomic entities that our
system can display.
Eg glColor3f(1.0,0.0,0.0);
glLineWidth(1.0);
OpenGL Functions
• Viewing functions-The viewing functions allows us
to specify various views,although APIs differ in the
degree of flexibility they provide in choosing a view.
• Example
• glViewport (xvmin, yvmin, vpWidth,
vpHeight);
• gluOrtho2D (xwmin, xwmax, ywmin,
ywmax);
• gluLookAt(…);
OpenGL Functions
• Transformation functions-Transformation
function that allows to carry out
transformations of objects,such as
rotation, translation and scaling.
• Example
• glTranslatef (tx, ty, tz);
• glRotatef (theta, vx, vy, vz);
• glScalef (sx, sy, sz);
OpenGL Functions
• Input function- Allows us to deal with the
diverse forms of input that characterize
modern graphics systems.
• void glutKeyboardFunc(void (*func)
(unsigned char key, int x, int y));
Animations
Animation is the art of making drawings
move or the method of photographing
successive drawings, models, and
puppets and manipulating them to
appear as moving images.
Animations
Animation: Introduction
Images are manipulated to create moving
images.
Linear List Notation Languages
Linear List Notation Languages
• It is especially animation supporting language.
• Example:
• 42,53,B,rotate, “palm”, 1,30
• 42=> starting frame
• 53=> ending frame
• B=> table
• rotate=>action
• palm=>object
• 1=>start angle
• 30=>end angle
General purpose Languages
C
C++
Java
Javascript
Pascal
LISP
Animation Tools
Open source Tools
• Blender
• Containerize
• openToonz
• Pencil2D
• Synfig
• K-3D
• Krita
Animation Tools
Paid Tools
• Animate CC
• Cartoon Animator
HISTORY
• Many people were involved in the history of
animation and creating the first animations. However,
there is only one person who is considered as
the “Father of Animation.”
• He is the French cartoonist, Émile Eugène Jean Louis
Courtet, known as Émile Cohl. Cohl is the creator of
the first fully animated movie
called Fantasmagorie. It premiered in Paris on
August 17, 1908.
Types Of Animation
• There are four main types of animation:
1. 2D animation
2. 3D animation
3. Stop motion animation
4. Motion graphics
There is an additional type of animation called traditional animation.
However, since traditional animation is the first type of 2D animation
Traditional Animation
Traditional animation is also called hand-drawing animation, classical
animation, or cel animation. It consisted of drawing everything frame
by frame, be it a character, a background, and everything in between.
Types Of Animation
• TRADITIONAL ANIMATION
Traditional animation is also called hand-drawing animation, classical
animation, or cel animation. It consisted of drawing everything frame
by frame, be it a character, a background, and everything in between.
These drawings were made on sheets of transparent paper and then
photographed on an animation camera.
After that, the final photographs were used to create movement in a
two-dimensional space, animated on 12 frames per second (fps).
Sometimes they were animated on 24fps for smoother movements and
faster action.
Types Of Animation
• 2D ANIMATION
• With traditional animation, animators were required to
keep drawing the same characters over and over again.
• That is not needed with vector-based 2D animation
since the motion is controlled by vectors.
• With vectors, every creation can be reused as many
times as the animator wishes, without having to re-
create the same backgrounds, characters, and so on.
• Moreover, the movement of the characters is
controlled by vectors.
Types Of Animation
• 3D ANIMATION
• Also called CGI or Computer Animation, 3D
animation is one of the most popular types of
animation. 3D animation is used not only for feature
films but also for short films, video games, ads, and
more.
3D Animation vs. 2D Animation
• Technical skillsets:excellent drawing skills to
become a 3D designer. However, you will need
to have a clear understanding of animating in
3D.
• Moving instead of drawing:Compared to 2D
animation, 3D animation will mainly consist of
moving the character in a 3D program rather
than drawing for different frames.
Stop Motion Animation
• Stop motion animation is similar to traditional
animation since it also combines a series of images
that document slight movements.
• However, stop motion animation uses photographs
of real objects and not drawings or vector
animations.
• Artists take pictures of real-life objects and scenes.
After each object they move in the scene they have
set up, they take a picture before making the next
move or the next moves.
Stop Motion Animation
• They continue this process until they have a photo for
each frame they want to use for their animation.
• Similar to traditional 2D animation, when all frames
are shown in a sequence right after the other, the
objects seem like they are moving on their own. That’s
how the illusion of movement is created with stop
motion animation.
• Before CGI animation, stop motion animation was the
only animation type that gave viewers that “special
effects” feeling.
Motion Graphics
• Motion graphics can be 2D and 3D and are
mainly used to animate text, logos, and video
clips. Motion graphics are called all digital
graphics that create the illusion of motion.
• Unlike 2D animation and 3D animation, you
do not need to follow a particular storyline or
focus on key characters with motion graphics.

More Related Content

PDF
18csl67 vtu lab manual
PPT
Open gl
PPT
openGL basics for sample program (1).ppt
PPT
openGL basics for sample program.ppt
PDF
OpenGL Introduction.
PPTX
Computer Graphics with OpenGL presentation Slides.pptx
PPT
opengl.ppt
PPT
Intro to Computer Graphics.ppt
18csl67 vtu lab manual
Open gl
openGL basics for sample program (1).ppt
openGL basics for sample program.ppt
OpenGL Introduction.
Computer Graphics with OpenGL presentation Slides.pptx
opengl.ppt
Intro to Computer Graphics.ppt

Similar to UNIT 1 OPENGL_UPDATED .pptx (20)

PDF
Opengl basics
PPT
Hill ch2ed3
PPT
Programming with OpenGL
PPT
Open Graphics Library
PPT
september11.ppt
PPT
Opengl (1)
DOCX
Computer graphics workbook
PPTX
3 CG_U1_P2_PPT_3 OpenGL.pptx
PPTX
OpenGL Introduction
PPTX
Lecture 6 introduction to open gl and glut
PDF
CG3_ch3+ch4computergraphicsbreesenhan.pdf
PPT
01.Opengl_intro-2.ppt
PPT
Introduction to OpenGL modern OpenGL program
PPTX
Chapter02 graphics-programming
PDF
OpenGL_Programming_Guide.pdf
PPT
Introduction to OpenGL.ppt
PPT
PDF
Open gl basics
PPT
Programming with OpenGL
Opengl basics
Hill ch2ed3
Programming with OpenGL
Open Graphics Library
september11.ppt
Opengl (1)
Computer graphics workbook
3 CG_U1_P2_PPT_3 OpenGL.pptx
OpenGL Introduction
Lecture 6 introduction to open gl and glut
CG3_ch3+ch4computergraphicsbreesenhan.pdf
01.Opengl_intro-2.ppt
Introduction to OpenGL modern OpenGL program
Chapter02 graphics-programming
OpenGL_Programming_Guide.pdf
Introduction to OpenGL.ppt
Open gl basics
Programming with OpenGL
Ad

More from miteshchaudhari4466 (6)

PPTX
PPTX
Address_Calculation_Arrays .pptx
PPTX
Unit 2 open gl .pptx
PPT
bresenham circle algorithm .ppt
PPTX
Python list tuple dictionary .pptx
PDF
While Loop in python engineering .pdf
Address_Calculation_Arrays .pptx
Unit 2 open gl .pptx
bresenham circle algorithm .ppt
Python list tuple dictionary .pptx
While Loop in python engineering .pdf
Ad

Recently uploaded (20)

PPTX
Information Storage and Retrieval Techniques Unit III
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PDF
Design Guidelines and solutions for Plastics parts
PDF
Soil Improvement Techniques Note - Rabbi
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPT
Occupational Health and Safety Management System
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Software Engineering and software moduleing
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Information Storage and Retrieval Techniques Unit III
Safety Seminar civil to be ensured for safe working.
Exploratory_Data_Analysis_Fundamentals.pdf
III.4.1.2_The_Space_Environment.p pdffdf
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
Design Guidelines and solutions for Plastics parts
Soil Improvement Techniques Note - Rabbi
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Fundamentals of Mechanical Engineering.pptx
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Nature of X-rays, X- Ray Equipment, Fluoroscopy
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Occupational Health and Safety Management System
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Software Engineering and software moduleing
R24 SURVEYING LAB MANUAL for civil enggi
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...

UNIT 1 OPENGL_UPDATED .pptx

  • 1. Unit -1 Introduction to OpenGL OpenGL as a State Machine Display Points Lines Polygons in OpenGL OpenGL Geometric Drawing Primitives Normal Vectors Vertex Arrays OpenGL Rendering Pipeline OpenGL-Related Libraries Basics of GLUT.
  • 2. Animations Introduction Animation Techniques Animation Languages Principles of animations key framing: character and Facial Animation Deformation Motion capture.
  • 4. OpenGL • OpenGL (Open Graphics Library) is a standard specification defining a cross language, cross platform API for writing applications that produce 2D and 3D computer graphics. • In 1992, released by Silicon Graphics Inc. (SGI). • OpenGL provides a common set of commands that can be used to manage graphics in different applications and on multiple platforms.
  • 6. OpenGL • OpenGL is a software interface to graphics hardware. • This interface consists of about 150 distinct commands that you use to specify the objects and operations needed to produce interactive three−dimensional applications. • The following list briefly describes the major graphics operations which OpenGL performs to render an image on the screen. (See "OpenGL Rendering Pipeline" for detailed information about this order of operations.) 1. Construct shapes from geometric primitives, thereby creating mathematical descriptions of objects. (OpenGL considers points, lines, polygons, images, and bitmaps to be primitives.) 2. Arrange the objects in three−dimensional space and select the desired vantage point for viewing the composed scene. 3. Calculate the color of all the objects. The color might be explicitly assigned by the application, determined from specified lighting conditions, obtained by pasting a texture onto the objects, or some combination of these three actions. 4. Convert the mathematical description of objects and their associated color information to pixels on the screen. This process is called rasterization.
  • 8. Basic OpenGL Syntax.. • In order to write OpenGL program, there are some things that we should know. – Function names in the OpenGL basic library (also called the OpenGL core library) are prefixed with gl, – and each component word within a function name has its first letter capitalized. – E.g., glBegin, glClear, glCopyPixels, glPolygonMode
  • 9. Basic OpenGL Syntax.. • All constants begin with the uppercase letters GL_, – E.g., glBegin(GL_POLYGON); – In above example component words within a constant name are written in capital letters, and the underscore (‘_’) is used as a separator between all component words in the name.
  • 10. Data Type of OpenGL.. Suffix Data Type C Language Type OpenGL Type Definition b 8-bit integer sign char GLbyte s 16-bit integer short GLshort i 32-bit integer int or long GLint, GLsizei f 32-bit floating point float GLfloat, GLclampf d 64-bit floating point double GLdouble, GLclampd ub 8−bit unsigned integer unsigned char GLubyte, GLboolean us 16−bit unsigned integer unsigned short GLushort ui 32−bit unsigned integer unsigned int or Unsigned long GLuint, GLenum, GLbitfield
  • 11. Data Type of OpenGL • Note: – The letters used as suffixes to specify these data types for ISO C implementations of OpenGL are shown in Table, along with the corresponding OpenGL type definitions. – Implementations of OpenGL have scope in selecting which C data type to use to represent OpenGL data types.
  • 12. OpenGL - Related Libraries • OpenGL provides a powerful but primitive set of rendering commands, and all higher level drawing must be done in terms of these commands. • A number of libraries exist to allow us to simplify our programming tasks, GL GLU GLUT Primitives - points, line, polygons, Shading and Colour, Translation, rotation, scaling, Viewing, Clipping, Hidden surface removal The OpenGL Utility Library (GLU) contains several routines such tasks as setting up matrices for specific viewing orientations and projections, performing polygon tessellation, and rendering surfaces. This library is provided as part of every OpenGL implementation. The OpenGL Utility Toolkit (GLUT) is a window system independent toolkit, written by Mark Kilgard, to hide the complexities of differing window system APIs. Windowing toolkit (key, mouse handler, window events)
  • 13. Header Files.. • For all OpenGL applications, we want to include the gl.h header file in every file. Almost all OpenGL applications use GLU, the OpenGL Utility Library, which requires inclusion of the glu.h header file. So almost every OpenGL source file begins with, #include <GL/gl.h> #include <GL/glu.h> • If you are using GLUT for managing your window manager tasks, you should include #include <GL/glut.h> • Note that glut.h includes gl.h, glu.h, and glx.h automatically, so including all three files is redundant.
  • 14. Header Files • In addition, we will often need to include header files that are required by the C / C++ code. For example, //C Code #include <stdio.h> #include <stdlib.h> #include <math.h> //C++ Code #include <iostream> #include <stdlib.h> #include <math.h> Using namespace std;
  • 15. Display-Window Management using GLUT.. • To get started, Five routines perform tasks necessary to initialize a window. glutInit(int *argc, char **argv) glutInitDisplayMode(unsigned int mode) initializes GLUT and processes any command line arguments. glutInit() should be called before any other GLUT routine specifies whether to use an RGBA or color index color model. You can also specify whether you want a single or double buffered window. //glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
  • 16. Display-Window Management using GLUT glutInitWindowPosition(int x, int y) glutInitWindowSize(int width, int size) int glutCreateWindow(char *string) glClearColor (1.0, 1.0, 1.0, 0.0); specifies the screen location for the upper left corner of our window. specifies the size, in pixels, of our window set the background color for the display window The first three arguments in this function set the red, green, and blue component. Last parameter, alpha value. creates a window with an OpenGL context. It returns a unique identifier for the new window.
  • 17. Drawing Primitive Shapes.. • Drawing a Triangle glBegin (GL_TRIANGLES); //Start the draw triangle glVertex2f( 2, 1); glVertex2f(1, 1); glVertex2f(0, 2); glEnd() //End the draw triangle Vertices 2- indicates Parameter counts f- indicates float data type glBegin(Glenum mode); - mode is basically the type of primitive we’re drawing
  • 18. Drawing Primitive Shapes.. • Drawing other shapes glBegin(GL_POINTS); glVertex2f( -3, 2); glVertex2f(2, 1); glEnd(); glBegin(GL_LINES); glVertex2f( -2, -2); glVertex2f(2, -1); glEnd();
  • 19. Installation of codebook along with OPENGL
  • 20. Installation of codebook along with OPENGL
  • 21. Installation of codebook along with OPENGL
  • 22. Installation of codebook along with OPENGL
  • 23. Installation of codebook along with OPENGL
  • 24. Installation of codebook along with OPENGL
  • 25. Installation of codebook along with OPENGL
  • 26. Installation of codebook along with OPENGL
  • 27. Installation of codebook along with OPENGL
  • 28. Installation of codebook along with OPENGL
  • 29. Installation of codebook along with OPENGL
  • 30. Installation of codebook along with OPENGL
  • 31. Installation of codebook along with OPENGL
  • 32. Installation of codebook along with OPENGL
  • 33. Installation of codebook along with OPENGL
  • 34. OpenGL as a State Machine • OpenGL is a state machine. You put it into various states (or modes) that then remain in effect until you change them • the current color is a state variable. You can set the current color to white, red, or any other color, and thereafter every object is drawn with that color until you set the current color to something else • The current color is only one of many state variables that OpenGL maintains. • Others control such things as the current viewing and projection transformations, line and polygon stipple patterns, polygon drawing modes, pixel-packing conventions, positions and characteristics of lights, and material properties of the objects being drawn. • Many state variables refer to modes that are enabled or disabled with the command glEnable() or glDisable().
  • 35. OpenGL as a State Machine • OpenGL is by itself a large state machine: a collection of variables that define how OpenGL should currently operate. • The state of OpenGL is commonly referred to as the OpenGL context. • When using OpenGL, we often change its state by setting some options, manipulating some buffers and then render using the current context. • When working in OpenGL we will come across several state-changing functions that change the context and several state-using functions that perform some operations based on the current state of OpenGL.
  • 36. OpenGL as a State Machine • Each state variable or mode has a default value, and at any point you can query the system for each variable's current value • six following commands to do this • glGetBooleanv(), • glGetDoublev(), • glGetFloatv(), • glGetIntegerv(), • glGetPointerv(), • or glIsEnabled()
  • 37. OpenGL as a State Machine • can save a collection of state variables on an attribute stack with glPushAttrib() or glPushClientAttrib() • temporarily modify them, and later restore the values with glPopAttrib() or glPopClientAttrib().
  • 39. • Step 1 - Vertex Specification • The programmer can not make any changes or interventions in Vertex Specification. • For example, we want to draw a triangle on the monitor. • Each corner point of the triangle to be drawn is called a vertex and each vertex has x, y and z coordinates data in the drawing area. • Simple shapes drawn using vertices are called primitives. For example, the triangle shape that we wanted to draw is a primitive. • The vertices data are set as a bit series for the primitive/primitives that will be rendered in Vertex Specification.
  • 40. • Step 2 - Vertex Processing • Points called vertex in the previous step begin to be processed for rendering in this step. This step consists of several sub-steps. in this step, programmers can directly modify or intervene in the processing of vertexes with these sub-steps.
  • 41. • Step 2.1 - Vertex Shader • The programmer can make some changes or interventions in Vertex Shader. • The aim of Vertex Shader is to geometrically calculate the position and features of the 2D/3D model to be created by using vertices. Some interventions are made using GLSL commands in this step. The vertex data sent from the previous step to this step comes as a data series of bit type. The type of the bit data can be labeled when writing GLSL commands in this step. For example, “layout(location=0)” command is used to indicate that the vertex data received in the previous step is a location data. • Moreover, the vector sent in the previous step is transformed from a 3-element vector (x, y, z coordinates) to a 4-element vector in this step. The 1 number is added to the end of the vertex data to do this transformation. In this way, the new vector is converted to [x, y, z, 1]. • The purpose of this vector transformation is so that the matrix multiplication can be done correctly in the next steps. • The reason for adding 1 to the end of the vertices data is that the number 1 is an ineffective element in the multiplication process. • In other words, the purpose is that the matrix multiplications for the next steps can be done without distorting the original data.
  • 42. • Step 2.2 - Tessellation • The programmer can make some changes or interventions in Tessellation. • The data sent from the previous step can be converted into smaller primitives in this step because more detail and complexity can be added dynamically to 3D surfaces by breaking the primitives into smaller pieces. • The model/shape that we wanted to create can be converted to more realistic in this way.
  • 43. • Step 2.3 - Geometry Shader • The programmer can make some changes or interventions in Geometry Shader. • Geometry Shader is logically similar to Vertex Shader. More complex and new primitives are created by using the primitives sent from the previous step in the Geometry Shader, just like geometric shapes are created by using vertices in the Vertex Shader. • For example, a hexagon is created by using triangle shapes.
  • 44. • Step 3 - Vertex Post-Processing • The programmer can not make any changes or interventions in Vertex Post-Processing. • Values calculated in Vertex and Geometry Shader can be saved in this step if wish. • Sometimes, the drawing area that contains the shape wanted to create can be larger than the monitor on which the shape will be displayed. Unnecessary calculations are prevented by removing primitives that cannot be displayed on the monitor from the drawing screen in this step. • This processing is called clipping.
  • 45. • Step 4 - Primitive Assembly • The programmer can not make any changes or interventions in the Primitive Assembly. • Vertices are processed as a series and new shapes are rendered from these series in this step. For example, drawing 3 triangles from a 9-element vertex series. • In addition, Face Culling is done in this step. Face Culling processing means that invisible or too far to be seen in perspective primitives are in our drawing area removed from the drawing area.
  • 46. • Step 5 - Rasterization • The programmer can not make any changes or interventions in Rasterization. • Geometric shapes created in the previous step are converted into pixels called fragment data in this step. • Information such as the color and depth of each pixel of the shape/model to be wanted drawing is stored in the fragment data for the next step.
  • 47. • Step 6 - Fragment Shader • The programmer can make some changes or interventions in Fragment Shader. • Pixels named as fragment data in the previous step are processed in this step. In particular, the coloring of each pixel of the created shape/model is done at this stage. • In addition to coloring the pixels in this step, operations such as shading and lighting of each pixel are also processed. • GLSL commands are used at this stage, just like in Vertex Shader to perform the operations mentioned above.
  • 48. • Step 7 - Per-Sample Operations • The programmer can not make any changes or interventions in Per-Sample Operations. • First of all, the Depth Test is performed in this step. The Depth Test is the stage of whether the fragment data wanted drawing will be drawn or not. For example; If there is another fragment of data in front of the fragment data to be wanted drawing, the fragment data to be drawn will fail for the depth test. • Moreover, Color Blending is performed in this step. Using the operations described in the previous steps, the colors in the fragment data are mixed with each other and interact with overlapping fragment data in this stage. • As a result of all these steps, the rendering process of the scene is completed and the final 2D/3D shape is created.
  • 49. OpenGL-Related Libraries • OpenGL provides a powerful but primitive set of rendering commands. • All higher-level drawing must be done in terms of these commands. • A number of libraries exist to allow you to simplify your programming tasks, including the following: The OpenGL Utility Library (GLU) contains several routines that use lower-level OpenGL commands to perform such tasks as setting up matrices for specific viewing orientations and projections, performing polygon tessellation, and rendering surfaces.
  • 50. OpenGL-Related Libraries • For every window system, there is a library that extends the functionality of that window system to support OpenGL rendering. • For machines that use the X Window System, the OpenGL Extension to the X Window System (GLX) is provided as an adjunct to OpenGL • GLX routines use the prefix glX • For Microsoft Windows, the WGL routines provide the Windows to OpenGL interface. • All WGL routines use the prefix wgl.
  • 51. OpenGL-Related Libraries • The OpenGL Utility Toolkit (GLUT) is a window system- independent toolkit, written by Mark Kilgard. • GLUT routines use the prefix glut • Open Inventor is an object-oriented toolkit based on OpenGL which provides objects and methods for creating interactive three- dimensional graphics applications. • Open Inventor, which is written in C++, provides prebuilt objects and a built-in event model for user interaction, high-level application components for creating and editing three-dimensional scenes, and the ability to print objects and exchange data in other graphics formats. • Open Inventor is separate from OpenGL.
  • 52. OpenGL-Related Libraries • OpenGL Utility Toolkit (GLUT) • OpenGL drawing commands are limited to those that generate simple geometric primitives (points, lines, and polygons). • GLUT includes several routines that create more complicated three-dimensional objects such as a sphere, a torus, and a teapot. • OpenGL Utility Library, GLU, also has quadrics routines that create some of the same three-dimensional objects as GLUT, such as a sphere, cylinder, or cone.
  • 53. OpenGL-Related Libraries OpenGL Utility Toolkit (GLUT) Window Management-Five routines perform tasks necessary to initialize a window. • glutInit(int *argc, char **argv) initializes GLUT and processes any command line arguments (for X, this would be options like -display and -geometry). glutInit() should be called before any other GLUT routine. • glutInitDisplayMode(unsigned int mode) specifies whether to use an RGBA or color-index color model. You can also specify whether you want a single- or double-buffered window. (If you're working in color-index mode, you'll want to load certain colors into the color map; use glutSetColor() to do this.) Finally, you can use this routine to indicate that you want the window to have an associated depth, stencil, and/or accumulation buffer. For example, if you want a window with double buffering, the RGBA color model, and a depth buffer, you might call glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH). • glutInitWindowPosition(int x, int y) specifies the screen location for the upper-left corner of your window. • glutInitWindowSize(int width, int size) specifies the size, in pixels, of your window. • int glutCreateWindow(char *string) creates a window with an OpenGL context. It returns a unique identifier for the new window. Be warned: Until glutMainLoop() is called (see next section), the window is not yet displayed.
  • 54. OpenGL-Related Libraries OpenGL Utility Toolkit (GLUT) The Display Callback- • glutDisplayFunc(void (*func)(void)) is the first and most important event callback function. Whenever GLUT determines the contents of the window need to be redisplayed, the callback function registered by glutDisplayFunc() is executed. Therefore, you should put all the routines you need to redraw the scene in the display callback function. • If your program changes the contents of the window, sometimes you will have to call glutPostRedisplay(void), which gives glutMainLoop() a nudge to call the registered display callback at its next opportunity. • Running the Program
  • 55. OpenGL-Related Libraries OpenGL Utility Toolkit (GLUT) Running the Program- • The very last thing you must do is call glutMainLoop(void). • All windows that have been created are now shown, and rendering to those windows is now effective. • Event processing begins, and the registered display callback is triggered. • Once this loop is entered, it is never exited.
  • 56. Input Data You must provide several types of input data to the OpenGL pipeline: • Vertices - Vertices describe the shape of the desired geometric object. To specify vertices, you use glVertex*() commands in conjunction with glBegin() and glEnd() to create a point, line, or polygon. You can also use glRect*() to describe an entire rectangle at once.
  • 57. Input Data You must provide several types of input data to the OpenGL pipeline: • Edge flag - Edge flag - By default, all edges of polygons are boundary edges. Use the glEdgeFlag*() command to explicitly set the edge flag. • Current raster position- Specified with glRasterPos*(), the current raster position is used to determine raster coordinates for pixel and bitmap drawing operations.
  • 58. Input Data You must provide several types of input data to the OpenGL pipeline: • Current normal -A normal vector associated with a particular vertex determines how a surface at that vertex is oriented in three-dimensional space; this in turn affects how much light that particular vertex receives. Use glNormal*() to specify a normal vector. • Current color - The color of a vertex, together with the lighting conditions, determine the final,lit color. Color is specified with glColor*() if in RGBA mode or with glIndex*() if in colorindex mode.
  • 59. Input Data You must provide several types of input data to the OpenGL pipeline: • Current texture coordinates - Specified with glTexCoord*(), texture coordinates determine the location in a texture map that should be associated with a vertex of an object. • When glVertex*() is called, the resulting vertex inherits the current edge flag, normal, color, and texture coordinates. Therefore, glEdgeFlag*(), glNormal*(), glColor*(), and glTexCoord*() must be called before glVertex*() if they are to affect the resulting vertex.
  • 60. Vertex Array Objects (VAOs) If you are using OpenGL ES 3 or higher, you should use Vertex Array Objects (or "VAOs") to store your vertex attribute state. • Using a VAO allows the drivers to compile the vertex description format for repeated use. In addition, this frees you from having to cache the vertex format needed for glVertexAttribPointer. • Instead you specify individual vertex data in immediate mode (between glBegin() and glEnd() pairs), you can store vertex data in a set of arrays including vertex positions, normals, texture coordinates and color information. And you can draw only a selection of geometric primitives by dereferencing the array elements with array indices.
  • 61. VAO’S Take a look the following code to draw a cube with immediate mode. Each face needs 6 times of glVertex*() calls to make 2 triangles, for example, the front face has v0-v1-v2 and v2-v3-v0 triangles. A cube has 6 faces, so the total number of glVertex*() calls is 36. If you also specify normals, texture coordinates and colors to the corresponding vertices, it increases the number of OpenGL function calls. The other thing that you should notice is the vertex "v0" is shared with 3 adjacent faces; front, right and top face. In immediate mode, you have to provide this shared vertex 6 times, twice for each side as shown in the code.
  • 62. VAO’S • glBegin(GL_TRIANGLES); // draw a cube with 12 triangles • // front face ================= • glVertex3fv(v0); // v0-v1-v2 • glVertex3fv(v1); • glVertex3fv(v2); • glVertex3fv(v2); // v2-v3-v0 • glVertex3fv(v3); • glVertex3fv(v0); • // right face ================= • glVertex3fv(v0); // v0-v3-v4 • glVertex3fv(v3); • glVertex3fv(v4); • glVertex3fv(v4); // v4-v5-v0 • glVertex3fv(v5); • glVertex3fv(v0); • // top face =================== • glVertex3fv(v0); // v0-v5-v6 • glVertex3fv(v5); • glVertex3fv(v6); • glVertex3fv(v6); // v6-v1-v0 • glVertex3fv(v1); • glVertex3fv(v0); ... • // draw other 3 faces • glEnd();
  • 63. VAO’S Using vertex arrays reduces the number of function calls and redundant usage of shared vertices. Therefore, you may increase the performance of rendering. Here, 3 different OpenGL functions are explained to use vertex arrays; glDrawArrays(), glDrawElements() and glDrawRangeElements(). Although, better approach is using vertex buffer objects (VBO) or display lists.
  • 65. OpenGL Functions • A software API consisting of around several hundred functions that allow you to talk to your graphics hardware. • It is cross-platform and the most commonly used in professional graphics applications
  • 66. OpenGL Functions • 1.Primitive functions • 2.Attribute functions • 3.Viewing functions • 4.Transformation functions • 5.Input functions • 6.Control functions • 7.query functions. • Primitive functions
  • 67. OpenGL Functions • Primitive functions-To perform operations ranging from choosing the color with which we display a line segment. • Depending on the API,the primitives can include points, line, segments, polygons, pixels, text , and various type of curves and surfaces. • Example glBegin(GL_POINTS); glVertex2f(100.0,200.0); glEnd();
  • 68. OpenGL Functions glVertex2d, glVertex2f, glVertex2i, glVertex2s, glVertex3d, glVertex3f, glVertex3i, glVertex3s, glVertex4d, glVertex4f, glVertex4i, glVertex4s, glVertex2dv, glVertex2fv, glVertex2iv, glVertex2sv, glVertex3dv, glVertex3fv, glVertex3iv, glVertex3sv, glVertex4dv, glVertex4fv, glVertex4iv, glVertex4sv
  • 69. OpenGL Functions • The postfix specifies the format of parameters used by each function: • 2 means a 2D point x, y. • 3 means a 3D point x, y, and z. • 4 means a 3D point in homogeneous coordinates x, y, z, and w. [Homogeneous coordinates will be discussed in the lecture on Chapter 5.] • d means double type. • f means float type. • i means integer type. • s means short type. • v means vector type. • u[bsi] means unsigned version of that type
  • 70. OpenGL Functions Example: using vector type parameter double P1[2], P2[2], P3[2]; /* set values to P1, P2, P3. */ P1[0] = 1.5; P1[1] = -0.3; ...... glBegin(GL_POINTS); glVertex2dv(P1); glVertex2dv(P2); glVertex2dv(&P3[0]); /* This is equivalent. */ glEnd()
  • 71. OpenGL Functions • OpenGL lines • Three different line primitives can be created: • GL_LINES-draws a line segment for each pair of vertices. • GL_LINE_STRIP-draws a connected group of line segments from vertex v0to vn connecting a line between each vertex and the next in the order given. • GL_LINE_LOOPSimilar to GL_LINE_STRIP, except it closes the line fromvn to v0, defining a loop. glBegin(GL_LINE_LOOP); //make it a connected close line segment glVertex2f(0.0f, 2.0f); //note 2D form glVertex2f(1.0f, 2.0f); glVertex2f(0.0f, -2.0f); glVertex2f(-1.0f, 0.0f); glEnd();
  • 73. OpenGL Functions • OpenGL polygons • Front faces, back faces and rendering modes • glCullFace() -- specify whether front- or back-facing sides (faces) should be drawn • glFrontFace( ) -- define front- and back-facing polygons • glPolygonMode( ) -- select a polygon rasterization mode • Polygon Types • GL_POLYGON -- draws a polygon from vertex v0 to vn-1 • GL_QUADS -- draws a series of separate four-sided polygons • GL_TRIANGLES -- draws a series of separate three-sided polygons • GL_QUAD_STRIP -- draws a strip of connected quadrilaterals • GL_TRIANGLE_STRIP -- draws a strip of connected triangles • GL_TRIANGLE_FAN -- draws a strip of triangles connected about a common origin
  • 74. OpenGL Functions • OpenGL polygons The following code constructs a filled in parallelogram on the x-y plane: glBegin(GL_POLYGON); glVertex2f(0.0f, 2.0f); //note 2D form glVertex2f(1.0f, 2.0f); glVertex2f(0.0f, -2.0f); glVertex2f(-1.0f, 0.0f); glEnd();
  • 75. OpenGL Functions • The following draws a rectangle: glRectf(0f, 0f, 1f, 1f); // x0, y0, x1, y1: two opposite corners // of the rectangle. glBegin(GL_QUADS); glVertex2f(0.0f, 0.0f); //note 2D form glVertex2f(1.0f, 0.0f); glVertex2f(1.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd();
  • 76. OpenGL Functions • Attribute functions-Define the low level objects or atomic entities that our system can display. Eg glColor3f(1.0,0.0,0.0); glLineWidth(1.0);
  • 77. OpenGL Functions • Viewing functions-The viewing functions allows us to specify various views,although APIs differ in the degree of flexibility they provide in choosing a view. • Example • glViewport (xvmin, yvmin, vpWidth, vpHeight); • gluOrtho2D (xwmin, xwmax, ywmin, ywmax); • gluLookAt(…);
  • 78. OpenGL Functions • Transformation functions-Transformation function that allows to carry out transformations of objects,such as rotation, translation and scaling. • Example • glTranslatef (tx, ty, tz); • glRotatef (theta, vx, vy, vz); • glScalef (sx, sy, sz);
  • 79. OpenGL Functions • Input function- Allows us to deal with the diverse forms of input that characterize modern graphics systems. • void glutKeyboardFunc(void (*func) (unsigned char key, int x, int y));
  • 80. Animations Animation is the art of making drawings move or the method of photographing successive drawings, models, and puppets and manipulating them to appear as moving images.
  • 82. Animation: Introduction Images are manipulated to create moving images.
  • 83. Linear List Notation Languages Linear List Notation Languages • It is especially animation supporting language. • Example: • 42,53,B,rotate, “palm”, 1,30 • 42=> starting frame • 53=> ending frame • B=> table • rotate=>action • palm=>object • 1=>start angle • 30=>end angle
  • 85. Animation Tools Open source Tools • Blender • Containerize • openToonz • Pencil2D • Synfig • K-3D • Krita
  • 86. Animation Tools Paid Tools • Animate CC • Cartoon Animator
  • 87. HISTORY • Many people were involved in the history of animation and creating the first animations. However, there is only one person who is considered as the “Father of Animation.” • He is the French cartoonist, Émile Eugène Jean Louis Courtet, known as Émile Cohl. Cohl is the creator of the first fully animated movie called Fantasmagorie. It premiered in Paris on August 17, 1908.
  • 88. Types Of Animation • There are four main types of animation: 1. 2D animation 2. 3D animation 3. Stop motion animation 4. Motion graphics There is an additional type of animation called traditional animation. However, since traditional animation is the first type of 2D animation Traditional Animation Traditional animation is also called hand-drawing animation, classical animation, or cel animation. It consisted of drawing everything frame by frame, be it a character, a background, and everything in between.
  • 89. Types Of Animation • TRADITIONAL ANIMATION Traditional animation is also called hand-drawing animation, classical animation, or cel animation. It consisted of drawing everything frame by frame, be it a character, a background, and everything in between. These drawings were made on sheets of transparent paper and then photographed on an animation camera. After that, the final photographs were used to create movement in a two-dimensional space, animated on 12 frames per second (fps). Sometimes they were animated on 24fps for smoother movements and faster action.
  • 90. Types Of Animation • 2D ANIMATION • With traditional animation, animators were required to keep drawing the same characters over and over again. • That is not needed with vector-based 2D animation since the motion is controlled by vectors. • With vectors, every creation can be reused as many times as the animator wishes, without having to re- create the same backgrounds, characters, and so on. • Moreover, the movement of the characters is controlled by vectors.
  • 91. Types Of Animation • 3D ANIMATION • Also called CGI or Computer Animation, 3D animation is one of the most popular types of animation. 3D animation is used not only for feature films but also for short films, video games, ads, and more.
  • 92. 3D Animation vs. 2D Animation • Technical skillsets:excellent drawing skills to become a 3D designer. However, you will need to have a clear understanding of animating in 3D. • Moving instead of drawing:Compared to 2D animation, 3D animation will mainly consist of moving the character in a 3D program rather than drawing for different frames.
  • 93. Stop Motion Animation • Stop motion animation is similar to traditional animation since it also combines a series of images that document slight movements. • However, stop motion animation uses photographs of real objects and not drawings or vector animations. • Artists take pictures of real-life objects and scenes. After each object they move in the scene they have set up, they take a picture before making the next move or the next moves.
  • 94. Stop Motion Animation • They continue this process until they have a photo for each frame they want to use for their animation. • Similar to traditional 2D animation, when all frames are shown in a sequence right after the other, the objects seem like they are moving on their own. That’s how the illusion of movement is created with stop motion animation. • Before CGI animation, stop motion animation was the only animation type that gave viewers that “special effects” feeling.
  • 95. Motion Graphics • Motion graphics can be 2D and 3D and are mainly used to animate text, logos, and video clips. Motion graphics are called all digital graphics that create the illusion of motion. • Unlike 2D animation and 3D animation, you do not need to follow a particular storyline or focus on key characters with motion graphics.