Introduction to Computer Graphics with OpenGL

blareweyrΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

72 εμφανίσεις

Introduction to Computer Graphics with OpenGL
Ioannis Tsiombikas
nuclear@member.fsf.org
9th unipi free software event
What is OpenGL?
OpenGL Specification
A specification of an interface between an application program and
a 3D renderer based on z-buffered polygon rasterization.
OpenGL Implementation
Software implementation:C library implementing all of the
OpenGL operations (Mesa,SGI reference implementation).
Hardware implementation:C library communicating with
kernel-space graphics driver.This setup implements most of
OpenGL in hardware graphics processors.(Mesa-DRI,SGI,
nvidia,ATI).
What is OpenGL?
OpenGL Specification
A specification of an interface between an application program and
a 3D renderer based on z-buffered polygon rasterization.
OpenGL Implementation
Software implementation:C library implementing all of the
OpenGL operations (Mesa,SGI reference implementation).
Hardware implementation:C library communicating with
kernel-space graphics driver.This setup implements most of
OpenGL in hardware graphics processors.(Mesa-DRI,SGI,
nvidia,ATI).
What is OpenGL?
OpenGL Specification
A specification of an interface between an application program and
a 3D renderer based on z-buffered polygon rasterization.
OpenGL Implementation
Software implementation:C library implementing all of the
OpenGL operations (Mesa,SGI reference implementation).
Hardware implementation:C library communicating with
kernel-space graphics driver.This setup implements most of
OpenGL in hardware graphics processors.(Mesa-DRI,SGI,
nvidia,ATI).
OpenGL Overview
Notable attributes of OpenGL:
Controlled by a committee,the Architecture Review Board or
ARB.
Stable core API.New features are introduced through an
extension mechanism.
Cross-platform,OpenGL implementations available for
everything that can be connected to a raster display.
Only handles graphics.No input/event handling,sound,etc.
Depends on system-specific glue libraries to work with the
window system (GLX).
OpenGL Overview
Notable attributes of OpenGL:
Controlled by a committee,the Architecture Review Board or
ARB.
Stable core API.New features are introduced through an
extension mechanism.
Cross-platform,OpenGL implementations available for
everything that can be connected to a raster display.
Only handles graphics.No input/event handling,sound,etc.
Depends on system-specific glue libraries to work with the
window system (GLX).
OpenGL Overview
Notable attributes of OpenGL:
Controlled by a committee,the Architecture Review Board or
ARB.
Stable core API.New features are introduced through an
extension mechanism.
Cross-platform,OpenGL implementations available for
everything that can be connected to a raster display.
Only handles graphics.No input/event handling,sound,etc.
Depends on system-specific glue libraries to work with the
window system (GLX).
OpenGL Overview
Notable attributes of OpenGL:
Controlled by a committee,the Architecture Review Board or
ARB.
Stable core API.New features are introduced through an
extension mechanism.
Cross-platform,OpenGL implementations available for
everything that can be connected to a raster display.
Only handles graphics.No input/event handling,sound,etc.
Depends on system-specific glue libraries to work with the
window system (GLX).
OpenGL Overview
Notable attributes of OpenGL:
Controlled by a committee,the Architecture Review Board or
ARB.
Stable core API.New features are introduced through an
extension mechanism.
Cross-platform,OpenGL implementations available for
everything that can be connected to a raster display.
Only handles graphics.No input/event handling,sound,etc.
Depends on system-specific glue libraries to work with the
window system (GLX).
OpenGL Overview (cont.)
Simple state-based API.
Client-server architecture.
Network transparent (when used in conjunction with a real
window system).
OpenGL Overview (cont.)
Simple state-based API.
Client-server architecture.
Network transparent (when used in conjunction with a real
window system).
OpenGL Overview (cont.)
Simple state-based API.
Client-server architecture.
Network transparent (when used in conjunction with a real
window system).
OpenGL Overview (cont.)
Simple state-based API.
Client-server architecture.
Network transparent (when used in conjunction with a real
window system).
The Rendering Pipeline
xy
z
Local Coordinate System
x
y
z
World Space
xy
z
View Space
xy
z
Post−Projection Clip Space
−1 1
Output raster image
World Transformation
(model matrix)
Viewing Transformation
(view matrix)
Projection Transformation
(projection matrix)
Rasterization
Transformations
Any linear transformation in 3D space can be defined by a 3x3
matrix.However in order to be able to also represent affine
transformations,and perspective projections,we must work in
homogeneous coordinates.
Thus,we work with 4D vectors (x y z w) where w = 1,and
transform them using 4x4 matrices.




x

y

z

w





=




m
11
m
12
m
13
m
14
m
21
m
22
m
23
m
24
m
31
m
32
m
33
m
34
m
41
m
42
m
43
m
44









x
y
z
1




Constructing Transformation Matrices
R
x
(θ) =




1 0 0 0
0 cos θ −sinθ 0
0 sinθ cos θ 0
0 0 0 1




R
y
(θ) =




cos θ 0 sinθ 0
0 1 0 0
−sinθ 0 cos θ 0
0 0 0 1




R
z
(θ) =




cos θ −sinθ 0 0
sinθ cos θ 0 0
0 0 1 0
0 0 0 1




T(t
x
,t
y
,t
z
) =




1 0 0 t
x
0 1 0 t
y
0 0 1 t
z
0 0 0 1




S(s
x
,s
y
,s
z
) =




s
x
0 0 0
0 s
y
0 0
0 0 s
z
0
0 0 0 1




Transformations in OpenGL
OpenGL handles transformations (ideally in hardware),we need
only supply the matrices.
Before calling any matrix manipulation function we must specify
which matrix we want to affect.This is done by calling
glMatrixMode().Possible arguments:GL
MODELVIEW,
GL
PROJECTION,GL
TEXTURE.
glLoadIdentity()
glLoadMatrix() and glMultMatrix()
glTranslate(),glRotate(),and glScale()
Actually a stack of matrices is maintained for each
transformation.glPushMatrix() and glPopMatrix() are
used to manipulate the stack.
Transformations in OpenGL
OpenGL handles transformations (ideally in hardware),we need
only supply the matrices.
Before calling any matrix manipulation function we must specify
which matrix we want to affect.This is done by calling
glMatrixMode().Possible arguments:GL
MODELVIEW,
GL
PROJECTION,GL
TEXTURE.
glLoadIdentity()
glLoadMatrix() and glMultMatrix()
glTranslate(),glRotate(),and glScale()
Actually a stack of matrices is maintained for each
transformation.glPushMatrix() and glPopMatrix() are
used to manipulate the stack.
Transformations in OpenGL
OpenGL handles transformations (ideally in hardware),we need
only supply the matrices.
Before calling any matrix manipulation function we must specify
which matrix we want to affect.This is done by calling
glMatrixMode().Possible arguments:GL
MODELVIEW,
GL
PROJECTION,GL
TEXTURE.
glLoadIdentity()
glLoadMatrix() and glMultMatrix()
glTranslate(),glRotate(),and glScale()
Actually a stack of matrices is maintained for each
transformation.glPushMatrix() and glPopMatrix() are
used to manipulate the stack.
Transformations in OpenGL
OpenGL handles transformations (ideally in hardware),we need
only supply the matrices.
Before calling any matrix manipulation function we must specify
which matrix we want to affect.This is done by calling
glMatrixMode().Possible arguments:GL
MODELVIEW,
GL
PROJECTION,GL
TEXTURE.
glLoadIdentity()
glLoadMatrix() and glMultMatrix()
glTranslate(),glRotate(),and glScale()
Actually a stack of matrices is maintained for each
transformation.glPushMatrix() and glPopMatrix() are
used to manipulate the stack.
Transformations in OpenGL
OpenGL handles transformations (ideally in hardware),we need
only supply the matrices.
Before calling any matrix manipulation function we must specify
which matrix we want to affect.This is done by calling
glMatrixMode().Possible arguments:GL
MODELVIEW,
GL
PROJECTION,GL
TEXTURE.
glLoadIdentity()
glLoadMatrix() and glMultMatrix()
glTranslate(),glRotate(),and glScale()
Actually a stack of matrices is maintained for each
transformation.glPushMatrix() and glPopMatrix() are
used to manipulate the stack.
3D Object Representation
A collection of polygons are used to approximate the surface of any
object.
A rubber duck
Vertex attributes:
Position vector.
Normal vector.
Color.
Texture coordinates.
3D Object Representation
A collection of polygons are used to approximate the surface of any
object.
A rubber duck
Vertex attributes:
Position vector.
Normal vector.
Color.
Texture coordinates.
OpenGL 3D Object Data
A number of methods can be used to supply polygons and vertex
data to OpenGL:
Immediate mode (glBegin()/glEnd()).
Display lists.
Vertex arrays (stored client side).
Vertex buffer objects (server-side vertex arrays).
OpenGL 3D Object Data
A number of methods can be used to supply polygons and vertex
data to OpenGL:
Immediate mode (glBegin()/glEnd()).
Display lists.
Vertex arrays (stored client side).
Vertex buffer objects (server-side vertex arrays).
OpenGL 3D Object Data
A number of methods can be used to supply polygons and vertex
data to OpenGL:
Immediate mode (glBegin()/glEnd()).
Display lists.
Vertex arrays (stored client side).
Vertex buffer objects (server-side vertex arrays).
OpenGL 3D Object Data
A number of methods can be used to supply polygons and vertex
data to OpenGL:
Immediate mode (glBegin()/glEnd()).
Display lists.
Vertex arrays (stored client side).
Vertex buffer objects (server-side vertex arrays).
OpenGL 3D Object Data
A number of methods can be used to supply polygons and vertex
data to OpenGL:
Immediate mode (glBegin()/glEnd()).
Display lists.
Vertex arrays (stored client side).
Vertex buffer objects (server-side vertex arrays).
Shading Algorithms
Flat Shading
Gouraud Shading
Phong Shading
Phong Reflectance Model
OpenGL calculates a color for each vertex (or face if flat-shading is
enabled) by combining illumination intensity with material colors.
Illumination intensity is calculated according to the phong
reflectance model.
AM
a
+(L∙ N) M
d
+(L∙ V
r
)
M
p
M
s
N
L
V
rV
OpenGL Materials
Material parameters (to be used as factors in the phong equation),
are given to OpenGL through glMaterial:
Material colors (ambient,diffuse,and specular).
Specular exponent.
Self-illumination.
OpenGL Lights
Lighting is enabled by glEnable-ing GL
LIGHTING and
GL
LIGHTn,where 0 ≤ n < GL
MAX
LIGHTS.
Light types:point lights,directional lights,and spotlights.
Light parameters are given to OpenGL through the glLight()
functions:
Position or direction.
Color.
Attenuation coefficients (constant,linear,and quadratic).
Spotlight cone.
OpenGL Lights
Lighting is enabled by glEnable-ing GL
LIGHTING and
GL
LIGHTn,where 0 ≤ n < GL
MAX
LIGHTS.
Light types:point lights,directional lights,and spotlights.
Light parameters are given to OpenGL through the glLight()
functions:
Position or direction.
Color.
Attenuation coefficients (constant,linear,and quadratic).
Spotlight cone.
OpenGL Lights
Lighting is enabled by glEnable-ing GL
LIGHTING and
GL
LIGHTn,where 0 ≤ n < GL
MAX
LIGHTS.
Light types:point lights,directional lights,and spotlights.
Light parameters are given to OpenGL through the glLight()
functions:
Position or direction.
Color.
Attenuation coefficients (constant,linear,and quadratic).
Spotlight cone.
THE END