Pages

Tuesday, March 1, 2011

OpenGL - Backgrouning Using Keyboard

/**
 * This function will backgrouning the background based on
 * the key you type.
 * for example, if you type y, you will get the yellow background
 */

void keyboard(unsigned char key, int x, int y){

    switch(key){
        case 'r':
            glClearColor(1.0, 0.0, 0.0, 1.0);
            glutPostRedisplay();              // refresh window
            break;
        case 'b':
            glClearColor(0.0, 0.0, 0.0, 1.0);
            glutPostRedisplay();
            break;
        case 'g':
            glClearColor(0.0, 1.0, 0.0, 1.0);
            glutPostRedisplay();
            break;
        case 'y':
            glClearColor(1.0, 1.0, 0.0, 1.0);
            glutPostRedisplay();
            break;
        case 'm':
            glClearColor(1.0, 0.0, 1.0, 1.0);
            glutPostRedisplay();
            break;
        case 'a':
            glClearColor(0.0, 1.0, 1.0, 1.0);
            glutPostRedisplay();
            break;
        case 'u':
            glClearColor(0.0, 0.0, 1.0, 1.0);
            glutPostRedisplay();
            break;
        case 'w':
            glClearColor(1.0, 1.0, 1.0, 1.0);
            glutPostRedisplay();
            break;
        case 'h':
            cout << "Enter a key on keyboard to backgrouning!" << endl;
            cout << "a -> aqua" << endl;
            cout << "r -> red" << endl;
            cout << "b -> blue" << endl;
            cout << "g -> green" << endl;
            cout << "y -> yellow" << endl;
            cout << "m -> magenta" << endl;
            cout << "b -> black" << endl;
            cout << "w -> white" << endl;
            break;
    }
}

No comments:

Post a Comment