Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that a pointer to an instance bound member function has to include the <code>this</code> pointer. OpenGL is a C API, and knows nothing about <code>this</code> pointers. You'll have to use a static member function (which doesn't require an instance, and thus no <code>this</code>), and set some static data members (to access the instance) in order to use <code>glutDisplayFunc</code>.</p> <pre><code>class myPixmap { private: static myPixmap* currentInstance; static void drawCallback() { currentInstance-&gt;draw(); } void setupDrawCallback() { currentInstance = this; ::glutDisplayFunc(myPixmap::drawCallback); } }; </code></pre> <p>You may also have problems with C linkage vs C++ linkage, in which case you'll have to play around with <code>extern "C"</code>. If so, you might have to use a global function, rather than a static member function as your callback, and have <em>that</em> call <code>myPixmap::draw</code>. Something like:</p> <pre><code>class myPixmap { public: void draw(); private: void setupDrawCallback(); }; myPixmap* g_CurrentInstance; extern "C" void drawCallback() { g_CurrentInstance-&gt;draw(); } void myPixmap::setupDrawCallback(); { ::g_CurrentInstance = this; ::glutDisplayFunc(::drawCallback); } </code></pre> <p>With all of this, try to make as few changes as possible, since this is really kind of a kludge to deal w/ OpenGL being a C API.</p> <p>If you want multiple instances (I don't think most people using GLUT make multiple instances, but maybe you are), you'll have to figure out a solution using a std::map to retrieve the instance:</p> <pre><code>static std::map&lt;int, myPixmap&gt; instanceMap; </code></pre> <p>Where you'd get the <code>int</code> to resolve <em>which</em> instance, I am not sure :)</p> <p>FYI, you should define functions that take no parameters this way:</p> <pre><code>void some_function() { } </code></pre> <p>not</p> <pre><code>void some_function(void) { } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload