Im trying to create a checkerboard using only one square function, but i dont know how to switch the color from one pointer to another. code currently looks like this
void init() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 8.0, 0.0, 8.0, -1.0, 1.0);
squareCoordinates[0].setXY(0.0f, 0.0f);
squareCoordinates[1].setXY(1.0f, 0.0f);
squareCoordinates[2].setXY(1.0f, 1.0f);
squareCoordinates[3].setXY(0.0f, 1.0f);
squareColor1[0].setColor(0.0f, 0.0f, 1.0f);
squareColor1[1].setColor(0.0f, 0.0f, 1.0f);
squareColor1[2].setColor(0.0f, 0.0f, 1.0f);
squareColor1[3].setColor(0.0f, 0.0f, 1.0f);
squareCoordinates2[0].setXY(1.0f, 0.0f);
squareCoordinates2[1].setXY(2.0f, 0.0f);
squareCoordinates2[2].setXY(2.0f, 1.0f);
squareCoordinates2[3].setXY(1.0f, 1.0f);
squareColor2[0].setColor(1.0f, 0.45f, 0.0f);
squareColor2[1].setColor(1.0f, 0.45f, 0.0f);
squareColor2[2].setColor(1.0f, 0.45f, 0.0f);
squareColor2[3].setColor(1.0f, 0.45f, 0.0f);
for (int i=0; i<4; i++)
squareColor1[i].setColor(0.0f, 0.0f, 1.0f);
for (int i=0; i<4; i++)
squareColor2[i].setColor(1.0f, 0.45f, 0.0f);
float PI = 3.14159f;
float outerRadius = 0.9f;
diskCoordinates[0].setXY(0.0, 0.0);
diskColor1[0].setColor(1.0f, 1.0f, 0.0f);
for (int i=0; i<=72; i++) {
float angleInRadians = (5.0fiPI)/180.0f;
float x = outerRadiuscos(angleInRadians);
float y = outerRadiussin(angleInRadians);
diskCoordinates[i+1].setXY(x, y);
diskColor1[i+1].setColor(1.0f, 1.0f, 0.0f);
}
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
}
void Square() {
glColorPointer(4, GL_FLOAT, 0, squareColor1);
glVertexPointer(4, GL_FLOAT, 0, squareCoordinates);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
void Square2() {
glColorPointer( 4, GL_FLOAT, 0, squareColor2);
glVertexPointer(4, GL_FLOAT, 0, squareCoordinates2);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
void Disk() {
glColorPointer( 4, GL_FLOAT, 0, diskColor1);
glVertexPointer(4, GL_FLOAT, 0, diskCoordinates);
glDrawArrays(GL_TRIANGLE_FAN, 0 , 74);
}
void Draw() {
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
float col = 0.0;
for(int i=0; i<=3; i++){
float row = 0.0;
glPushMatrix();
glTranslated(row, col, 0.0);
Square();
glPopMatrix();
glPushMatrix();
glTranslated(row, col, 0.0);
Square2();
glPopMatrix();
for(int j=0; j<=3; j++){
glPushMatrix();
glTranslated(row, col, 0.0);
Square();
glPopMatrix();
glPushMatrix();
glTranslated(row, col, 0.0);
Square2();
glPopMatrix();
row = row+2;
}
col = col+2;
}
float row2 = 1.0;
for(int i=0; i<=3; i++){
float col2 = -1.0;
float col3 = 1.0;
glPushMatrix();
glTranslated(col3, row2, 0.0);
Square();
glPopMatrix();
glPushMatrix();
glTranslated(col2, row2, 0.0);
Square2();
glPopMatrix();
for(int j=0; j<=3; j++){
glPushMatrix();
glTranslated(col3, row2, 0.0);
Square();
glPopMatrix();
glPushMatrix();
glTranslated(col2, row2, 0.0);
Square2();
glPopMatrix();
col2 = col2+2;
col3 = col3+2;
}
row2 = row2+2;
}
glutSwapBuffers();
}
But i cant have the two squares. I know it has something to do with the parameters in Square but i dont know how to switch the pointer or set it to another color.