SlideShare a Scribd company logo
1 of 56
Download to read offline
Opening ES 2.0/3.0 Programming
Introduction
Champ Yen
http://champyen.blogspot.com

1
Outline
●

3D mathematics

●

OpenGL ES 2.0 overview

●

Vertex/Fragment shader basic understanding

●

Further study.

02/07/14

2
Basic Matrix/Vector Review
●

Vector Notation

●

Vector Operations

●

Matrix Notation

●

Matrix Operations

●

Orthogonality

●

Right-Handed Coordinate

●

Transformation/Translation

02/07/14

3
Vectors - Notation

1, 2, 3
1
2
3

02/07/14

row vector

column vector

a

b

4
Operations of Vectors
●
●
●
●

Negate (vector with opposite direction)
Magnitude (length of a vector)
Multiply by a scalar (scale length)
Normalize (vector with same direction, length = 1)

●

+, -, distance

●

Dot, Cross

02/07/14

5
Operations of Vectors - Dot

Geometric meaning
Dot product tells the similarity between
two vectors.

02/07/14

6
Operations of Vectors - Cross

Geometric meaning

Cross product yields a vector that is perpendicular
to the original two vectors.

02/07/14

7
Matrices - Notation

Mr×c
row

m11 m12 m13 … m1(c-1) m1c
m21 m22 m23 … m2(c-1) m2c
m31 m32 m33 … m3(c-1) m3c
………………………...
m(r-1)1 m(r-1)2 m(r-1)3 … m(r-1)(c-1) m(r-1)c
mr1 mr2 mr3 …. mr(c-1) mrc

column

02/07/14

8
Matrices Operations
●

Identity matrix

●

Transposition (for Mrc, MTcr, mTij = mji)

●

Multiply with a scalar

●

Multiply two matrices

●

Multiply a vector with a matrix

●

Multiply a matrix with a vector

02/07/14

9
Orthogonality
●
●

Vector : a, b are orthogonal if a dot b = 0
Matrix : matrix m is orthogonal if m*mT = I => MT is M’s
inverse Matrix (M-1)

02/07/14

10
Coordinate – Right-Handed
+y

+x

+z
02/07/14

11
Linear Tranformation
+y
+y
’

A linear transformation
preserves straight and parallel
lines, and there is no
translation—the origin does
not move.
Applications:
 Rotation
+x  Scaling
 Reflection
…..

+z
’

+z
02/07/14

+x
’
12
2D Rotation
The coordinate of P’ in XY space is:
(x, y) => (x*cos + y*(-sin), x*sin + y*cos)
+y’

+y

P’

p
+x’

θ

02/07/14

cos -sin
sin cos

x
y

+x

13
Rotation in 3D
Mx=

1
0
0

My=

cos
0
-sin

Mz =

0
0
cos -sin
sin cos
0
1
0

cos -sin
sin cos
0
0

Rotation around X axis

sin
0
cos

Rotation around Y axis

0
0
1

Rotation around Z axis

v’ = Mv
02/07/14

14
Translation
+y

P’ - P =

P’
P

+x

P’ =
+z

02/07/14

dx
dy
dz

1
0
0
0

0
1
0
0

0
0
1
0

dx
dy
dz
1

P
1
15
Combination – Transformation & Translation
Rotation then Translation

1
0
0
0

0
1
0
0

0
0
1
0

dx
dy
dz
1

cos -sin 0
sin cos 0
0
0
1
0
0
0

0
0
0
1

x
y
z
1

1
0
0
0

dx
dy
dz
1

x
y
z
1

Translation then Rotation

cos -sin 0
sin cos 0
0
0
1
0
0
0

0
0
0
1

0
1
0
0

0
0
1
0

Yes! We can do multiple things in ONE matrix.
02/07/14

16
What is OpenGL ES?
●

OpenGL-based API for Embedded Systems

●

Removed redundant and expensive functionality

●

Kept as compatible with OpenGL as possible

●

Added features needed for embedded systems

02/07/14

17
http://developer.amd.com/media/gpu_assets/GDCMobile2006-Ginsburg-OpenGLES2.0.pdf
OpenGL ES 2.0 programming
●
●

OpenGL ES 1.1/2.0 pipeline
initialization


●

setup




●

window system
geometry
shader
texture

per-frame rendering



02/07/14

uniform
drawing primitives
18
OpenGL (ES) 1.x Pipeline
Triangles/Lines/Points

API
API

Primitive
Primitive
Processing Vertices
Processing

Vertex
Vertex
Buffer
Buffer
Objects
Objects

Alpha
Alpha
Test
Test

02/07/14

Transform
Transform
and
and
Lighting
Lighting

Primitive
Primitive
Assembly
Assembly

Rasterizer
Rasterizer

Texture
Texture
Environment
Environment

Colour
Colour
Sum
Sum

Fog
Fog

Depth
Depth
Stencil
Stencil

Color
Color
Buffer
Buffer
Blend
Blend

Dither
Dither

http://www.khronos.org/opengles/2_X/

Frame Buffer

19
OpenGL (ES) 2.0 Pipeline
Triangles/Lines/Points

API
API

Primitive
Primitive
Processing Vertices
Processing

Vertex
Vertex
Shader
Shader

Vertex
Vertex
Buffer
Buffer
Objects
Objects

Primitive
Primitive
Assembly
Assembly

Rasterizer
Rasterizer

Fragment
Fragment
Shader
Shader

Depth
Depth
Stencil
Stencil

Color
Color
Buffer
Buffer
Blend
Blend

Dither
Dither

Frame Buffer

This isn’t your father’s OpenGL! (*)
02/07/14

*) OpenGL SuperBible 4/E

20
OpenGL ES 2.0 Overview
●

Shader only

●

Not backwards compatible to 1.x

●

ES GLSL forms core of API

●

●

Shifts some burden to application But puts more power in
your hands
Convergence of desktop and handheld!

02/07/14

21
http://developer.amd.com/media/gpu_assets/GDCMobile2006-Ginsburg-OpenGLES2.0.pdf
Initialize
●

●

●

EGL
Play the same role as glx/wgl/cgl.
glDepthRange(n, f);
Specify the depth of window coordinate.
glViewport(x, y, w, h);
Specify the bottom-left corner and display width/height of
window coordinate.

02/07/14

22
What you see may not be what you think.
Normalized Device Coordinate
(-1, 1, 1)

Window Coordinate

(1, 1, 1)

glViewPort
glDepthRange

(0, h, 1)
(0, h, 0)

(w, h, 1)
(w, h, 0)

Viewport
Transform

(-1, -1, 1)
(1, -1, 1)

(0, 0, 1)
(0, 0, 0)

(-1, -1, -1)
02/07/14

eye

(1, -1, -1)

(w, 0, 1)
(w, 0, 0)

eye
23
What’s shader?
●

●
●

●

a set of software instructions which is used primarily to
calculate rendering effects. (*)
Apply to each vertex or pixel.
Expose the capability to program a specific stage in
graphics pipeline.
Leverage CPU burden to GPU.

02/07/14

*) http://en.wikipedia.org/wiki/Shader

24
Vertex & Fragments

02/07/14

25
Shader Create/Compilation
GLuint LoadShader(GLenum type, const char *shaderSrc)
{
GLuint shader;
GLint compiled;
// Create the shader object, type must be GL_VERTEX_SHADER or GL_FRAGMENT_SHADER
shader = glCreateShader(type);
if(shader == 0)
return 0;
// Load the shader source
glShaderSource(shader, 1, &shaderSrc, NULL); // Compile the shader
glCompileShader(shader);
// Check the compile status
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if(!compiled){
………
glDeleteShader(shader);
return 0;
}
return shader;
}
02/07/14

26
Program Create/Link
// Create the program object
programObject = glCreateProgram();
if(programObject == 0)
return 0;
glAttachShader(programObject, vertexShader);
glAttachShader(programObject, fragmentShader);
// Link the program
glLinkProgram(programObject);
// Check the link status
glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
if(!linked){
……
glDeleteProgram(programObject);
return FALSE;
}
…
// Use the program object
glUseProgram(programObject);

02/07/14

Linked Program
Vertex
Shader
Object
Fragment
Shader
Object

27
Vertex Shaders
output to fragment shader

02/07/14

28
GLSL
●

OpenGL Shading Language

●

C-Like Grammar

●

consistent version # with OpenGL since 3.3

●

GLSL ES 1.00 is based on GLSL 1.20

02/07/14

29
GLSL ES – Basic Types

vector/matrix types

textures
02/07/14

30
http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
Vertex Shader - Example
// uniforms used by the shaders
uniform mat4 u_mvp; // matrix to convert P from
// model space to clip space.
// attributes input to the vertex shader
attribute vec4 a_position; // input position value
attribute vec4 a_color;
// input vertex color
// varying variables – input to the fragment shader
varying vec4 v_color;
// output vertex color
void main()
{
v_color = a_color;
gl_Position = u_mvp * a_position;
}
02/07/14

31
Vertex Shader
Attributes: position, color,
normal, texture coordinate
… etc
Uniform: transform matrix,
light direction … etc

per-vertex info.
global info.

(0, 0.5, 0)

(-0.5, -0.5, 0)

02/07/14

(0.5, -0.5, 0)

32
Vertice Attributes
/* vertex without VBO, copy to GPU before
rendering each time*/
glEnableVertexAttribArray(vtxIdx);
glVertexAttribPointer(vtxIdx, vtxSize,
GL_FLOAT, GL_FALSE, vtxStride,
vtxBuf);
……
glBindAttribLocation(programObject,
vtxIdx, “a_position”);
glDrawElements(GL_TRIANGLES,
numIdx, GL_UNSIGNED_SHORT,
indices);

02/07/14

/* vertex with VBO, stored in GPU side */
glGenBuffer(1, &vboIds);
glBindBuffer(GL_ARRAY_BUFFER,
vboIdx);
glBufferData(GL_ARRAY_BUFFER,
vtxStride*numVtx, vtxBuf,
GL_STATIC);
offset = 0;
glEnableVertexAttribArray(vtxIdx);
glVertexAttribPointer(vtxIdx, vtxSize,
GL_FLOAT, GL_FALSE, vtxStride,
(void*)offset);
……
glBindAttribLocation(programObject,
vtxIdx, “a_position”);
glDrawElements(GL_TRIANGLES,
numIdx, GL_UNSIGNED_SHORT,
indices);
33
Primitives & Rasterization

02/07/14

34
Uniforms
GLint location;
GLfloat mvp[16];
…… (calculate ModelViewProjection matrix)
location = glGetUniformLocation(programObject, “u_mvp”);
glUniform4fv(location, mvp);
……

103/02/07

35
Coordinate Transformation
world space

e
ey

eye space

model space
View Matrix
Rotate
Translation

Model Matrix
Rotate/Scaling
Translation

Perspective
Projection

103/02/07

Projection
Matrix

(Mproj * (Mview * (Mmodel * vertex))) = (Mproj * Mview * Mmodel) * vertex
= Mmvp * vertex

NDC, clip coordinate

36
View Matrix(cont.)
world space’ = world space – Peye

+y
+y’

+y

+x’
+z’

world space

e
ey

+x’

+y’

+z’

Translation

ey

e

+x

+x
+z

+z
103/02/07

37
View Matrix(cont.)
+y

M
+y’

X’

Y’

Z’

=

X

Y

Z

+x’
+z’

world space’

I

e
ey

+x

=

-1
∴

M=

X’

Y’

1
0
0

Z’

=

T
X’

Y’

Z’

0
1
0

0
0
1

X’

=

Y’
Z’

103/02/07

38
Perspective Projection Matrix

103/02/07

http://www.songho.ca/opengl/gl_projectionmatrix.html
http://read.pudn.com/downloads130/doc/556616/perspective.doc

39
View Matrix
Mview
X’
Y’
Z’
0 0 0

0
0
0
1

Mview =

103/02/07

1
0
0
0

0
1
0
0

0
0 -Peye
1
0 1

xw
yw
zw
1

=

xe
ye
ze
1

X’
-dot(X’,Pe)
Y’
-dot(Y’,Pe)
Z’
-dot(Z’,Pe)
0 0 0
1
40
Perspective Projection Matrix

103/02/07

http://www.songho.ca/opengl/gl_projectionmatrix.html
http://read.pudn.com/downloads130/doc/556616/perspective.doc

41
Fragment Shader

Color of a pixel in a fragment

103/02/07

42
Fragment Shader - Example

varying vec4 v_color;
// input vertex color
void main(void)
{
gl_FragColor = v_color;
}

103/02/07

43
Fragment Shader
The varying inputs of fragment shader from vertex shader
is interpolated for each pixel of a fragment.

103/02/07

44
Per-fragment Lightinng
Per-vertex Lighting

Per-fragment Lighting

103/02/07

45
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=222753
Textures – 2D Texture
// Generate a texture object
glGenTextures(1, &textureId);
// Bind the texture object
glBindTexture(GL_TEXTURE_2D, textureId);
// Load the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height,
0, GL_RGB,GL_UNSIGNED_BYTE, pixels);
// Set the filtering mode
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_NEAREST);
…..
// Get the sampler locations
location = glGetUniformLocation(programObject, "s_texture");
// …
// Bind the texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureId);
// Set the sampler texture unit to 0
glUniform1i(location, 0);
103/02/07

●

Only Texture2D is supported
(0.0, 1.0)

(1.0, 1.0)

(0.0, 0.0)

(1.0, 0.0)

46
Fragment Shader – Texture Example

varying vec2 v_textcoord;
uniform sampler2D s_texture;
void main(void)
{
gl_FragColor
= texture2D(s_texture, v_textcoord);
}

103/02/07

47
Texture - Environment Cube Mapping
Environment mapping provides good reflection effect.

103/02/07

48
Depth Test
glEnable(GL_DEPTH_TEST);
without depth test

103/02/07

with depth test

49
Culling
Culling opertaion discards the specific side of each triagles.

glFrontFace(GL_CW);

//clockwise

glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
Clockwise

V0
103/02/07

Counter-Clockwise

V1

V2

V2

V1

V0
50
Scissor/Stencil/Dithering

Scissor

Stencil

Dithering
103/02/07

http://angra.blog31.fc2.com/blog-entry-52.html
http://iphone-3d-programming.labs.oreilly.com/ch06.html

51
Frame Buffer Objects – release the power of GPU
motion blur

Depth of Field

Bloom lighting
Light Scattering

103/02/07

http://developer.nvidia.com/docs/IO/8230/GDC2003_OpenGLShaderTricks.pdf
http://en.wikipedia.org/wiki/Bloom_%28shader_effect%29
http://developer.amd.com/media/gpu_assets/Scheuermann_DepthOfField.pdf
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch13.html
http://www.fabiensanglard.net/lightScattering/index.php

52
More Power on Desktop
●
●
●
●
●
●
●
●

3D texture
Uniform Buffer Object
Floating-Point Depth/Texture/Render buffer
Double Precision
Shader subroutines
Geometry Shader
Tessellation Shader
……..

103/02/07

53
Further Study
OpenGL ES 2.0 Programming Guide by Aaftab Munshi, Aaftab Munshi and Aaftab Munshi,
Addison-Wesley, ISBN13: 978-0321502797

OpenGL ES SuperBible 4th/5th edition by Richard S. Wright, Nicholas S Haemel, Graham
Sellers and Benjamin Lipchak, Addison-Wesley, ISBN13: 978-0321712615

3D Math Primer for Graphics and Game Development by Fletcher Dunn and Ian Parberry,
Jones & Bartlett Publishers , ISBN13: 978-1556229114

GPU Gems 3 by Hubert Nguyen, Addison-Wesley, ISBN13: 978-0321515261
Free Online: http://developer.nvidia.com/object/gpu-gems-3.html

103/02/07

54
Further Study
GPU Pro 2 edited by Wolfgang Engel, A K Peters/CRC Press (GPU Pro Series)
Original ShaderX series (http://tog.acm.org/resources/shaderx/)

OpenGL ES 2.0 specification (API 2.0.25, GLSL ES 1.0.17)
http://www.khronos.org/registry/gles/
OpenGL 4.1 Specification
http://www.opengl.org/registry/
NeHe
http://nehe.gamedev.net/
LightHouse3D
http://www.lighthouse3d.com/opengl/

103/02/07

55
Q&A
Thanks.

103/02/07

56

More Related Content

What's hot

iSCSI (Internet Small Computer System Interface)
iSCSI (Internet Small Computer System Interface)iSCSI (Internet Small Computer System Interface)
iSCSI (Internet Small Computer System Interface)Sayali Koranne
 
Verifiable Credentials 101 for SSI and Decentralized Digital Identity - Tyler...
Verifiable Credentials 101 for SSI and Decentralized Digital Identity - Tyler...Verifiable Credentials 101 for SSI and Decentralized Digital Identity - Tyler...
Verifiable Credentials 101 for SSI and Decentralized Digital Identity - Tyler...SSIMeetup
 
Introduction to the Dart language
Introduction to the Dart languageIntroduction to the Dart language
Introduction to the Dart languageJana Moudrá
 
Presentation On Group Policy in Windows Server 2012 R2 By Barek-IT
Presentation On Group Policy in Windows Server 2012 R2 By Barek-ITPresentation On Group Policy in Windows Server 2012 R2 By Barek-IT
Presentation On Group Policy in Windows Server 2012 R2 By Barek-ITMd. Abdul Barek
 
Identity management and single sign on - how much flexibility
Identity management and single sign on - how much flexibilityIdentity management and single sign on - how much flexibility
Identity management and single sign on - how much flexibilityRyan Dawson
 
Secure shell ppt
Secure shell pptSecure shell ppt
Secure shell pptsravya raju
 
Multi Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And TypesMulti Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And TypesEthan Cha
 
Game Design Fundamentals
Game Design FundamentalsGame Design Fundamentals
Game Design FundamentalsIntelligent_ly
 
18CS2005 Cryptography and Network Security
18CS2005 Cryptography and Network Security18CS2005 Cryptography and Network Security
18CS2005 Cryptography and Network SecurityKathirvel Ayyaswamy
 
Alastria Digital Identity: the Spanish Blockchain solution for SSI - Carlos P...
Alastria Digital Identity: the Spanish Blockchain solution for SSI - Carlos P...Alastria Digital Identity: the Spanish Blockchain solution for SSI - Carlos P...
Alastria Digital Identity: the Spanish Blockchain solution for SSI - Carlos P...SSIMeetup
 
Android Architecture
Android ArchitectureAndroid Architecture
Android Architecturedeepakshare
 
Zero-Knowledge Proofs: Privacy-Preserving Digital Identity with Clare Nelson
Zero-Knowledge Proofs: Privacy-Preserving Digital Identity with Clare NelsonZero-Knowledge Proofs: Privacy-Preserving Digital Identity with Clare Nelson
Zero-Knowledge Proofs: Privacy-Preserving Digital Identity with Clare NelsonSSIMeetup
 

What's hot (20)

iSCSI (Internet Small Computer System Interface)
iSCSI (Internet Small Computer System Interface)iSCSI (Internet Small Computer System Interface)
iSCSI (Internet Small Computer System Interface)
 
Ios development
Ios developmentIos development
Ios development
 
Verifiable Credentials 101 for SSI and Decentralized Digital Identity - Tyler...
Verifiable Credentials 101 for SSI and Decentralized Digital Identity - Tyler...Verifiable Credentials 101 for SSI and Decentralized Digital Identity - Tyler...
Verifiable Credentials 101 for SSI and Decentralized Digital Identity - Tyler...
 
Introduction to the Dart language
Introduction to the Dart languageIntroduction to the Dart language
Introduction to the Dart language
 
Presentation On Group Policy in Windows Server 2012 R2 By Barek-IT
Presentation On Group Policy in Windows Server 2012 R2 By Barek-ITPresentation On Group Policy in Windows Server 2012 R2 By Barek-IT
Presentation On Group Policy in Windows Server 2012 R2 By Barek-IT
 
Angular Fundamentals
Angular FundamentalsAngular Fundamentals
Angular Fundamentals
 
Identity management and single sign on - how much flexibility
Identity management and single sign on - how much flexibilityIdentity management and single sign on - how much flexibility
Identity management and single sign on - how much flexibility
 
Secure shell ppt
Secure shell pptSecure shell ppt
Secure shell ppt
 
3 ip address
3 ip address3 ip address
3 ip address
 
Multi Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And TypesMulti Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And Types
 
Open Source Licences
Open Source LicencesOpen Source Licences
Open Source Licences
 
Public Vs. Private Keys
Public Vs. Private KeysPublic Vs. Private Keys
Public Vs. Private Keys
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Unity3D Programming
Unity3D ProgrammingUnity3D Programming
Unity3D Programming
 
Game Design Fundamentals
Game Design FundamentalsGame Design Fundamentals
Game Design Fundamentals
 
18CS2005 Cryptography and Network Security
18CS2005 Cryptography and Network Security18CS2005 Cryptography and Network Security
18CS2005 Cryptography and Network Security
 
Web Security
Web SecurityWeb Security
Web Security
 
Alastria Digital Identity: the Spanish Blockchain solution for SSI - Carlos P...
Alastria Digital Identity: the Spanish Blockchain solution for SSI - Carlos P...Alastria Digital Identity: the Spanish Blockchain solution for SSI - Carlos P...
Alastria Digital Identity: the Spanish Blockchain solution for SSI - Carlos P...
 
Android Architecture
Android ArchitectureAndroid Architecture
Android Architecture
 
Zero-Knowledge Proofs: Privacy-Preserving Digital Identity with Clare Nelson
Zero-Knowledge Proofs: Privacy-Preserving Digital Identity with Clare NelsonZero-Knowledge Proofs: Privacy-Preserving Digital Identity with Clare Nelson
Zero-Knowledge Proofs: Privacy-Preserving Digital Identity with Clare Nelson
 

Viewers also liked

OpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering System
OpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering SystemOpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering System
OpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering Systemoasiskim
 
OpenGL ES Presentation
OpenGL ES PresentationOpenGL ES Presentation
OpenGL ES PresentationEric Cheng
 
OpenCL Kernel Optimization Tips
OpenCL Kernel Optimization TipsOpenCL Kernel Optimization Tips
OpenCL Kernel Optimization TipsChamp Yen
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtICS
 
Simd programming introduction
Simd programming introductionSimd programming introduction
Simd programming introductionChamp Yen
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - ShadersNick Pruehs
 
Introduction to protein structure
Introduction to protein structureIntroduction to protein structure
Introduction to protein structureBilal El Houdaigui
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open glArvind Devaraj
 
CG OpenGL vectors geometric & transformations-course 5
CG OpenGL vectors geometric & transformations-course 5CG OpenGL vectors geometric & transformations-course 5
CG OpenGL vectors geometric & transformations-course 5fungfung Chen
 
kgc2014 LINE Rangers/Stage 크래시 및 어뷰징 대응
kgc2014 LINE Rangers/Stage크래시 및 어뷰징 대응kgc2014 LINE Rangers/Stage크래시 및 어뷰징 대응
kgc2014 LINE Rangers/Stage 크래시 및 어뷰징 대응sewoon Nam
 
jQTouch at jQuery Conference 2010
jQTouch at jQuery Conference 2010jQTouch at jQuery Conference 2010
jQTouch at jQuery Conference 2010David Kaneda
 
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...David Kaneda
 
Play With Android
Play With AndroidPlay With Android
Play With AndroidChamp Yen
 
Introduction to open_gl_in_android
Introduction to open_gl_in_androidIntroduction to open_gl_in_android
Introduction to open_gl_in_androidtamillarasan
 

Viewers also liked (20)

OpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering System
OpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering SystemOpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering System
OpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering System
 
OpenGL ES Presentation
OpenGL ES PresentationOpenGL ES Presentation
OpenGL ES Presentation
 
OpenGL Basics
OpenGL BasicsOpenGL Basics
OpenGL Basics
 
OpenCL Kernel Optimization Tips
OpenCL Kernel Optimization TipsOpenCL Kernel Optimization Tips
OpenCL Kernel Optimization Tips
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
 
Simd programming introduction
Simd programming introductionSimd programming introduction
Simd programming introduction
 
Bai 1
Bai 1Bai 1
Bai 1
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - Shaders
 
Introduction to protein structure
Introduction to protein structureIntroduction to protein structure
Introduction to protein structure
 
OpenGL for 2015
OpenGL for 2015OpenGL for 2015
OpenGL for 2015
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
CG OpenGL vectors geometric & transformations-course 5
CG OpenGL vectors geometric & transformations-course 5CG OpenGL vectors geometric & transformations-course 5
CG OpenGL vectors geometric & transformations-course 5
 
Part I : Introduction to Protein Structure
Part I : Introduction to Protein StructurePart I : Introduction to Protein Structure
Part I : Introduction to Protein Structure
 
kgc2014 LINE Rangers/Stage 크래시 및 어뷰징 대응
kgc2014 LINE Rangers/Stage크래시 및 어뷰징 대응kgc2014 LINE Rangers/Stage크래시 및 어뷰징 대응
kgc2014 LINE Rangers/Stage 크래시 및 어뷰징 대응
 
jQTouch at jQuery Conference 2010
jQTouch at jQuery Conference 2010jQTouch at jQuery Conference 2010
jQTouch at jQuery Conference 2010
 
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
 
Introduction to LESS
Introduction to LESSIntroduction to LESS
Introduction to LESS
 
Play With Android
Play With AndroidPlay With Android
Play With Android
 
jQTouch and Titanium
jQTouch and TitaniumjQTouch and Titanium
jQTouch and Titanium
 
Introduction to open_gl_in_android
Introduction to open_gl_in_androidIntroduction to open_gl_in_android
Introduction to open_gl_in_android
 

Similar to OpenGL ES 2.x Programming Introduction

Open GL ES Android
Open GL ES AndroidOpen GL ES Android
Open GL ES AndroidMindos Cheng
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Prabindh Sundareson
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I💻 Anton Gerdelan
 
OpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsOpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsPrabindh Sundareson
 
OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading LanguageJungsoo Nam
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glchangehee lee
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...ICS
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and MoreMark Kilgard
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).pptHIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.pptHIMANKMISHRA2
 
GL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfGL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfshaikhshehzad024
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGLMegha V
 
GFX Part 1 - Introduction to GPU HW and OpenGL ES specifications
GFX Part 1 - Introduction to GPU HW and OpenGL ES specificationsGFX Part 1 - Introduction to GPU HW and OpenGL ES specifications
GFX Part 1 - Introduction to GPU HW and OpenGL ES specificationsPrabindh Sundareson
 
13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGLJungsoo Nam
 

Similar to OpenGL ES 2.x Programming Introduction (20)

Android native gl
Android native glAndroid native gl
Android native gl
 
Open GL ES Android
Open GL ES AndroidOpen GL ES Android
Open GL ES Android
 
How to Use OpenGL/ES on Native Activity
How to Use OpenGL/ES on Native ActivityHow to Use OpenGL/ES on Native Activity
How to Use OpenGL/ES on Native Activity
 
Opengl basics
Opengl basicsOpengl basics
Opengl basics
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
OpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsOpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI Platforms
 
OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading Language
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
GL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfGL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdf
 
Intro to OpenGL ES 2.0
Intro to OpenGL ES 2.0Intro to OpenGL ES 2.0
Intro to OpenGL ES 2.0
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGL
 
GFX Part 1 - Introduction to GPU HW and OpenGL ES specifications
GFX Part 1 - Introduction to GPU HW and OpenGL ES specificationsGFX Part 1 - Introduction to GPU HW and OpenGL ES specifications
GFX Part 1 - Introduction to GPU HW and OpenGL ES specifications
 
13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL
 
2D graphics
2D graphics2D graphics
2D graphics
 

Recently uploaded

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

OpenGL ES 2.x Programming Introduction

  • 1. Opening ES 2.0/3.0 Programming Introduction Champ Yen http://champyen.blogspot.com 1
  • 2. Outline ● 3D mathematics ● OpenGL ES 2.0 overview ● Vertex/Fragment shader basic understanding ● Further study. 02/07/14 2
  • 3. Basic Matrix/Vector Review ● Vector Notation ● Vector Operations ● Matrix Notation ● Matrix Operations ● Orthogonality ● Right-Handed Coordinate ● Transformation/Translation 02/07/14 3
  • 4. Vectors - Notation 1, 2, 3 1 2 3 02/07/14 row vector column vector a b 4
  • 5. Operations of Vectors ● ● ● ● Negate (vector with opposite direction) Magnitude (length of a vector) Multiply by a scalar (scale length) Normalize (vector with same direction, length = 1) ● +, -, distance ● Dot, Cross 02/07/14 5
  • 6. Operations of Vectors - Dot Geometric meaning Dot product tells the similarity between two vectors. 02/07/14 6
  • 7. Operations of Vectors - Cross Geometric meaning Cross product yields a vector that is perpendicular to the original two vectors. 02/07/14 7
  • 8. Matrices - Notation Mr×c row m11 m12 m13 … m1(c-1) m1c m21 m22 m23 … m2(c-1) m2c m31 m32 m33 … m3(c-1) m3c ………………………... m(r-1)1 m(r-1)2 m(r-1)3 … m(r-1)(c-1) m(r-1)c mr1 mr2 mr3 …. mr(c-1) mrc column 02/07/14 8
  • 9. Matrices Operations ● Identity matrix ● Transposition (for Mrc, MTcr, mTij = mji) ● Multiply with a scalar ● Multiply two matrices ● Multiply a vector with a matrix ● Multiply a matrix with a vector 02/07/14 9
  • 10. Orthogonality ● ● Vector : a, b are orthogonal if a dot b = 0 Matrix : matrix m is orthogonal if m*mT = I => MT is M’s inverse Matrix (M-1) 02/07/14 10
  • 12. Linear Tranformation +y +y ’ A linear transformation preserves straight and parallel lines, and there is no translation—the origin does not move. Applications:  Rotation +x  Scaling  Reflection ….. +z ’ +z 02/07/14 +x ’ 12
  • 13. 2D Rotation The coordinate of P’ in XY space is: (x, y) => (x*cos + y*(-sin), x*sin + y*cos) +y’ +y P’ p +x’ θ 02/07/14 cos -sin sin cos x y +x 13
  • 14. Rotation in 3D Mx= 1 0 0 My= cos 0 -sin Mz = 0 0 cos -sin sin cos 0 1 0 cos -sin sin cos 0 0 Rotation around X axis sin 0 cos Rotation around Y axis 0 0 1 Rotation around Z axis v’ = Mv 02/07/14 14
  • 15. Translation +y P’ - P = P’ P +x P’ = +z 02/07/14 dx dy dz 1 0 0 0 0 1 0 0 0 0 1 0 dx dy dz 1 P 1 15
  • 16. Combination – Transformation & Translation Rotation then Translation 1 0 0 0 0 1 0 0 0 0 1 0 dx dy dz 1 cos -sin 0 sin cos 0 0 0 1 0 0 0 0 0 0 1 x y z 1 1 0 0 0 dx dy dz 1 x y z 1 Translation then Rotation cos -sin 0 sin cos 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 Yes! We can do multiple things in ONE matrix. 02/07/14 16
  • 17. What is OpenGL ES? ● OpenGL-based API for Embedded Systems ● Removed redundant and expensive functionality ● Kept as compatible with OpenGL as possible ● Added features needed for embedded systems 02/07/14 17 http://developer.amd.com/media/gpu_assets/GDCMobile2006-Ginsburg-OpenGLES2.0.pdf
  • 18. OpenGL ES 2.0 programming ● ● OpenGL ES 1.1/2.0 pipeline initialization  ● setup    ● window system geometry shader texture per-frame rendering   02/07/14 uniform drawing primitives 18
  • 19. OpenGL (ES) 1.x Pipeline Triangles/Lines/Points API API Primitive Primitive Processing Vertices Processing Vertex Vertex Buffer Buffer Objects Objects Alpha Alpha Test Test 02/07/14 Transform Transform and and Lighting Lighting Primitive Primitive Assembly Assembly Rasterizer Rasterizer Texture Texture Environment Environment Colour Colour Sum Sum Fog Fog Depth Depth Stencil Stencil Color Color Buffer Buffer Blend Blend Dither Dither http://www.khronos.org/opengles/2_X/ Frame Buffer 19
  • 20. OpenGL (ES) 2.0 Pipeline Triangles/Lines/Points API API Primitive Primitive Processing Vertices Processing Vertex Vertex Shader Shader Vertex Vertex Buffer Buffer Objects Objects Primitive Primitive Assembly Assembly Rasterizer Rasterizer Fragment Fragment Shader Shader Depth Depth Stencil Stencil Color Color Buffer Buffer Blend Blend Dither Dither Frame Buffer This isn’t your father’s OpenGL! (*) 02/07/14 *) OpenGL SuperBible 4/E 20
  • 21. OpenGL ES 2.0 Overview ● Shader only ● Not backwards compatible to 1.x ● ES GLSL forms core of API ● ● Shifts some burden to application But puts more power in your hands Convergence of desktop and handheld! 02/07/14 21 http://developer.amd.com/media/gpu_assets/GDCMobile2006-Ginsburg-OpenGLES2.0.pdf
  • 22. Initialize ● ● ● EGL Play the same role as glx/wgl/cgl. glDepthRange(n, f); Specify the depth of window coordinate. glViewport(x, y, w, h); Specify the bottom-left corner and display width/height of window coordinate. 02/07/14 22
  • 23. What you see may not be what you think. Normalized Device Coordinate (-1, 1, 1) Window Coordinate (1, 1, 1) glViewPort glDepthRange (0, h, 1) (0, h, 0) (w, h, 1) (w, h, 0) Viewport Transform (-1, -1, 1) (1, -1, 1) (0, 0, 1) (0, 0, 0) (-1, -1, -1) 02/07/14 eye (1, -1, -1) (w, 0, 1) (w, 0, 0) eye 23
  • 24. What’s shader? ● ● ● ● a set of software instructions which is used primarily to calculate rendering effects. (*) Apply to each vertex or pixel. Expose the capability to program a specific stage in graphics pipeline. Leverage CPU burden to GPU. 02/07/14 *) http://en.wikipedia.org/wiki/Shader 24
  • 26. Shader Create/Compilation GLuint LoadShader(GLenum type, const char *shaderSrc) { GLuint shader; GLint compiled; // Create the shader object, type must be GL_VERTEX_SHADER or GL_FRAGMENT_SHADER shader = glCreateShader(type); if(shader == 0) return 0; // Load the shader source glShaderSource(shader, 1, &shaderSrc, NULL); // Compile the shader glCompileShader(shader); // Check the compile status glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); if(!compiled){ ……… glDeleteShader(shader); return 0; } return shader; } 02/07/14 26
  • 27. Program Create/Link // Create the program object programObject = glCreateProgram(); if(programObject == 0) return 0; glAttachShader(programObject, vertexShader); glAttachShader(programObject, fragmentShader); // Link the program glLinkProgram(programObject); // Check the link status glGetProgramiv(programObject, GL_LINK_STATUS, &linked); if(!linked){ …… glDeleteProgram(programObject); return FALSE; } … // Use the program object glUseProgram(programObject); 02/07/14 Linked Program Vertex Shader Object Fragment Shader Object 27
  • 28. Vertex Shaders output to fragment shader 02/07/14 28
  • 29. GLSL ● OpenGL Shading Language ● C-Like Grammar ● consistent version # with OpenGL since 3.3 ● GLSL ES 1.00 is based on GLSL 1.20 02/07/14 29
  • 30. GLSL ES – Basic Types vector/matrix types textures 02/07/14 30 http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
  • 31. Vertex Shader - Example // uniforms used by the shaders uniform mat4 u_mvp; // matrix to convert P from // model space to clip space. // attributes input to the vertex shader attribute vec4 a_position; // input position value attribute vec4 a_color; // input vertex color // varying variables – input to the fragment shader varying vec4 v_color; // output vertex color void main() { v_color = a_color; gl_Position = u_mvp * a_position; } 02/07/14 31
  • 32. Vertex Shader Attributes: position, color, normal, texture coordinate … etc Uniform: transform matrix, light direction … etc per-vertex info. global info. (0, 0.5, 0) (-0.5, -0.5, 0) 02/07/14 (0.5, -0.5, 0) 32
  • 33. Vertice Attributes /* vertex without VBO, copy to GPU before rendering each time*/ glEnableVertexAttribArray(vtxIdx); glVertexAttribPointer(vtxIdx, vtxSize, GL_FLOAT, GL_FALSE, vtxStride, vtxBuf); …… glBindAttribLocation(programObject, vtxIdx, “a_position”); glDrawElements(GL_TRIANGLES, numIdx, GL_UNSIGNED_SHORT, indices); 02/07/14 /* vertex with VBO, stored in GPU side */ glGenBuffer(1, &vboIds); glBindBuffer(GL_ARRAY_BUFFER, vboIdx); glBufferData(GL_ARRAY_BUFFER, vtxStride*numVtx, vtxBuf, GL_STATIC); offset = 0; glEnableVertexAttribArray(vtxIdx); glVertexAttribPointer(vtxIdx, vtxSize, GL_FLOAT, GL_FALSE, vtxStride, (void*)offset); …… glBindAttribLocation(programObject, vtxIdx, “a_position”); glDrawElements(GL_TRIANGLES, numIdx, GL_UNSIGNED_SHORT, indices); 33
  • 35. Uniforms GLint location; GLfloat mvp[16]; …… (calculate ModelViewProjection matrix) location = glGetUniformLocation(programObject, “u_mvp”); glUniform4fv(location, mvp); …… 103/02/07 35
  • 36. Coordinate Transformation world space e ey eye space model space View Matrix Rotate Translation Model Matrix Rotate/Scaling Translation Perspective Projection 103/02/07 Projection Matrix (Mproj * (Mview * (Mmodel * vertex))) = (Mproj * Mview * Mmodel) * vertex = Mmvp * vertex NDC, clip coordinate 36
  • 37. View Matrix(cont.) world space’ = world space – Peye +y +y’ +y +x’ +z’ world space e ey +x’ +y’ +z’ Translation ey e +x +x +z +z 103/02/07 37
  • 40. View Matrix Mview X’ Y’ Z’ 0 0 0 0 0 0 1 Mview = 103/02/07 1 0 0 0 0 1 0 0 0 0 -Peye 1 0 1 xw yw zw 1 = xe ye ze 1 X’ -dot(X’,Pe) Y’ -dot(Y’,Pe) Z’ -dot(Z’,Pe) 0 0 0 1 40
  • 42. Fragment Shader Color of a pixel in a fragment 103/02/07 42
  • 43. Fragment Shader - Example varying vec4 v_color; // input vertex color void main(void) { gl_FragColor = v_color; } 103/02/07 43
  • 44. Fragment Shader The varying inputs of fragment shader from vertex shader is interpolated for each pixel of a fragment. 103/02/07 44
  • 45. Per-fragment Lightinng Per-vertex Lighting Per-fragment Lighting 103/02/07 45 http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=222753
  • 46. Textures – 2D Texture // Generate a texture object glGenTextures(1, &textureId); // Bind the texture object glBindTexture(GL_TEXTURE_2D, textureId); // Load the texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,GL_UNSIGNED_BYTE, pixels); // Set the filtering mode glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); ….. // Get the sampler locations location = glGetUniformLocation(programObject, "s_texture"); // … // Bind the texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textureId); // Set the sampler texture unit to 0 glUniform1i(location, 0); 103/02/07 ● Only Texture2D is supported (0.0, 1.0) (1.0, 1.0) (0.0, 0.0) (1.0, 0.0) 46
  • 47. Fragment Shader – Texture Example varying vec2 v_textcoord; uniform sampler2D s_texture; void main(void) { gl_FragColor = texture2D(s_texture, v_textcoord); } 103/02/07 47
  • 48. Texture - Environment Cube Mapping Environment mapping provides good reflection effect. 103/02/07 48
  • 49. Depth Test glEnable(GL_DEPTH_TEST); without depth test 103/02/07 with depth test 49
  • 50. Culling Culling opertaion discards the specific side of each triagles. glFrontFace(GL_CW); //clockwise glCullFace(GL_BACK); glEnable(GL_CULL_FACE); Clockwise V0 103/02/07 Counter-Clockwise V1 V2 V2 V1 V0 50
  • 52. Frame Buffer Objects – release the power of GPU motion blur Depth of Field Bloom lighting Light Scattering 103/02/07 http://developer.nvidia.com/docs/IO/8230/GDC2003_OpenGLShaderTricks.pdf http://en.wikipedia.org/wiki/Bloom_%28shader_effect%29 http://developer.amd.com/media/gpu_assets/Scheuermann_DepthOfField.pdf http://http.developer.nvidia.com/GPUGems3/gpugems3_ch13.html http://www.fabiensanglard.net/lightScattering/index.php 52
  • 53. More Power on Desktop ● ● ● ● ● ● ● ● 3D texture Uniform Buffer Object Floating-Point Depth/Texture/Render buffer Double Precision Shader subroutines Geometry Shader Tessellation Shader …….. 103/02/07 53
  • 54. Further Study OpenGL ES 2.0 Programming Guide by Aaftab Munshi, Aaftab Munshi and Aaftab Munshi, Addison-Wesley, ISBN13: 978-0321502797 OpenGL ES SuperBible 4th/5th edition by Richard S. Wright, Nicholas S Haemel, Graham Sellers and Benjamin Lipchak, Addison-Wesley, ISBN13: 978-0321712615 3D Math Primer for Graphics and Game Development by Fletcher Dunn and Ian Parberry, Jones & Bartlett Publishers , ISBN13: 978-1556229114 GPU Gems 3 by Hubert Nguyen, Addison-Wesley, ISBN13: 978-0321515261 Free Online: http://developer.nvidia.com/object/gpu-gems-3.html 103/02/07 54
  • 55. Further Study GPU Pro 2 edited by Wolfgang Engel, A K Peters/CRC Press (GPU Pro Series) Original ShaderX series (http://tog.acm.org/resources/shaderx/) OpenGL ES 2.0 specification (API 2.0.25, GLSL ES 1.0.17) http://www.khronos.org/registry/gles/ OpenGL 4.1 Specification http://www.opengl.org/registry/ NeHe http://nehe.gamedev.net/ LightHouse3D http://www.lighthouse3d.com/opengl/ 103/02/07 55