Implementing C++ and OpenGL?

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

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.

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?

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.

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.