SlideShare a Scribd company logo
Practical Opengl for 2D
Game Developement
Rob Muller
Part 1 - The Nitty Gritty
Opengl ES 1.x

         source - http://www.khronos.org/opengles/2_X/
Opengl ES 2.x

         source - http://www.khronos.org/opengles/2_X/
Rotations, Translations &
   Scaling - Oh My!
Rotations and Scaling are
        about 0,0,0
      void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);

      void glScalef(GLfloat x, GLfloat y, GLfloat z);



Rotations and scaling both happen about 0,0,0
They are Commutative (if translations aren’t introduced)
Cardboard vector demo?
+Y




     +X
pick your sprite coordinates around zero so they scale
  and rotate how you like:

                              bottomJustifiedQuad[ ] =
                                           {-0.5, 1.0,
                                             0.5, 1.0,
                                            -0.5, 0.0,
centerJustifiedQuad[ ] =
                                             0.5, 0.0}
             {-0.5, 0.5,
               0.5, 0.5,
             -0.5, -0.5,
                               cornerJustifiedQuad[ ] =
              0.5, -0.5}
                                             {0.0, 1.0,
                                              1.0, 1.0,
                                              0.0, 0.0,
                                              1.0, 0.0}
+Y
centerJustifiedQuad[ ] =
             {-0.5, 0.5,
               0.5, 0.5,
             -0.5, -0.5,
              0.5, -0.5}
                   -0.5, 0.5         0.5, 0.5




                                                 +X
                   -0.5, -0.5        0.5, -0.5
+Y
centerJustifiedQuad[ ] =
        1 {-0.5, 0.5,
        2      0.5, 0.5,                           Triangle Strip!
        3 -0.5, -0.5,
        4     0.5, -0.5}
                   -0.5, 0.51        2 0.5, 0.5


                                                                     +X
                   -0.5, -0.5          0.5, -0.5
                            3        4
+Y
glScalef(2.0f, 2.0f, 1.0f);
glRotatef(90.0f, 0.0f, 0.0f, 1.0f);




                                           +X
+Y
glRotatef(90.0f, 0.0f, 0.0f, 1.0f);        communative w/o
glScalef(2.0f, 2.0f, 1.0f);                  translations




                                                         +X
+Y
glScalef(1.0f, 2.0f, 1.0f);




                                   +X
+Y
glScalef(1.0f, -2.0f, 1.0f);




                                    +X
+Y
glRotatef(360.0f, 0.0f, 0.0f, 1.0f);




                                            +X
+Y
glRotatef(-45.0f, 0.0f, 0.0f, 1.0f);
                                            it’s not actually like this...




                                                                      +X
glRotatef(-45.0f, 0.0f, 0.0f, 1.0);
                                           +Y




                                      +X
+Y



                   -0.5, 1.0        0.5, 1.0




                   -0.5, 0.0         0.5, 0.0

                                                +X
bottomJustifiedQuad[ ] =
             {-0.5, 1.0,
               0.5, 1.0,
              -0.5, 0.0,
               0.5, 0.0}
glScalef(2.0f, 2.0f, 1.0f);

Scale 2x
+Y



                     f(1.0f, 0.5f,
             glScale
             1.0f);
                    P W N ED




                                     +X
Mushrooms
  FTW!
Translation in the mix


 Translations change what 0,0,0 means to the vertices
 you provide
 CardBoard demo?
glScalef(2.0f, 2.0f, 0.0f);
                                  +Y
glTranslatef(1.0f, 1.0f, 0.0f);




                                       +X

 (your actually making the
translation go twice as far)
glTranslatef(1.0f, 1.0f, 0.0f);
                                  +Y
glScalef(2.0f, 2.0f, 0.0f);




                                       +X
+Y
glRotatef(45.0f, 0.0f, 0.0f, 1.0);        At this point I
glTranslatef(1.0f, 1.0f, 0.0f);
                                          thought huh?




                                                        +X
+Y
glRotatef(45.0f, 0.0f, 0.0f, 1.0);   +X
glRotatef(45.0f, 0.0f, 0.0f, 1.0);
                                             +X
glTranslatef(1.0f, 1.0f, 0.0f);


                +Y                   (1,1)
+Y
glTranslatef(1.0f, 1.0f, 0.0f);
glRotatef(45.0f, 0.0f, 0.0f, 1.0);




                                          +X
Demo!
  trs
What is an ID in opengl?


 an ID is usually just an integer that you get when you
 make something (textures, various buffers). These are
 then “bound” and whatever drawing you do will use the
 use the texture/buffer associated with that integer value
 until you bind something else;
Part 2 - Setup
Take a moment to think
about boiler plate code
(asking the OS for stuff)
Now think about that on
your own time with some
examples you found on the
internetz...
(fairly) universal boilerplate
GLint backingWidth;
GLint backingHeight;
GLuint defaultFramebuffer, colorRenderbuffer;

                           ...
//initialization
glGenFramebuffersOES(1, &defaultFramebuffer);
glGenRenderbuffersOES(1, &colorRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);
                           ...
//this is called during a resize
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer];
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
                           ...
//free everything up
if (defaultFramebuffer)
    {
        glDeleteFramebuffersOES(1, &defaultFramebuffer);
        defaultFramebuffer = 0;
    }

    if (colorRenderbuffer)
    {
        glDeleteRenderbuffersOES(1, &colorRenderbuffer);
        colorRenderbuffer = 0;
    }
Stuff you gotta mess with...
    //boilerplate init and resize stuffz

    ...

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

	   //glOrthof(left, right, bottom, top, nearClip, farClip);	
	   //glViewport(0, 0, width, heigth);
	   //glOrthof( -320 * 0.5, 320 * 0.5, 480 * 0.5, -480 * 0.5, 0, 1000 ); //iphone-ish
                     //coordinates... rotations along z are reversed and so is positive z

	   glOrthof( -320 * 0.5, 320 * 0.5, -480 * 0.5, 480 * 0.5, 0, 1000 );	//opengl coordinates
	   glViewport(0, 0, 320, 480);
	
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
	
	   glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    ...

    //draw yo stuffz
Use a stack to reset for
    another sprite


               glPushMatrix();
 Demo:
 makeSquares
               glPopMatrix();
glEnable & glDisable
	   glEnable(GL_BLEND);
	   glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
	   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	   //glBlendFunc(GL_ONE, GL_ONE); //use this for Additive

    ... //draw stuff

    glDisable(GL_BLEND);




                            Demo!
                            makeSquares
Make a picture appear
(texture boiler plate)
	 GLuint texID;

glGenTextures(1, &texID);
 glBindTexture(GL_TEXTURE_2D, texID);
 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);




 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mwidth, mheight, 0,
              GL_RGBA, GL_UNSIGNED_BYTE, imageData);
Vertices &
Texture coordinates
   GLfloat quadTexture[] = {
           0.0f, 1.0f,
           1.0f, 1.0f,
           0.0f, 0.0f,
           1.0f, 0.0f
       };	 //



   GLfloat quad[] = {
        -0.5f, 0.5f, 0.0f,
   	 	 0.5f, 0.5f, 0.0f,
        -0.5f, -0.5f, 0.0f,
   	 	 0.5f, -0.5f, 0.0f
       };
centerJustifiedQuad[ ] =        GLfloat quadTexture[ ] = {
             {-0.5, 0.5,            0.0f, 1.0f,
               0.5, 0.5,            1.0f, 1.0f,
             -0.5, -0.5,            0.0f, 0.0f,
              0.5, -0.5}            1.0f, 0.0f}


  -0.5, 0.51     2 0.5, 0.5          0, 1           1, 1




  -0.5, -0.5       0.5, -0.5
           3     4                 0, 0            0, 1
centerJustifiedQuad[ ] =        GLfloat quadTexture[ ] = {
             {-0.5, 0.5,            0.25f, 1.0f,
               0.5, 0.5,            0.75f, 1.0f,
             -0.5, -0.5,            0.25f, 0.5f,
              0.5, -0.5}            0.75f, 0.5f}


  -0.5, 0.51     2 0.5, 0.5



  -0.5, -0.5       0.5, -0.5
           3     4
centerJustifiedQuad[ ] =                       GLfloat quadTexture[ ] = {
             {-0.5, 0.5,                           0.0f, 2.0f,
               0.5, 0.5,                           2.0f, 2.0f,
             -0.5, -0.5,                           0.0f, 0.0f,
              0.5, -0.5}                           2.0f, 0.0f}


  -0.5, 0.51                 2 0.5, 0.5



  -0.5, -0.5                   0.5, -0.5
           3                 4


               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
Where the $#!% hits the fan



...
glPushMatrix();
//transformations go here

glBindTexture(GL_TEXTURE_2D, texID);
glVertexPointer(3, GL_FLOAT, 0, quad);
glTexCoordPointer(2, GL_FLOAT, 0, quadTexture);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glPopMatrix();
Giminy Gee
                         Willikers Batman!
                        That’s a lot of stuff
                        for one source file!




   Oh, he’s much
 more cunning than
 that... This is only
the beginning of his
                               Demo!
    genius plan                 makeSprite
Ok, but what do we do
when we have a lot of
things?
drawing is done in the order you call the draw methods
depth buffer is rarely used because games almost
always have partially transparent images

   Background

    Enemies

     Hero

     HUD
Solution: Groups
Background

 Enemies


                           Background

                            Enemies


             VS.             Hero

                             HUD


   Hero

   HUD




                   (just sort within the layers)
Discussion


Scene/Asset managers
Particle Engines
Scene graphs and/or physics engine integration
Online resources
http://nehe.gamedev.net/
http://iphonedevdepot.com/
http://www.devmaster.net/engines/
http://gpwiki.org/index.php/Game_Engines
http://en.wikipedia.org/wiki/List_of_game_engines
http://www.wotsit.org/
Q&A
+1
                M
                  us
               Po hr
                 we o o
                    r !! m
                        !!


  Ol
     ds
t h ch                       d
   e M oo                 EN
          lt            e
        AX o       TH

More Related Content

What's hot

The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180
Mahmoud Samir Fayed
 
Apuntes clojure
Apuntes clojureApuntes clojure
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
Ken'ichi Matsui
 
統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半
Ken'ichi Matsui
 
A/B Testing for Game Design
A/B Testing for Game DesignA/B Testing for Game Design
A/B Testing for Game Design
Trieu Nguyen
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212
Mahmoud Samir Fayed
 
Program Language - Fall 2013
Program Language - Fall 2013 Program Language - Fall 2013
Program Language - Fall 2013
Yun-Yan Chi
 
A promise is a Promise
A promise is a PromiseA promise is a Promise
A promise is a Promise
Mateusz Bryła
 
The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
Mahmoud Samir Fayed
 
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
Ken'ichi Matsui
 
The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 59 of 202
The Ring programming language version 1.8 book - Part 59 of 202The Ring programming language version 1.8 book - Part 59 of 202
The Ring programming language version 1.8 book - Part 59 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 38 of 189
The Ring programming language version 1.6 book - Part 38 of 189The Ring programming language version 1.6 book - Part 38 of 189
The Ring programming language version 1.6 book - Part 38 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.6 book - Part 55 of 189The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.6 book - Part 55 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 25 of 84
The Ring programming language version 1.2 book - Part 25 of 84The Ring programming language version 1.2 book - Part 25 of 84
The Ring programming language version 1.2 book - Part 25 of 84
Mahmoud Samir Fayed
 

What's hot (20)

Texconf11
Texconf11Texconf11
Texconf11
 
ejercicio 211 del libro de Baldor
ejercicio 211 del libro de Baldorejercicio 211 del libro de Baldor
ejercicio 211 del libro de Baldor
 
The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180
 
Apuntes clojure
Apuntes clojureApuntes clojure
Apuntes clojure
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
 
統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半
 
A/B Testing for Game Design
A/B Testing for Game DesignA/B Testing for Game Design
A/B Testing for Game Design
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212
 
Program Language - Fall 2013
Program Language - Fall 2013 Program Language - Fall 2013
Program Language - Fall 2013
 
A promise is a Promise
A promise is a PromiseA promise is a Promise
A promise is a Promise
 
The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
 
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
 
The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
The Ring programming language version 1.8 book - Part 59 of 202
The Ring programming language version 1.8 book - Part 59 of 202The Ring programming language version 1.8 book - Part 59 of 202
The Ring programming language version 1.8 book - Part 59 of 202
 
The Ring programming language version 1.6 book - Part 38 of 189
The Ring programming language version 1.6 book - Part 38 of 189The Ring programming language version 1.6 book - Part 38 of 189
The Ring programming language version 1.6 book - Part 38 of 189
 
The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.6 book - Part 55 of 189The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.6 book - Part 55 of 189
 
The Ring programming language version 1.2 book - Part 25 of 84
The Ring programming language version 1.2 book - Part 25 of 84The Ring programming language version 1.2 book - Part 25 of 84
The Ring programming language version 1.2 book - Part 25 of 84
 
ejercicio 211 libro de baldor
ejercicio 211 libro de baldorejercicio 211 libro de baldor
ejercicio 211 libro de baldor
 

Viewers also liked

Nahu & Saraf
Nahu & SarafNahu & Saraf
Nahu & Sarafmimi
 
Hobbies and sports
Hobbies and sportsHobbies and sports
Hobbies and sportsalexandra91
 
Put your money where your mouse is: measuring ROI
Put your money where your mouse is: measuring ROIPut your money where your mouse is: measuring ROI
Put your money where your mouse is: measuring ROIBrew
 
2009 - Eclipse foundation presentation
2009 - Eclipse foundation presentation2009 - Eclipse foundation presentation
2009 - Eclipse foundation presentation
fOSSa - Free Open Source Software Academia Conference
 
Tec i iletrag
Tec i iletragTec i iletrag
Tec i iletragvazumano
 
Geometry In Art
Geometry In ArtGeometry In Art
Geometry In Art
Catherine Haight
 
Pavasaris slidesharei
Pavasaris slideshareiPavasaris slidesharei
Pavasaris slidesharei
Aelita Punkstiņa
 
Hy solution사례(4)친디아변액가입고객
Hy solution사례(4)친디아변액가입고객Hy solution사례(4)친디아변액가입고객
Hy solution사례(4)친디아변액가입고객
valuasset
 
Analysis and usage of forges - fossa2010
Analysis and usage of forges - fossa2010Analysis and usage of forges - fossa2010
Analysis and usage of forges - fossa2010
fOSSa - Free Open Source Software Academia Conference
 
Kruskal
KruskalKruskal
KruskalJorge
 
My Grandson Cute Hasnain
My Grandson Cute HasnainMy Grandson Cute Hasnain
My Grandson Cute Hasnain
shahhmurad
 
2010 ADA Standards Seminar: Application for Existing Buildings
2010 ADA Standards Seminar: Application for Existing Buildings2010 ADA Standards Seminar: Application for Existing Buildings
2010 ADA Standards Seminar: Application for Existing Buildings
REBNY
 
视频编码原理简介Sohu版
视频编码原理简介Sohu版视频编码原理简介Sohu版
视频编码原理简介Sohu版
pluschen
 
走向开源:提交CPAN模块Step by Step
走向开源:提交CPAN模块Step by Step走向开源:提交CPAN模块Step by Step
走向开源:提交CPAN模块Step by Step
pluschen
 
Oss project management - fossa2010
Oss project management - fossa2010Oss project management - fossa2010
Oss project management - fossa2010
fOSSa - Free Open Source Software Academia Conference
 
10
1010
How to Stop Gray Market and Counterfeit Piracy
How to Stop Gray Market and Counterfeit PiracyHow to Stop Gray Market and Counterfeit Piracy
How to Stop Gray Market and Counterfeit Piracy
NEW Momentum
 

Viewers also liked (20)

Nahu & Saraf
Nahu & SarafNahu & Saraf
Nahu & Saraf
 
Hobbies and sports
Hobbies and sportsHobbies and sports
Hobbies and sports
 
Put your money where your mouse is: measuring ROI
Put your money where your mouse is: measuring ROIPut your money where your mouse is: measuring ROI
Put your money where your mouse is: measuring ROI
 
2009 - Eclipse foundation presentation
2009 - Eclipse foundation presentation2009 - Eclipse foundation presentation
2009 - Eclipse foundation presentation
 
Tec i iletrag
Tec i iletragTec i iletrag
Tec i iletrag
 
Geometry In Art
Geometry In ArtGeometry In Art
Geometry In Art
 
Power point
Power pointPower point
Power point
 
Pavasaris slidesharei
Pavasaris slideshareiPavasaris slidesharei
Pavasaris slidesharei
 
Hy solution사례(4)친디아변액가입고객
Hy solution사례(4)친디아변액가입고객Hy solution사례(4)친디아변액가입고객
Hy solution사례(4)친디아변액가입고객
 
Analysis and usage of forges - fossa2010
Analysis and usage of forges - fossa2010Analysis and usage of forges - fossa2010
Analysis and usage of forges - fossa2010
 
Kruskal
KruskalKruskal
Kruskal
 
My Grandson Cute Hasnain
My Grandson Cute HasnainMy Grandson Cute Hasnain
My Grandson Cute Hasnain
 
2010 ADA Standards Seminar: Application for Existing Buildings
2010 ADA Standards Seminar: Application for Existing Buildings2010 ADA Standards Seminar: Application for Existing Buildings
2010 ADA Standards Seminar: Application for Existing Buildings
 
视频编码原理简介Sohu版
视频编码原理简介Sohu版视频编码原理简介Sohu版
视频编码原理简介Sohu版
 
走向开源:提交CPAN模块Step by Step
走向开源:提交CPAN模块Step by Step走向开源:提交CPAN模块Step by Step
走向开源:提交CPAN模块Step by Step
 
Oss project management - fossa2010
Oss project management - fossa2010Oss project management - fossa2010
Oss project management - fossa2010
 
Bug tracking - fossa2010
Bug tracking - fossa2010Bug tracking - fossa2010
Bug tracking - fossa2010
 
Makalah: Pengantar Reportase
Makalah: Pengantar ReportaseMakalah: Pengantar Reportase
Makalah: Pengantar Reportase
 
10
1010
10
 
How to Stop Gray Market and Counterfeit Piracy
How to Stop Gray Market and Counterfeit PiracyHow to Stop Gray Market and Counterfeit Piracy
How to Stop Gray Market and Counterfeit Piracy
 

Similar to Disney Effects: Building web/mobile castle in OpenGL 2D & 3D

The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185
Mahmoud Samir Fayed
 
Robot Motion Source code
Robot Motion Source codeRobot Motion Source code
Robot Motion Source codeBrian Goggins
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
Mark Kilgard
 
Trident International Graphics Workshop 2014 2/5
Trident International Graphics Workshop 2014 2/5Trident International Graphics Workshop 2014 2/5
Trident International Graphics Workshop 2014 2/5
Takao Wada
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
Mahmoud Samir Fayed
 
10CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 310CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 3
Vanishree Arun
 
The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210
Mahmoud Samir Fayed
 
Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)
Aila Gema Safitri
 
Programa de objetos 3 d wire
Programa de objetos 3 d wirePrograma de objetos 3 d wire
Programa de objetos 3 d wireRené Domínguez
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8
Vanishree Arun
 
transformation in open GL. why use open GL modes
transformation in open GL. why use open GL modestransformation in open GL. why use open GL modes
transformation in open GL. why use open GL modes
jawadsafee
 
Ass day3 2_olympic logos
Ass day3 2_olympic logosAss day3 2_olympic logos
Ass day3 2_olympic logosRobi Parvez
 
10CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 710CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 7
Vanishree Arun
 
The Ring programming language version 1.5.4 book - Part 58 of 185
The Ring programming language version 1.5.4 book - Part 58 of 185The Ring programming language version 1.5.4 book - Part 58 of 185
The Ring programming language version 1.5.4 book - Part 58 of 185
Mahmoud Samir Fayed
 
OpenGL Starter L02
OpenGL Starter L02OpenGL Starter L02
OpenGL Starter L02
Mohammad Shaker
 

Similar to Disney Effects: Building web/mobile castle in OpenGL 2D & 3D (20)

The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185
 
Robot Motion Source code
Robot Motion Source codeRobot Motion Source code
Robot Motion Source code
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
 
Practica
PracticaPractica
Practica
 
Trident International Graphics Workshop 2014 2/5
Trident International Graphics Workshop 2014 2/5Trident International Graphics Workshop 2014 2/5
Trident International Graphics Workshop 2014 2/5
 
Transformasi 2 dmensi
Transformasi 2 dmensiTransformasi 2 dmensi
Transformasi 2 dmensi
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
 
10CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 310CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 3
 
The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196
 
The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210
 
Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)
 
Programa de objetos 3 d wire
Programa de objetos 3 d wirePrograma de objetos 3 d wire
Programa de objetos 3 d wire
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8
 
transformation in open GL. why use open GL modes
transformation in open GL. why use open GL modestransformation in open GL. why use open GL modes
transformation in open GL. why use open GL modes
 
Ass day3 2_olympic logos
Ass day3 2_olympic logosAss day3 2_olympic logos
Ass day3 2_olympic logos
 
10CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 710CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 7
 
The Ring programming language version 1.5.4 book - Part 58 of 185
The Ring programming language version 1.5.4 book - Part 58 of 185The Ring programming language version 1.5.4 book - Part 58 of 185
The Ring programming language version 1.5.4 book - Part 58 of 185
 
OpenGL Starter L02
OpenGL Starter L02OpenGL Starter L02
OpenGL Starter L02
 

Recently uploaded

ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 

Recently uploaded (20)

ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 

Disney Effects: Building web/mobile castle in OpenGL 2D & 3D

  • 1. Practical Opengl for 2D Game Developement Rob Muller
  • 2. Part 1 - The Nitty Gritty
  • 3. Opengl ES 1.x source - http://www.khronos.org/opengles/2_X/
  • 4. Opengl ES 2.x source - http://www.khronos.org/opengles/2_X/
  • 5. Rotations, Translations & Scaling - Oh My!
  • 6. Rotations and Scaling are about 0,0,0 void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); void glScalef(GLfloat x, GLfloat y, GLfloat z); Rotations and scaling both happen about 0,0,0 They are Commutative (if translations aren’t introduced) Cardboard vector demo?
  • 7. +Y +X
  • 8. pick your sprite coordinates around zero so they scale and rotate how you like: bottomJustifiedQuad[ ] = {-0.5, 1.0, 0.5, 1.0, -0.5, 0.0, centerJustifiedQuad[ ] = 0.5, 0.0} {-0.5, 0.5, 0.5, 0.5, -0.5, -0.5, cornerJustifiedQuad[ ] = 0.5, -0.5} {0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0}
  • 9. +Y centerJustifiedQuad[ ] = {-0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5} -0.5, 0.5 0.5, 0.5 +X -0.5, -0.5 0.5, -0.5
  • 10. +Y centerJustifiedQuad[ ] = 1 {-0.5, 0.5, 2 0.5, 0.5, Triangle Strip! 3 -0.5, -0.5, 4 0.5, -0.5} -0.5, 0.51 2 0.5, 0.5 +X -0.5, -0.5 0.5, -0.5 3 4
  • 12. +Y glRotatef(90.0f, 0.0f, 0.0f, 1.0f); communative w/o glScalef(2.0f, 2.0f, 1.0f); translations +X
  • 16. +Y glRotatef(-45.0f, 0.0f, 0.0f, 1.0f); it’s not actually like this... +X
  • 18. +Y -0.5, 1.0 0.5, 1.0 -0.5, 0.0 0.5, 0.0 +X bottomJustifiedQuad[ ] = {-0.5, 1.0, 0.5, 1.0, -0.5, 0.0, 0.5, 0.0}
  • 20. +Y f(1.0f, 0.5f, glScale 1.0f); P W N ED +X Mushrooms FTW!
  • 21. Translation in the mix Translations change what 0,0,0 means to the vertices you provide CardBoard demo?
  • 22. glScalef(2.0f, 2.0f, 0.0f); +Y glTranslatef(1.0f, 1.0f, 0.0f); +X (your actually making the translation go twice as far)
  • 23. glTranslatef(1.0f, 1.0f, 0.0f); +Y glScalef(2.0f, 2.0f, 0.0f); +X
  • 24. +Y glRotatef(45.0f, 0.0f, 0.0f, 1.0); At this point I glTranslatef(1.0f, 1.0f, 0.0f); thought huh? +X
  • 26. glRotatef(45.0f, 0.0f, 0.0f, 1.0); +X glTranslatef(1.0f, 1.0f, 0.0f); +Y (1,1)
  • 29. What is an ID in opengl? an ID is usually just an integer that you get when you make something (textures, various buffers). These are then “bound” and whatever drawing you do will use the use the texture/buffer associated with that integer value until you bind something else;
  • 30. Part 2 - Setup
  • 31. Take a moment to think about boiler plate code (asking the OS for stuff)
  • 32. Now think about that on your own time with some examples you found on the internetz...
  • 33. (fairly) universal boilerplate GLint backingWidth; GLint backingHeight; GLuint defaultFramebuffer, colorRenderbuffer; ... //initialization glGenFramebuffersOES(1, &defaultFramebuffer); glGenRenderbuffersOES(1, &colorRenderbuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer); ... //this is called during a resize glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer]; glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); ... //free everything up if (defaultFramebuffer) { glDeleteFramebuffersOES(1, &defaultFramebuffer); defaultFramebuffer = 0; } if (colorRenderbuffer) { glDeleteRenderbuffersOES(1, &colorRenderbuffer); colorRenderbuffer = 0; }
  • 34. Stuff you gotta mess with... //boilerplate init and resize stuffz ... glMatrixMode(GL_PROJECTION); glLoadIdentity(); //glOrthof(left, right, bottom, top, nearClip, farClip); //glViewport(0, 0, width, heigth); //glOrthof( -320 * 0.5, 320 * 0.5, 480 * 0.5, -480 * 0.5, 0, 1000 ); //iphone-ish //coordinates... rotations along z are reversed and so is positive z glOrthof( -320 * 0.5, 320 * 0.5, -480 * 0.5, 480 * 0.5, 0, 1000 ); //opengl coordinates glViewport(0, 0, 320, 480); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0.5f, 0.5f, 0.5f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); ... //draw yo stuffz
  • 35. Use a stack to reset for another sprite glPushMatrix(); Demo: makeSquares glPopMatrix();
  • 36. glEnable & glDisable glEnable(GL_BLEND); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFunc(GL_ONE, GL_ONE); //use this for Additive ... //draw stuff glDisable(GL_BLEND); Demo! makeSquares
  • 37. Make a picture appear (texture boiler plate) GLuint texID; glGenTextures(1, &texID); glBindTexture(GL_TEXTURE_2D, texID); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mwidth, mheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
  • 38. Vertices & Texture coordinates GLfloat quadTexture[] = { 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; // GLfloat quad[] = { -0.5f, 0.5f, 0.0f, 0.5f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f };
  • 39. centerJustifiedQuad[ ] = GLfloat quadTexture[ ] = { {-0.5, 0.5, 0.0f, 1.0f, 0.5, 0.5, 1.0f, 1.0f, -0.5, -0.5, 0.0f, 0.0f, 0.5, -0.5} 1.0f, 0.0f} -0.5, 0.51 2 0.5, 0.5 0, 1 1, 1 -0.5, -0.5 0.5, -0.5 3 4 0, 0 0, 1
  • 40. centerJustifiedQuad[ ] = GLfloat quadTexture[ ] = { {-0.5, 0.5, 0.25f, 1.0f, 0.5, 0.5, 0.75f, 1.0f, -0.5, -0.5, 0.25f, 0.5f, 0.5, -0.5} 0.75f, 0.5f} -0.5, 0.51 2 0.5, 0.5 -0.5, -0.5 0.5, -0.5 3 4
  • 41. centerJustifiedQuad[ ] = GLfloat quadTexture[ ] = { {-0.5, 0.5, 0.0f, 2.0f, 0.5, 0.5, 2.0f, 2.0f, -0.5, -0.5, 0.0f, 0.0f, 0.5, -0.5} 2.0f, 0.0f} -0.5, 0.51 2 0.5, 0.5 -0.5, -0.5 0.5, -0.5 3 4 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  • 42. Where the $#!% hits the fan ... glPushMatrix(); //transformations go here glBindTexture(GL_TEXTURE_2D, texID); glVertexPointer(3, GL_FLOAT, 0, quad); glTexCoordPointer(2, GL_FLOAT, 0, quadTexture); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glPopMatrix();
  • 43. Giminy Gee Willikers Batman! That’s a lot of stuff for one source file! Oh, he’s much more cunning than that... This is only the beginning of his Demo! genius plan makeSprite
  • 44. Ok, but what do we do when we have a lot of things? drawing is done in the order you call the draw methods depth buffer is rarely used because games almost always have partially transparent images Background Enemies Hero HUD
  • 45. Solution: Groups Background Enemies Background Enemies VS. Hero HUD Hero HUD (just sort within the layers)
  • 46. Discussion Scene/Asset managers Particle Engines Scene graphs and/or physics engine integration
  • 48. Q&A
  • 49. +1 M us Po hr we o o r !! m !! Ol ds t h ch d e M oo EN lt e AX o TH

Editor's Notes