From: smr@cs.stanford.edu Newsgroups: su.class.cs248 Subject: Re: openGL C to C++ HELP Date: 3 Nov 1999 01:41:17 GMT Susheel M. Daswani wrote: > Our feisty OpenGL book has all its examples in C, which is just fine for > people who like BellBottoms and Disco music, but I was hoping to bring > them into the new millenium by converting them to C++. Well, here is > the problem: certain functions (I wouldn't dare call them methods), such > as glutDisplayFunc, require you to pass functions types, such as (void > (*func)(void)). Well, if I want to incorporate these calls into a > class, I have a problem since I can't pass them method from the class, > since Bjarne had to build OO on top of C, so every method in a class has > a funky type that makes the compiler complain. Any direction on how to > get over this problem would be duly appreciated. One approach is to use static member functions. That's not perfect, since you still don't get to have the callbacks associated with objects, but at least you get to encapsulate everything within a class. Another solution is to have an abstract base class that lets derived classes register their own callbacks, register a static member function of its own as a regular GLUT callback, and distributes the callbacks to the clients. If this sounds confusing, check out http://www.duke.edu/~stetten/GlutMaster/GlutMaster.html which is an implementation that basically does the above for you. Feel free to use it (with acknowledgment) if you think it does what you want. - Szymon -------- From: "Susheel M. Daswani" Newsgroups: su.class.cs248 Subject: Re: openGL C to C++ HELP Date: Wed, 03 Nov 1999 00:05:51 -0800 Thanks Szymon. I encourage everyone to take advantage of the GlutMaster and GlutWindow class, it is cool. Also, I am going to be keeping converted C programs from the text on the web, so feel free to use them if you want a C++ alternative. The url is www.stanford.edu/~smd/code. Right now, the program from page 24 of the text is up. Only difference is that the right mouse button stops the spinning, not the middle one (I am developing on my PC). Susheel