473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

GLUT callback registration (not quite OT)


Hi all. I'm having trouble registering a GLUT callback function.
glutIdleFunc wants a void(*)() function as argument, and I believe
that's what I've given it, but gcc complains with the following message:

GraphicDisplay.cpp:15: error: no matches converting function `DrawC' to
type `void (*)()'
GraphicDisplay.hpp:11: error: candidates are: void GraphicDisplay::DrawC()

Can anyone see what I'm missing here?

//---begin code:

class GraphicDisplay
{
public:
void Init();
void DrawC();
};

void GraphicDisplay::Init()
{
// Standard GLUT init stuff...
// (snip)
glutIdleFunc( GraphicDisplay::DrawC );
}

void GraphicDisplay::DrawC()
{
// some code...
}

//---end code.

Jul 19 '05 #1
1 3126
"Martin Magnusson" <lo*******@frustratedhousewives.zzn.com> wrote in message
news:bj**********@green.tninet.se...
GraphicDisplay.cpp:15: error: no matches converting function `DrawC' to
type `void (*)()'
GraphicDisplay.hpp:11: error: candidates are: void GraphicDisplay::DrawC()
Glut is a C library, and it expects a pointer to a C function.
So you cannot pass a non-static member function to it.

What will probably work is to replace: void DrawC();

with:
static void DrawC();

But yes, this will force you to use global variables (DrawC will not
be able to access non-static member variables of class GraphicDisplay.
Note that, in theory, you also need to add an extern "C"
in front of the function's declaration (this is to formally
follow the standard, but this is rather rarly used in such
a context...)

hth,
--
http://www.post1.com/~ivec <> Ivan Vecerina
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steven Gutstein | last post by:
I've just managed to get PyOpenGL installed on a Windows NT machine. I've tried testing it using one of the programs supplied with the PyOpenGL download - molehill.py. On my machine, it was placed...
8
by: Ash | last post by:
Hello all, I am hoping this is the appropriate newsgroup for a C++ interface design question. I am trying to design an interface for a subscriber to register/deregister handlers for various...
0
by: Bushido Hacks | last post by:
What's that? I've go GCC working for Windows? Well, sort of. But I'm not using a Unix Emulator. The trick is to install Dev-C++, but do not use the Dev-C++ IDE unless you feel like it. I...
11
by: ajay.sonawane | last post by:
Hello ther I read somewhere that callback function should be global or static member function. 1: I could use static member functions but how could I access members of class which ar not static....
5
by: Michael Kipper | last post by:
Hi, I'm having a problem moving from C to C++. In C, I have a function: void display(void) {} that I can register with OpenGL as a callback using: GLUTAPI void glutDisplayFunc( void...
4
by: Dmitri Sologoubenko | last post by:
Hi, guys! I need a C++ class (Linux/POSIX/GNU C++), which can be started and stopped, and calls a virtual callback instance method (e.g. "expired()") when a given time has elapsed. High...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
1
Airslash
by: Airslash | last post by:
Hello, I'm trying to make a simpel renderengine that allows me to draw objects and 3D models. To make it cross-platform i'm working with the glut library supplied by OpenGL. This library...
0
by: shortyzms | last post by:
I have been trying to write a small glut program that uses popup context menus on right clicks to draw objects. However, every time I do this, the area underneath the submenu item I clicked does not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.