Adam
Adam

Reputation: 1396

Is it possible to move glutInit to my init function?

I use such main function for my c program using glut ( it works) :

int main(int argc, char **argv)
{
  char filename[MAXLINE];

  /* Read in the file (allocates space for Picture) */
  if (argc < 2) 
    {
    printf ("Enter the name of a PPM or PGM file: ");
    scanf("%s", filename);
    readPPM ((char *)filename, &Picture);
    }
    else { readPPM (argv[1], &Picture); }

    glutInit(&argc, argv);
    MyInit();
    glutPassiveMotionFunc(PassiveMouseMotion); // mouse move with no key pressed 
    glutReshapeFunc(Reshape);
    glutDisplayFunc(Draw);
    glutKeyboardFunc(Key);

    glutMainLoop();
    return 0;
}

Is it possible and good idea to move some code to myInit function and use :

int main(int argc, char **argv)
{

    MyInit(@argc, argv);
    glutPassiveMotionFunc(PassiveMouseMotion); // mouse move with no key pressed 
    glutReshapeFunc(Reshape);
    glutDisplayFunc(Draw);
    glutKeyboardFunc(Key);

    glutMainLoop();
    return 0;
}

( above code does not work , it is a proposition)

??

Upvotes: 0

Views: 335

Answers (1)

jpw
jpw

Reputation: 44921

Possible? Yes. Good idea? Don't know. It might be nice to have all init-related code in one place I guess.

If MyInit is declared as

void MyInit(int argc, char *argv[]) {
    glutInit(&argc, argv);
    // other init code etc... 
}

You should be able to call it from mainusing:

MyInit(argc, argv);

I doubt that glutInit cares from which function it's called, as long as it's called in a proper way, and before you do any GL stuff.

Upvotes: 1

Related Questions