OpenGL - glut "setup" very basic concept ( in Linux)

OK, this is very stupid, but…
It seems that all tutorials are focused on manipulating screen.
Fine. But I have not found a single explanation of very basic concept, without getting into "pipe etc ". Ended up with “multiple window definition” error.
So here is something, in pseudo code , I like to get confirmed from the group
setting up glut :

optionally verify non glut headers / libraries - if required
initialize glut
setup simple "main"basic “window” - size, color etc.
setup buffering
add “callbacks” as required (display, keyboard …)
start “main loop” - and watch for smoke

Now for meat and potatoes

  1. can I keep the basic glut setup - including "main loop "
    in C++ class constructor?
    If so - is there a real advantage to do so ?
    The OpenGL class will be active until the program is terminated , done.

  2. Is there a way to put the OpenGL “callbacks” functions as members of the class?
    I get " has to be static" and "cannot be static ".
    It does not matter if the callbacks are “global” - defined outside class, but it woudl be more organized if they are class functions.

It it is frowned on asking C++ (openGL) questions here, just ignore me.

You cannot use a method directly as a GLUT callback. You will need some non-member helper functions (technically, these should be declared with C linkage, i.e. extern "C" ...). If you only have a single window and a single instance of the class, then you can store that instance (or a pointer or reference to it) in a global variable (or static member variable) and just have the helper functions invoke the corresponding method on the instance.

It gets more complex if you have multiple instances of the class corresponding to multiple windows as the helper would need to use glutGetWindow to identify the correct instance before it can invoke methods on it. Conversely, if you want to add methods which call GLUT functions, the methods may need to call glutSetWindow first (GLUT always calls this itself before invoking callbacks, so it isn’t necessary when calling GLUT functions from callbacks unless you need the function to operate on a different window to that for which the callback was invoked).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.