PDA

View Full Version : simple openGL question



zzapatista
02-15-2001, 09:17 AM
This is the main body of an example problem i got out of an opengl book:

int main (int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

glutInitWindowSize(250, 250);

glutInitWindowPosition(100, 100);

glutCreateWindow(argv[0]);

init();

glutDisplayFunc(display);

glutReshapeFunc(reshape);

glutMouseFunc(mouse);

glutMainLoop();

return 0;

}

I was just wondering if anyone could tell me the function of
(int argc, char** argv) being passed into the main function?

02-15-2001, 09:30 AM
well it looks like a console application, and those variables are used to tell what sort of command line paramaters were specified when the program was started, like a -n or /p whatever, nothing to do with OpenGL to tell you the truth.

hell i might be wrong.

02-15-2001, 09:40 AM
I think its for command line arguements. Think you can specify window size and other parameters with the argument strings.

I usually put glutInit after I set the window size. So, in the event someone does pass a command line paramater it will use it instead before I create the window.

john
02-15-2001, 02:52 PM
int argc, char **argv (which can also be written int argc, char *argv[], if you've seen that) ARE the command line options.

argc (argument count) indicates how many parameters you have, and argv (argument vector) is a vector of pointers to the strings containting the arguments. an example, Mr Music:

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

for(t=0; t<argc; t++) {
printf("arg %d: %s\n", t, argv[t]);
}
}

argc is always at least 1. the first argument (argv[0]) points to the executable name, and possibly the path, too, depending on your o/s.

cheers,
John