0

So I'm making quiz in opengl with c++. The problem is that I don't know how to declare function inside other function, so I have an error.

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)
{

I also tried this, to solve errors: //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;

and there's error: 'first_screen_display' was not declared in this scope and same happens with first screen key.

    }
    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;
}
Rolekz
  • 1
  • 3
  • 2
    You may want to declare your function in a header. – drescherjm Mar 23 '20 at 17:54
  • 2
    You say "_declare function_" but I don't see any attempt at declaring a function within a function. [Example](https://godbolt.org/z/voq9nY) of declaration of function in another function. – Ted Lyngmo Mar 23 '20 at 17:58
  • Forward declaration of the functions, in a header file or in the same file ahead of first use, or eliminating forward definitions where possible and moving the functions definitions ahead of first use. – user4581301 Mar 23 '20 at 18:02
  • A function needs to be declared before it can be used (e.g. called). That declaration does not need to be IN the function. – Peter Mar 23 '20 at 18:57

0 Answers0