I'm developing an OpenGL-ES game of life program for the iPhone and I have an array that contains the boolean values of the entire grid, what I did for the array of the grid was:
grid = (BOOL *)malloc(2*XSize*YSize*sizeof(BOOL));
and I want to know what would be a good way of plotting this linear array to the screen.
I've tried to create the Vertices array and then plot via glDrawArray but I can't seem to get it right so I was wondering if anyone else could help me. This is the method I'm trying right now that when rendered creates artifacts for some reason:
- (void)GridToVertices {
int current = 0;
for(int y=-backingHeight/2;y<backingHeight/2;y++) {
for(int x=-backingWidth/2;x<backingWidth/2;x++) {
Vertices[current] = x;
Vertices[current+1] = y;
current+=2;
}
}
}
And then rendering it like so:
- (void)render {
[self GridToVertices];
[self GridToColors];
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float Left = -backingWidth/2;
float Right = backingWidth/2;
float Up = -backingHeight/2;
float Down = backingHeight/2;
glOrthof(Left, Right, Up, Down, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glVertexPointer(2, GL_FLOAT, 0, Vertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, Colors);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_POINTS, 0, [grid resolution]);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}