Game Development Reference
In-Depth Information
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:@"Texture" ofType:@"png"];
NSError* error = nil;
GLKTextureInfo* texture = [GLKTextureLoader
textureWithContentsOfFile:imagePath options:nil
error:&error];
if (error != nil) {
NSLog(@"Problem loading texture: %@", error);
}
_squareEffect.texture2d0.name = texture.name;
3. To modify the earlier square color, remove the following lines:
_squareEffect.useConstantColor = YES;
_squareEffect.constantColor = GLKVector4Make(1.0, 0.0,
0.0, 1.0);
Search WWH ::




Custom Search