Gluten arguments

I am new to openGL. In all simple examples, the main function has arguments and glutinit func uses them. But I do not understand why they are needed. I do not write anything in the arguments of the command, and the programs still work. What are they used for? Can you give an example?

glutInit(&argc, argv) 
+4
opengl
Jan 19 '13 at 2:00
source share
3 answers

They are used so that GLUT can handle command line arguments. He has a number of arguments that he always uses. If you do not want GLUT to process arguments, just pass something like this:

 { int argc = 1; char *argv[1] = {(char*)"Something"}; glutInit(&argc, argv); } 
+6
Jan 19 '13 at 3:30
source share

glutInit is used to initialize the GLUT library. In C, you can accept command line arguments. Command line arguments are specified after the program name in command line operating systems, such as DOS or Linux, and are transferred to the program from the operating system. To use command-line arguments in your program, you must first understand the full declaration of the main function, which previously did not accept arguments. In fact, main can actually take two arguments: one argument is the number of command line arguments, and the other argument is a complete list of all command line arguments.

argcp: pointer to the unmodified argc variable from main. Upon return, the value pointed to by argcp will be updated, since glutInit retrieves any command-line options intended for the GLUT library. argv: program unmodified variable argv from main. Like argcp, the data for argv will be updated as glutInit retrieves any command line options that the GLUT library understands.

glutInit also handles command line parameters, but the analysis of individual parameters depends on the Windows system.

+2
May 11 '14 at 16:42
source share

Another scenario is when unix main() takes command line arguments, none of which we want to redirect to GLUT.

In this case, we must declare and initialize the "user" GLUT initialization variables somewhere inside main() :

 int foo = 1; char * bar[1] = {" "}; glutInit(&foo, bar); 
0
Apr 29 '16 at 23:31 on
source share



All Articles