C++ and GLUT will not work!

Started by
0 comments, last by iNsAn1tY 17 years ago
Hello, I have one more problem with programing in C++. I programed before with C, now I want to write Games in c++. When Iḿ tryin` to compile the "game", I get an error: -------------------------------------------------------- ercan-lnx:/home/versuche/Thunder Rides Test Map # make gcc -o thunderrides src/tr_main.cpp src/tr_mains.cpp -lglut -lGL -lGLU -lm src/tr_main.cpp: In member function ‘void trMain::Main(int, char**)’: src/tr_main.cpp:63: error: argument of type ‘void (trMain::)()’ does not match ‘void (*)()’ src/tr_main.cpp:64: error: argument of type ‘void (trMain::)(int, int)’ does not match ‘void (*)(int, int)’ make: *** [thunderrides] Error 1 ercan-lnx:/home/versuche/Thunder Rides Test Map # -------------------------------------------------------- Here the code snippet of tr_main.cpp from line 56-69: -------------------------------------------------------- void trMain::Main(int argc, char *agrv[]) { glutInit(&argc,agrv); glutInitDisplayMode(GLUT_DEPTH|GLUT_RGBA|GLUT_DOUBLE); glutInitWindowSize(640,480); glutCreateWindow("Thunder Rides 1.0"); glutDisplayFunc(DrawOpenGLScene); glutReshapeFunc(ReshapeOpenGLScene); InitalizeOpenGL(); glutMainLoop(); }; -------------------------------------------------------- and here the code snippet of tr_main.h: -------------------------------------------------------- class trMain { private: void ReshapeOpenGLScene(int w, int h); void DrawOpenGLScene(void); int LevelOfDetail; } -------------------------------------------------------- I know that I have to add a "static"... but if I add "static", then there is an error... I cant modify "int LevelOfDetail" in the "ReshapeOpenGLScene()" or "DrawOpenGLScen()" procedure. I can only modify "int LevelOfDetail" out of a static void... What is wrong? Thanks ;)
Advertisement
You can specify the main function in C++ to be a static member of a class, but I've never seen this done before, and a quick test (in Visual Studio) suggests it's not a good idea. You'd need to add static before the main function's definition in the class header and change your linker options to make that the program entry point.

Unlike Java, where the main function must be a static member of a class, a C++ main function is pretty much exactly like a C main function. All of your initialization code can just go in there, and you can have other functions which handle GLUT reshape and display callbacks. If you want to wrap your program in a class, you need to create an instance of that class in the main function, then call it's methods.
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]

This topic is closed to new replies.

Advertisement