an ios developer's opengl primer

Upload: 3bqb3xvu3x

Post on 06-Apr-2018

241 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 An iOS Developer's OpenGL Primer

    1/185

    An iOS DevelopersOpenGL Primer

    ThingsMade Out Of OtherThings

    Jamie Montgomerie@th_in_gs

  • 8/3/2019 An iOS Developer's OpenGL Primer

    2/185

  • 8/3/2019 An iOS Developer's OpenGL Primer

    3/185

  • 8/3/2019 An iOS Developer's OpenGL Primer

    4/185

  • 8/3/2019 An iOS Developer's OpenGL Primer

    5/185

  • 8/3/2019 An iOS Developer's OpenGL Primer

    6/185

  • 8/3/2019 An iOS Developer's OpenGL Primer

    7/185

    OpenGL ES 2.0

  • 8/3/2019 An iOS Developer's OpenGL Primer

    8/185

    A transparent, lightweight, interface to

    modern graphics hardware.

    OpenGL ES 2.0

  • 8/3/2019 An iOS Developer's OpenGL Primer

    9/185

    Why Use OpenGL?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    10/185

    Why Use OpenGL?

    Flexibility

  • 8/3/2019 An iOS Developer's OpenGL Primer

    11/185

    Why Use OpenGL?

    Flexibility

    Performance

  • 8/3/2019 An iOS Developer's OpenGL Primer

    12/185

    How OpenGL uses

    your hardware to putstuff on the screen.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    13/185

    How you can use

    OpenGL to putyour stuff on the screen.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    14/185

  • 8/3/2019 An iOS Developer's OpenGL Primer

    15/185

  • 8/3/2019 An iOS Developer's OpenGL Primer

    16/185

    What makes all that stuff

    ha en?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    17/185

    A transparent, lightweight, interface to

    modern graphics hardware.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    18/185

    A transparent, lightweight, interface tomodern graphics hardware.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    19/185

    A transparent, lightweight, interface tomodern graphics hardware.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    20/185

    Where do the

    ixels come from?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    21/185

    Demo

  • 8/3/2019 An iOS Developer's OpenGL Primer

    22/185

    Where do the

    ixels come from?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    23/185

    Where do the

    ixels come from?

    Fragment shader.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    24/185

    Where do the

    ixels come from?

    Fragment shader.

    Simple program that runs on the GPU.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    25/185

    Where do the

    ixels come from?

    Fragment shader.

    Simple program that runs on the GPU.

    Computes the shade for each fragment, orpixel.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    26/185

    Where do the

    ixels come from?

    Fragment shader.

    Simple program that runs on the GPU.

    Computes the shade for each fragment, orpixel.

    Run once forevery pixelsimultaneously.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    27/185

    Where do the

    ixels come from?

    Fragment shader.

    Simple program that runs on the GPU.

    Computes the shade for each fragment, orpixel.

    Run once forevery fragmentindependently.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    28/185

    Where do the

    ixels come from?

    Fragment shader.

    Simple program that runs on the GPU.

    Computes the shade for each fragment, orpixel.

    Run once forevery pixelsimultaneously.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    29/185

    OpenGL ES 2.0

    Shading Language

  • 8/3/2019 An iOS Developer's OpenGL Primer

    30/185

    OpenGL ES 2.0

    Shading Languageuniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =

    texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    31/185

    Scalarsfloatintbool

    Vectors[i,b]vec2[i,b]vec3[i,b]vec4

    Matrices

    mat2

    mat3mat4

    Samplerssampler2d

    samplerCube

    Shading Language

    Basic T es

  • 8/3/2019 An iOS Developer's OpenGL Primer

    32/185

    float i = 1.0;

    Shading Language

    Variable Initialisation

  • 8/3/2019 An iOS Developer's OpenGL Primer

    33/185

    float i = 1.0;

    const float too = 2.0;

    Shading Language

    Variable Initialisation

  • 8/3/2019 An iOS Developer's OpenGL Primer

    34/185

    float i = 1.0;

    const float too = 2.0;

    Shading Language

    Variable Initialisation

  • 8/3/2019 An iOS Developer's OpenGL Primer

    35/185

    float i = 1.0;

    const float too = 2.0;

    int j = 1;

    Shading Language

    Variable Initialisation

  • 8/3/2019 An iOS Developer's OpenGL Primer

    36/185

    Shading Language

    Variable Initialisation

    12

    34

    v =

  • 8/3/2019 An iOS Developer's OpenGL Primer

    37/185

    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);

    Shading Language

    Variable Initialisation

  • 8/3/2019 An iOS Developer's OpenGL Primer

    38/185

    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);

    mat2 m = mat2(1.0, 0.0, // 1st Column

    0.0, 1.0); // 2nd Column

    Shading Language

    Variable Initialisation

  • 8/3/2019 An iOS Developer's OpenGL Primer

    39/185

    OpenGL ES 2.0

    Shading Languageuniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    40/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    41/185

    Simples.fsh

    void main(){

    gl_FragColor =vec4(0.0, 0.0, 0.0, 1.0);}

  • 8/3/2019 An iOS Developer's OpenGL Primer

    42/185

    Simples.fsh

    void main(){

    gl_FragColor =vec4(0.0, 0.0, 0.0, 1.0);}

  • 8/3/2019 An iOS Developer's OpenGL Primer

    43/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    44/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    45/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    46/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    47/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    48/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor=texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    49/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    50/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    51/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,vTextureCoordinate);

    }

  • 8/3/2019 An iOS Developer's OpenGL Primer

    52/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture, vTextureCoordinate);}

  • 8/3/2019 An iOS Developer's OpenGL Primer

    53/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,

    vTextureCoordinate);}

  • 8/3/2019 An iOS Developer's OpenGL Primer

    54/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,

    vTextureCoordinate);}

    D

  • 8/3/2019 An iOS Developer's OpenGL Primer

    55/185

    Demo

    D

  • 8/3/2019 An iOS Developer's OpenGL Primer

    56/185

    Demo

    Wh d th i l

  • 8/3/2019 An iOS Developer's OpenGL Primer

    57/185

    Where do the pixels come

    from?

    Wh d th i l

  • 8/3/2019 An iOS Developer's OpenGL Primer

    58/185

    Where do the pixels come

    from?

    Wh d th i l

  • 8/3/2019 An iOS Developer's OpenGL Primer

    59/185

    Where do the pixels come

    from?

    Wh d th i l

  • 8/3/2019 An iOS Developer's OpenGL Primer

    60/185

    Where do the pixels come

    from?

    pixels

  • 8/3/2019 An iOS Developer's OpenGL Primer

    61/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    void main(){

    gl_FragColor =texture2D(sTexture,

    vTextureCoordinate);}

  • 8/3/2019 An iOS Developer's OpenGL Primer

    62/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

  • 8/3/2019 An iOS Developer's OpenGL Primer

    63/185

    Colours.fsh

    uniformlowpsampler2D sTexture;

    varyinghighpvec2 vTextureCoordinate;

    Where are these inputscoming from?

    Wh th i t

  • 8/3/2019 An iOS Developer's OpenGL Primer

    64/185

    Where are these inputs

    coming from?

    Wh th i t

  • 8/3/2019 An iOS Developer's OpenGL Primer

    65/185

    Where are these inputs

    coming from?

    uniforms

    Wh th i t

  • 8/3/2019 An iOS Developer's OpenGL Primer

    66/185

    Where are these inputs

    coming from?

    uniforms

    Yourapp code

    Where are these inp ts

  • 8/3/2019 An iOS Developer's OpenGL Primer

    67/185

    Where are these inputs

    coming from?

    uniforms

    Yourapp code

    Objective-C (or other language - C, C++, Java etc.)

    Where are these inputs

  • 8/3/2019 An iOS Developer's OpenGL Primer

    68/185

    Where are these inputs

    coming from?

    Where are these inputs

  • 8/3/2019 An iOS Developer's OpenGL Primer

    69/185

    Where are these inputs

    coming from?

    varyings

    Where are these inputs

  • 8/3/2019 An iOS Developer's OpenGL Primer

    70/185

    Where are these inputs

    coming from?

    varyings Vertex shader

    Where are these inputs

  • 8/3/2019 An iOS Developer's OpenGL Primer

    71/185

    Where are these inputs

    coming from?

    varyings Vertex shader

    Simple program that runs on the GPU.

    Where are these inputs

  • 8/3/2019 An iOS Developer's OpenGL Primer

    72/185

    Where are these inputs

    coming from?

    varyings Vertex shader

    Simple program that runs on the GPU.

    OpenGL ES 2.0 Shading Language code.

    Where are these inputs

  • 8/3/2019 An iOS Developer's OpenGL Primer

    73/185

    Where are these inputs

    coming from?

    varyings Vertex shader

    Simple program that runs on the GPU.

    OpenGL ES 2.0 Shading Language code. Run once forevery vertexsimultaneously.

    Where are these inputs

  • 8/3/2019 An iOS Developer's OpenGL Primer

    74/185

    Where are these inputs

    coming from?

    varyings Vertex shader

    Simple program that runs on the GPU.

    OpenGL ES 2.0 Shading Language code. Run once forevery vertexindependently.

    Where are these inputs

  • 8/3/2019 An iOS Developer's OpenGL Primer

    75/185

    Where are these inputs

    coming from?

    varyings Vertex shader

    Simple program that runs on the GPU.

    OpenGL ES 2.0 Shading Language code. Run once forevery vertexsimultaneously.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    76/185

    Whats a Vertex?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    77/185

    Whats a Vertex?

    A vertex is a point

  • 8/3/2019 An iOS Developer's OpenGL Primer

    78/185

    Whats a Vertex?

    A vertex is a point

    Represents

  • 8/3/2019 An iOS Developer's OpenGL Primer

    79/185

    Whats a Vertex?

    A vertex is a point

    Represents

    Disconnected point

  • 8/3/2019 An iOS Developer's OpenGL Primer

    80/185

    Whats a Vertex?

    A vertex is a point

    Represents

    Disconnected point

    Line end point

  • 8/3/2019 An iOS Developer's OpenGL Primer

    81/185

    Whats a Vertex?

    A vertex is a point

    Represents

    Disconnected point

    Line end point

    Triangle corner point

  • 8/3/2019 An iOS Developer's OpenGL Primer

    82/185

    Whats a Vertex?

    A vertex is a point

    Represents

    Disconnected point

    Line end point

    Triangle corner point Two or three dimensional (vec2, vec3)

  • 8/3/2019 An iOS Developer's OpenGL Primer

    83/185

    Whats a Triangle Strip?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    84/185

    Whats a Triangle Strip?

    An array ofpoints...

  • 8/3/2019 An iOS Developer's OpenGL Primer

    85/185

    Whats a Triangle Strip?

    An array ofpoints...

    ...an array ofvec2s orvec3s, in Shading Language terms.

  • 8/3/2019 An iOS Developer's OpenGL Primer

    86/185

    Whats a Triangle Strip?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    87/185

  • 8/3/2019 An iOS Developer's OpenGL Primer

    88/185

    1

  • 8/3/2019 An iOS Developer's OpenGL Primer

    89/185

    1 2

  • 8/3/2019 An iOS Developer's OpenGL Primer

    90/185

    1 2

    3

  • 8/3/2019 An iOS Developer's OpenGL Primer

    91/185

    1 2

    3

  • 8/3/2019 An iOS Developer's OpenGL Primer

    92/185

    1 2

    3 4

  • 8/3/2019 An iOS Developer's OpenGL Primer

    93/185

    1 2

    3 4

  • 8/3/2019 An iOS Developer's OpenGL Primer

    94/185

    1 2

    3 4

  • 8/3/2019 An iOS Developer's OpenGL Primer

    95/185

    5

    1 2

    3 4

  • 8/3/2019 An iOS Developer's OpenGL Primer

    96/185

    5 6

    1 2

    3 4

  • 8/3/2019 An iOS Developer's OpenGL Primer

    97/185

    7

    5 6

    1 2

    3 4

  • 8/3/2019 An iOS Developer's OpenGL Primer

    98/185

    8

    7

    5 6

    1 2

    3 4

  • 8/3/2019 An iOS Developer's OpenGL Primer

    99/185

    8

    7

    5 6

    1 2

    3 4

    9

    Where do the Fragment

  • 8/3/2019 An iOS Developer's OpenGL Primer

    100/185

    Where do the Fragment

    Shader inputs come from? varyings

    Vertex shader

    Simple program that runs on the GPU.

    OpenGL ES 2.0 Shading Language code.

    Run once forevery vertexsimultaneously.

    Where do the Fragment

  • 8/3/2019 An iOS Developer's OpenGL Primer

    101/185

    Where do the Fragment

    Shader inputs come from? varyings

    Vertex shader

    Simple program that runs on the GPU.

    OpenGL ES 2.0 Shading Language code.

    Run once forevery vertexsimultaneously.

    Calculates the position of the vertex...

    Where do the Fragment

  • 8/3/2019 An iOS Developer's OpenGL Primer

    102/185

    Where do the Fragment

    Shader inputs come from? varyings

    Vertex shader

    Simple program that runs on the GPU.

    OpenGL ES 2.0 Shading Language code.

    Run once forevery vertexsimultaneously.

    Calculates the position of the vertex... ...and arbitraryother inputs to pass to the

    fragment shaders.

    V t Sh d

  • 8/3/2019 An iOS Developer's OpenGL Primer

    103/185

    Vertex Shader

    V t Sh d

  • 8/3/2019 An iOS Developer's OpenGL Primer

    104/185

    Vertex Shader

    attributevec4 aPosition;attributevec2 aTextureCoordinate;

    varyingvec2 vTextureCoordinate;

    void main(){

    vTextureCoordinate =aTextureCoordinate;

    gl_Position = aPosition;}

    C l h

  • 8/3/2019 An iOS Developer's OpenGL Primer

    105/185

    Colours.vsh

    attributevec4 aPosition;attributevec2 aTextureCoordinate;

    varyingvec2 vTextureCoordinate;

    void main(){

    vTextureCoordinate =aTextureCoordinate;

    gl_Position = aPosition;}

    C l h

  • 8/3/2019 An iOS Developer's OpenGL Primer

    106/185

    Colours.vsh

    attributevec4 aPosition;attributevec2 aTextureCoordinate;

    varyingvec2 vTextureCoordinate;

    void main(){

    vTextureCoordinate =aTextureCoordinate;

    gl_Position = aPosition;}

    Colo rs sh

  • 8/3/2019 An iOS Developer's OpenGL Primer

    107/185

    Colours.vsh

    attributevec4 aPosition;attributevec2 aTextureCoordinate;

    varyingvec2 vTextureCoordinate;

    void main(){

    vTextureCoordinate =aTextureCoordinate;

    gl_Position = aPosition;}

    Colours vsh

  • 8/3/2019 An iOS Developer's OpenGL Primer

    108/185

    Colours.vsh

    attributevec4 aPosition;attributevec2 aTextureCoordinate;

    varyingvec2 vTextureCoordinate;

    void main(){

    vTextureCoordinate =aTextureCoordinate;

    gl_Position = aPosition;}

    Colours vsh

  • 8/3/2019 An iOS Developer's OpenGL Primer

    109/185

    Colours.vsh

    attributevec4 aPosition;attributevec2 aTextureCoordinate;

    varyingvec2 vTextureCoordinate;

    void main(){

    vTextureCoordinate =aTextureCoordinate;

    gl_Position = aPosition;}

    Colours vsh

  • 8/3/2019 An iOS Developer's OpenGL Primer

    110/185

    Colours.vsh

    attributevec4 aPosition;attributevec2 aTextureCoordinate;

    varyingvec2 vTextureCoordinate;

    void main(){

    vTextureCoordinate =aTextureCoordinate;

    gl_Position = aPosition;}

    Colours vsh

  • 8/3/2019 An iOS Developer's OpenGL Primer

    111/185

    Colours.vsh

    attributevec4 aPosition;attributevec2 aTextureCoordinate;

    varyingvec2 vTextureCoordinate;

    void main(){

    vTextureCoordinate =aTextureCoordinate;

    gl_Position = aPosition;}

    Demo

  • 8/3/2019 An iOS Developer's OpenGL Primer

    112/185

    Demo

    Demo

  • 8/3/2019 An iOS Developer's OpenGL Primer

    113/185

    Demo

    Demo

  • 8/3/2019 An iOS Developer's OpenGL Primer

    114/185

    Demo

    Where do the

  • 8/3/2019 An iOS Developer's OpenGL Primer

    115/185

    ixels come from?

    pixels

    Where do the fragment shader

  • 8/3/2019 An iOS Developer's OpenGL Primer

    116/185

    g

    in uts come from?

    Where do the fragment shader

  • 8/3/2019 An iOS Developer's OpenGL Primer

    117/185

    g

    in uts come from?

    Where do the fragment shader

  • 8/3/2019 An iOS Developer's OpenGL Primer

    118/185

    g

    in uts come from?

    varyings

    Where do the shader

  • 8/3/2019 An iOS Developer's OpenGL Primer

    119/185

    in uts come from?

    varyings

    Where do the shader

  • 8/3/2019 An iOS Developer's OpenGL Primer

    120/185

    in uts come from?

    varyings

    Where do the shader

  • 8/3/2019 An iOS Developer's OpenGL Primer

    121/185

    in uts come from?

    varyings

    Where do the shader

  • 8/3/2019 An iOS Developer's OpenGL Primer

    122/185

    in uts come from?

    varyings

    uniforms uniforms

    Where do the shader

  • 8/3/2019 An iOS Developer's OpenGL Primer

    123/185

    in uts come from?

    varyings

    uniforms uniforms& attributes

    The OpenGL ES 2.0

  • 8/3/2019 An iOS Developer's OpenGL Primer

    124/185

    Pi eline

    varyings

    uniformsuniforms& attributes

    Modern Graphics Hardware

  • 8/3/2019 An iOS Developer's OpenGL Primer

    125/185

    Pi eline

    varyings

    uniformsuniforms& attributes

    The OpenGL ES 2.0

  • 8/3/2019 An iOS Developer's OpenGL Primer

    126/185

    Pi eline

    varyings

    uniformsuniforms& attributes

    What does the app code do?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    127/185

    What does the app code do?

    What does the app code do?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    128/185

    What does the app code do?

    What does the app code do?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    129/185

    What does the app code do?

    OpenGL content is presented in a CALayer...

    What does the app code do?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    130/185

    What does the app code do?

    OpenGL content is presented in a CALayer... ...specifically, a CAEAGLLayer.

    What does the app code do?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    131/185

    What does the app code do?

    OpenGL content is presented in a CALayer... ...specifically, a CAEAGLLayer.

    Use a UIView backed by a CAEAGLLayer...

    What does the app code do?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    132/185

    What does the app code do?

    OpenGL content is presented in a CALayer... ...specifically, a CAEAGLLayer.

    Use a UIView backed by a CAEAGLLayer...

    ...like Xcode template and sample codes EAGLView.

    What does the app code do?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    133/185

    What does the app code do?

    OpenGL content is presented in a CALayer... ...specifically, a CAEAGLLayer.

    Use a UIView backed by a CAEAGLLayer...

    ...like Xcode template and sample codes EAGLView.

    Use the C OpenGL API to draw.

    Integrating with UIKit

  • 8/3/2019 An iOS Developer's OpenGL Primer

    134/185

    Integrating with UIKit

    Integrating with UIKit

  • 8/3/2019 An iOS Developer's OpenGL Primer

    135/185

    Integrating with UIKit

    You cant use the setNeedsDisplay model.

    Integrating with UIKit

  • 8/3/2019 An iOS Developer's OpenGL Primer

    136/185

    Integrating with UIKit

    You cant use the setNeedsDisplay model.

    Draw explicitly when you have something to display.

    Integrating with UIKit

  • 8/3/2019 An iOS Developer's OpenGL Primer

    137/185

    Integrating with UIKit

    You cant use the setNeedsDisplay model.

    Draw explicitly when you have something to display.

    Draw on a timer (e.g. 30 frames per second).

    Integrating with UIKit

  • 8/3/2019 An iOS Developer's OpenGL Primer

    138/185

    Integrating with UIKit

    You cant use the setNeedsDisplay model.

    Draw explicitly when you have something to display.

    Draw on a timer (e.g. 30 frames per second).

    Use the CADisplayLinktimer class.

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    139/185

    C OpenGL API

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    140/185

    C OpenGL API

    Context based

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    141/185

    C OpenGL API

    Context based

    Like CoreGraphics CGContext.

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    142/185

    C OpenGL API

    Context based

    Like CoreGraphics CGContext.

    No state save/restore.

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    143/185

    C OpenGL API

    Context based

    Like CoreGraphics CGContext.

    No state save/restore.

    Not thread safe.

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    144/185

    C OpenGL API

    Context based

    Like CoreGraphics CGContext.

    No state save/restore.

    Not thread safe.

    Use from one thread at a time.

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    145/185

    C OpenGL API

    Context based

    Like CoreGraphics CGContext.

    No state save/restore.

    Not thread safe.

    Use from one thread at a time. Use share pools to share resources between threads.

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    146/185

    C OpenGL API

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    147/185

    C OpenGL API

    Functions to upload things to the GPU, e.g.:

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    148/185

    C OpenGL API

    Functions to upload things to the GPU, e.g.:

    Shader programs

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    149/185

    C OpenGL API

    Functions to upload things to the GPU, e.g.:

    Shader programs

    Textures

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    150/185

    C Ope G

    Functions to upload things to the GPU, e.g.:

    Shader programs

    Textures Shader program uniforms, attributes

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    151/185

    p

    Functions to upload things to the GPU, e.g.:

    Shader programs

    Textures Shader program uniforms, attributes

    Functions to set context state, e.g.:

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    152/185

    p

    Functions to upload things to the GPU, e.g.:

    Shader programs

    Textures Shader program uniforms, attributes

    Functions to set context state, e.g.:

    Active texture

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    153/185

    p

    Functions to upload things to the GPU, e.g.:

    Shader programs

    Textures Shader program uniforms, attributes

    Functions to set context state, e.g.:

    Active texture Clear colour

    C OpenGL API

  • 8/3/2019 An iOS Developer's OpenGL Primer

    154/185

    p

    Functions to upload things to the GPU, e.g.:

    Shader programs

    Textures Shader program uniforms, attributes

    Functions to set context state, e.g.:

    Active texture Clear colour

    Functions to perform rendering

    Demo

  • 8/3/2019 An iOS Developer's OpenGL Primer

    155/185

    Demo

    Demo

  • 8/3/2019 An iOS Developer's OpenGL Primer

    156/185

    Demo

    Demo

  • 8/3/2019 An iOS Developer's OpenGL Primer

    157/185

    Demo

    Demo

  • 8/3/2019 An iOS Developer's OpenGL Primer

    158/185

    Demo

    Why Use OpenGL?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    159/185

    y p

    Why Use OpenGL?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    160/185

    y p

    Flexibility

    Why Use OpenGL?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    161/185

    y p

    Flexibility

    Performance

    Why Use OpenGL?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    162/185

    y p

    Flexibility

    Performance

    3D Stuff?

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    163/185

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    164/185

    Upload models as in triangle strips made of 3D vec3 points.

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    165/185

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    166/185

    Dopositioning

    maths in thevertex shaders

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    167/185

    Do positioning maths in the vertex shaders

    One uniform mat4 to position each strip - a model

    matrix.

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    168/185

    Do positioning maths in the vertex shaders

    One uniform mat4 to position each strip - a model

    matrix.

    One uniform mat4 to position the world around the

    camera, calculate perspective - a projection matrix.

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    169/185

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    170/185

    Do lighting maths in the vertex shaders.

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    171/185

    Do lighting maths in the vertex shaders.

    Upload

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    172/185

    Do lighting maths in the vertex shaders.

    Upload

    light information

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    173/185

    Do lighting maths in the vertex shaders.

    Upload

    light information

    arrays ofvertex normals

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    174/185

    Do lighting maths in the vertex shaders.

    Upload

    light information

    arrays ofvertex normals

    Calculate per-vertex lighting brightness, color

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    175/185

    Do lighting maths in the vertex shaders.

    Upload

    light information

    arrays ofvertex normals

    Calculate per-vertex lighting brightness, color

    Formulas online

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    176/185

    Do lighting maths in the vertex shaders.

    Upload

    light information

    arrays ofvertex normals

    Calculate per-vertex lighting brightness, color

    Formulas online

    Pass as varying to fragment shader.

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    177/185

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    178/185

    Do texturing, other per-pixel effects in the fragment shaders.

    What about 3D stuff?

  • 8/3/2019 An iOS Developer's OpenGL Primer

    179/185

    Do texturing, other per-pixel effects in the fragment shaders.

    Multiply the pixel colour with the light colour.

    Learning More

  • 8/3/2019 An iOS Developer's OpenGL Primer

    180/185

    Learning More

  • 8/3/2019 An iOS Developer's OpenGL Primer

    181/185

    OpenGL ES ProgrammingGuide for iOS;Apple

    Learning More

  • 8/3/2019 An iOS Developer's OpenGL Primer

    182/185

    OpenGL ES ProgrammingGuide for iOS;Apple

    OpenGL ES 2.0Programming Guide;Munshi, Ginsburg & Shreiner

    Learning More

  • 8/3/2019 An iOS Developer's OpenGL Primer

    183/185

    OpenGL ES ProgrammingGuide for iOS;Apple

    OpenGL ES 2.0Programming Guide;Munshi, Ginsburg & Shreiner

    PowerVR Insider web site

    Learning More

  • 8/3/2019 An iOS Developer's OpenGL Primer

    184/185

    OpenGL ES ProgrammingGuide for iOS;Apple

    OpenGL ES 2.0Programming Guide;Munshi, Ginsburg & Shreiner

    PowerVR Insider web siteWatch out forgreat new

    things in iOS 5!

    github.com/th-in-gs/Colours

  • 8/3/2019 An iOS Developer's OpenGL Primer

    185/185

    Jamie Montgomerie@th_in_gs

    [email protected]

    www.blog.montgomerie.net

    th.ingsmadeoutofotherthin.gs