Как объявить функцию в другой функции? - PullRequest
0 голосов
/ 23 марта 2020

Итак, я делаю тест в opengl с c ++. Проблема в том, что я не знаю, как объявить функцию внутри другой функции, поэтому у меня есть ошибка.

void main_menu_display()
{
    glClear(GL_COLOR_BUFFER_BIT);

    // code to draw main menu

    glutSwapBuffers();
}

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

Я также пытался это исправить ошибки: // void first_screen_display (); // void first_screen_key ();

    switch(key)
    {
    case 27: //< escape -> quit
       exit(0);
    case 13: //< enter -> goto first display
       glutDisplayFunc(first_screen_display);
       glutKeyboardFunc(first_screen_key);
       break;

и есть ошибка: 'first_screen_display' не был объявлен в этой области, и то же самое происходит с первой экранной клавишей.

    }
    glutPostRedisplay();
}

void first_screen_display()
{
    glClear(GL_COLOR_BUFFER_BIT);

    // code to draw first screen of game

    glutSwapBuffers();
}

void first_screen_key(unsigned char key, int x, int y)
{
    switch(key)
    {
    case 27: //< escape -> return to main menu
       glutDisplayFunc(first_screen_display);
       glutKeyboardFunc(first_screen_key);
       break;
    /* other stuff */
    default:
       break;
    }
    glutPostRedisplay();
}

int main(int argc, char* argv[]) //argument count, argument variables
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
    glutInitWindowSize(600,600);
    glutInitWindowPosition(100,100);
    glutCreateWindow("Quiz");
    glutDisplayFunc(main_menu_display); 
    glutKeyboardFunc(main_menu_key); 

    //glutDisplayFunc(first_screen_display); 
    //glutKeyboardFunc(first_screen_key);
    Init();



    glutMainLoop();
    return 0;
}
...