Game Development Reference
In-Depth Information
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3,
GL_FLOAT, GL_FALSE, 0, 0);
21. Finally, we need to know how many vertices we're asking OpenGL to draw. This
can be figured out by taking the size of the entire index array, and dividing that by
the size of one element in that array:
int numberOfTriangles = sizeof(SquareTriangles)/
sizeof(SquareTriangles[0]);
glDrawElements(GL_TRIANGLES, numberOfTriangles,
GL_UNSIGNED_BYTE, 0);
So, our final implementation class probably looks like the following code:
#import "ViewController.h"
typedef struct {
GLKVector3 position;
} Vertex;
const Vertex SquareVertices[] = {
{-1, -1 , 0}, {1, -1 , 0}, {1, 1 , 0}, {-1, 1 , 0}
};
const GLubyte SquareTriangles[] = {
0, 1, 2,
2, 3, 0
};
@interface ViewController () {
GLuint _vertexBuffer;
GLuint _indexBuffer;
GLKBaseEffect* _squareEffect;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
GLKView* view = (GLKView*)self.view;
view.context = [[EAGLContext alloc]
initWithAPI:kEAGLRenderingAPIOpenGLES2];
Search WWH ::




Custom Search