/* Demo of two partly coincident quads, to show color speckling. The red one is drawn first, then the green one. Implemented Fall 2005 Scott D. Anderson */ #include #include bool BgBlack = true; bool DepthTest = true; float TextLeft = -0.2; // X coordinate for left end of text float TextTop = -0.2; // Y coordinate for first line of text void RedThenGreenQuads() { glBegin(GL_QUADS); glColor4f(1,0,0,1); // solid red glVertex2f(0,0); // lower left, then CCW glVertex2f(2,0); glVertex2f(2,2); glVertex2f(0,2); glColor4f(0,1,0,1); // solid green glVertex2f(1,0); // lower left, then CCW glVertex2f(3,0); glVertex2f(3,2); glVertex2f(1,2); glEnd(); } void depthTest() { twColorName(BgBlack?TW_WHITE:TW_BLACK); if(DepthTest) { glEnable(GL_DEPTH_TEST); twDrawString(TextLeft,TextTop,0, "Depth Test ON - 'd' toggles"); } else { glDisable(GL_DEPTH_TEST); twDrawString(TextLeft,TextTop,0, "Depth Test OFF - 'd' toggles"); } } void display(void) { if(BgBlack) glClearColor(0,0,0,0); // transparent black else glClearColor(1,1,1,1); // opaque white glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); twCamera(); depthTest(); RedThenGreenQuads(); glFlush(); glutSwapBuffers(); } void keys(unsigned char k, int, int) { switch(k) { case 'b': BgBlack = !BgBlack; break; case 'd': DepthTest = !DepthTest; break; } glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500,500); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(0,3,0,2,0,0); twMainInit(); twKeyCallback('b',keys,"toggle black/white background"); twKeyCallback('d',keys,"toggle depth test"); glutMainLoop(); return 0; }