PDA

View Full Version : Implementing C++ and OpenGL?



sh0ck2
01-27-2003, 09:45 AM
if i want to make a program structure with c++ with references to OpenGL commands, vars, etc, Can i just program it in the same file? or do i have to make a separate source project and link it via .DLL? if i can do it in the same file, then where do I do it (and any changes to normal #defs??) not sure if i stated this very clearly, but maybe you know what im talking about. my main frustration with openGL is the gigantx0r window initialization code, which confuses me on where to put everything. (any IDE's that will 'secretly' implement the code so i dont get confused when seeing it?)

Deiussum
01-27-2003, 12:28 PM
You can use the OpenGL headers right in your C++ source files. There's nothing wrong with using C functions from C++. You just need to use extern "C" in front of the function prototypes, but the GL.h file should already do that.

For APIs that hide the window initialization code, you can look at things like glut, SDL, and GLFW.

02-02-2003, 08:03 PM
What about using C++ routines in the window callbacks? I have tried unsuccessfully to
use C++ member functions in these callbacks. e.g. glutDisplayFunc(myC++memberfunc)... even declaring this func as extern "C" does not work. Has anyone done this? Is it possible in VC++6?

SThomas
02-02-2003, 08:46 PM
Originally posted by Wenlock:
What about using C++ routines in the window callbacks? I have tried unsuccessfully to
use C++ member functions in these callbacks.

declaring the member function as static should do the trick.


static void myMethod(void); beware though that declaring a member function static means that it can't be virtual.

Deiussum
02-04-2003, 08:30 AM
Static functions can also only access other static members of that class. That is because there is no "this" pointer associated with a static method.