Question

In c++, we are used to see that opengl is installed in main function.Such as-

int main(int argv,char **argc){
         glutInit(&argv,argc);
         glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB|GLUT_DEPTH);

..............................
}

But without this main function,how can we declare opengl in other sub functions? Such as-

int main(){
...........}

int installopengl(int argv,char **argc){
glutInit(&argv,argc);


glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB|GLUT_DEPTH);

..............................
}
Was it helpful?

Solution 3

While it is defiantly not recommended, you can always do this:

int i = 0;
glutInit(&i, NULL);

The issue with doing it this way is that you won't be able to pass any information to the glut library from the command line.

OTHER TIPS

Maybe I misunderstood - why cant you directly call the function like below ?

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

    ...........
}

int installopengl(int argv,char **argc) {
    glutInit(&argv,argc);
    glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB|GLUT_DEPTH);

    ..............................
}

Please get your terminology right. OpenGL is not installed in a program. It get's initialized.

Also the pattern you quoted is GLUT initialization. GLUT is not OpenGL, but a simple windowing framework, that creates a OpenGL context for you to use to draw to the window. But there are several other frameworks as well.

Then you seem to completely misunderstand what the main function does. main is the program entry point, the very first function that gets called in a process after the runtime environment has been set up. main can call any function, and you can simply call a dedicated framework initialization there. If it needs parameters from main you simply pass them along.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top