Jump to content
  • Advertisement
Sign in to follow this  
geforcefan

OpenGL C++ and GLUT will not work!

This topic is 4114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ;)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!