Book Image

iOS Game Programming Cookbook

Book Image

iOS Game Programming Cookbook

Overview of this book

Table of Contents (19 chapters)
iOS Game Programming Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Building a mini 3D animation game using OpenGL


In this recipe, we will load a texture and apply it to the square. Later, we will make a cube, and finally we will learn how to implement three-dimensional animation by rotating our cube in three-dimensions.

How to do it

Now we will start from the place we have left before and will load all the textures. To load the textures, follow the following steps:

  1. First, in our vertex structure, we need to include texture coordinate information:

    typedef struct {
    GLKVector3 position; // the location of each vertex in space
    GLKVector2 textureCoordinates; // the texture coordinates for each vertex
    } Vertex;
    const Vertex SquareVertices[] = {
    {{-1, -1 , 0}, {0,0}}, // bottom left
    {{1, -1 , 0}, {1,0}}, // bottom right
    {{1, 1 , 0}, {1,1}}, // top right
    {{-1, 1 , 0}, {0,1}}, // top left
    };
  2. Next, add an image (any) in our project, rename it as Texture.png, and then add the following code in viewDidLoad:

    NSString* imagePath = [[NSBundle mainBundle]
    pathForResource:@...