473,804 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Registering a GLUT Callback in C++

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 (GLUTCALLBACK *func)(void) )

called like so:

glutDisplayFunc ( display );

My problem is when I move to C++ objects, I have a class with a member
function 'void display(void)', which I want to register like:

glutDisplayFunc ( this->display );

But I get the error (in MSVC++):

error C2664: 'glutDisplayFun c' : cannot convert parameter 1 from
'void (void)' to 'void (__cdecl *)(void)'

What is the correct way to do this?

Thanks,
Michael
Jan 4 '06 #1
5 14296

Michael Kipper wrote:
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 (GLUTCALLBACK *func)(void) )

called like so:

glutDisplayFunc ( display );

My problem is when I move to C++ objects, I have a class with a member
function 'void display(void)', which I want to register like:

glutDisplayFunc ( this->display );

But I get the error (in MSVC++):

error C2664: 'glutDisplayFun c' : cannot convert parameter 1 from
'void (void)' to 'void (__cdecl *)(void)'

What is the correct way to do this?


"correct" is subjective.

http://www.google.com/search?hl=en&l...2B&btnG=Search

You can't actually do what you are trying to do. You'll need to use
some hack. See above for some ideas.

Jan 4 '06 #2
Michael Kipper wrote:
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 (GLUTCALLBACK *func)(void) )

called like so:

glutDisplayFunc ( display );

My problem is when I move to C++ objects, I have a class with a member
function 'void display(void)', which I want to register like:

glutDisplayFunc ( this->display );

But I get the error (in MSVC++):

error C2664: 'glutDisplayFun c' : cannot convert parameter 1 from
'void (void)' to 'void (__cdecl *)(void)'

What is the correct way to do this?

Thanks,
Michael


Maybe try something like GLUT for C++

http://www.cs.unc.edu/~rademach/glui/

-JJ
Jan 4 '06 #3
Michael Kipper wrote:
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 (GLUTCALLBACK *func)(void) )

called like so:

glutDisplayFunc ( display );

My problem is when I move to C++ objects, I have a class with a member
function 'void display(void)', which I want to register like:

glutDisplayFunc ( this->display );

But I get the error (in MSVC++):

error C2664: 'glutDisplayFun c' : cannot convert parameter 1 from
'void (void)' to 'void (__cdecl *)(void)'

What is the correct way to do this?


There is none.

Read the FAQ, it explains why non-static members cannot be used as
callbacks.

V
Jan 4 '06 #4

Michael Kipper wrote in message ...
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 (GLUTCALLBACK *func)(void) )
called like so:
glutDisplayFunc ( display );
My problem is when I move to C++ objects, I have a class with a member
function 'void display(void)', which I want to register like:
glutDisplayFunc ( this->display );
But I get the error (in MSVC++):
error C2664: 'glutDisplayFun c' : cannot convert parameter 1 from
'void (void)' to 'void (__cdecl *)(void)'
What is the correct way to do this?
Thanks,
Michael

You need to use 'static'. Much removed from the example below, but, should be
enough for you to get the idea.

// ---------------------------------------------------------
// GLutBase.cpp - Minimal GLut window
// made with (C) GLUTwriter by BobR <07dec01>
// ---------------------------------------------------------
#include <windows.h> // Standard Header For MSWindows Applications
#include "glut.h" // GL Utility Toolkit (GLUT 3.7) Header. LOCAL dir.

class GLRock{
public: //--------------------------------------- public
GLRock(){ } //GLRock() Ctor
~GLRock(){} //GLRock() Dtor
//--------------------------------------------------------------
bool InitGL(); // All setup for OpenGL goes here
// ======= InitCallBacks =======
static void InitCallBacks() ; // Match functions to their counterparts
static void DrawGLScene(); // Drawing done here
// ---------------------------------------------
protected: //--------------------------------------- protected
private: //--------------------------------------- private
// ---------------------------------------------
}; //GLRock
// ---------------------------------------------

// ======= InitGL =======
bool GLRock::InitGL( ){
// --- All setup for OpenGL goes here ---
return TRUE;
} //InitGL()
// ---------------------------------------------

// ======= DrawGLScene =======
void GLRock::DrawGLS cene(){
// --- Drawing done here ---
} //DrawGLScene()
// ---------------------------------------------

// ======= InitCallBacks =======
void GLRock::InitCal lBacks(){ // Match functions to their counterparts
glutDisplayFunc ( DrawGLScene ); // Register Display Function
// --- etc. ---
} //InitCallBacks()
// ---------------------------------------------

// ======= MAIN =======
int main(int argc, char** argv) {
glutInit(&argc, argv); // GLUT Initializtion
glutInitDisplay Mode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA );
if( g_gamemode ){
glutGameModeStr ing("640x480:24 "); // Select The 640x480 in 24bpp
Mode
if(glutGameMode Get(GLUT_GAME_M ODE_POSSIBLE))
glutEnterGameMo de(); // Enter Full Screen
else g_gamemode = false; // No Game Mode, switch to Windowed
}
if( not g_gamemode){
glutInitWindowS ize(640, 480); // Window size if Windowed Mode
glutCreateWindo w("GLut OpenGL Rock Demo"); // Window Title
}

GLRock GLR;
if( not GLR.InitGL() ){ // GL Initialization
/* "InitGL FAILED */
return EXIT_FAILURE;
}

GLR.InitCallBac ks();

glutMainLoop(); // Go To GLUT Main Loop
// --- Never reaches this line ---
return 0;
} //main()
// =============== =============== ===========

--
Bob R
POVrookie
Jan 4 '06 #5
Michael Kipper wrote:
What is the correct way to do this?


I've solved wrapping the callbacks.
Example (I use a reshape method from a custom obj called MainWindow):

----------------------------------------------------------
//Wrapping the glut reshape callback
void reshape(int w, int h){MainWindow.r eshape (w,h);}

int main ( int argc, char** argv )
{

glutInit ( &argc, argv );
glutReshapeFunc ( reshape );
glutDisplayFunc ( display );
glutMotionFunc( motion);
glutMainLoop ( );
system("PAUSE") ;
return 0;
}
----------------------------------------------------------
Jan 5 '06 #6

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

Similar topics

1
1995
by: Fulko van Westrenen | last post by:
Hello, I'm very new to Python and rather unexperienced in OpenGL, and now I try to learn both at the same time. I can find my way around in Perl with Perl/Tk. What I try to do is combining Tk and GLUT. Based on the dots.py code (from the examples) I wrote a working application that reacts fine to my keyboard. Now I would like to add some Tk widgets, like 'Quit' in the texturesurf2.py example. The problem is that texturesurf2.py takes a
5
5511
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 in the python23\Lib\site-packages\OpenGL\Demo\GLUT\examples directory. When I'm in Windows Explorer and double click on the icon for this program, it runs fine. However, when I try to 'execfile' molehill from the Python command line, I have...
1
3145
by: Martin Magnusson | last post by:
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?
0
2207
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 don't use it because I have grow so accustom to using Linux. (GCC rox!) I find GCC to be good because of its simplicity.
1
5618
by: Scott Chang | last post by:
Hi All I tried to use the attached OpenGL code to draw a Star-shaped figure on my Microsoft Visual C++ .NET 2002-Windows XP Pro PC. When I did 'Build' in Debug Mode, I got an error C2065: 'RenderScence': undeclared identifier. Please help and tell me (1) what it is wrong with my coding in this program and how to correct the problem, and (2) whether the functions/commands of the OpenGL v1.1 (existing in Microsoft Visual C++ .NET 2002) and GLUT...
13
3056
by: noone | last post by:
consider the following problem: You have a C style library and API that uses callbacks to implement functionality. Examples of this are X11 API, OpenGL/GLUT...The List goes on. The power of virtuals in C++ leads us to want to implement a framework where those callbacks are simply overriden virtual methods in a derived class. So...
1
2556
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 requires callback methods to be set for rendering and eventhandeling. The header of my engine looks like this : class RenderDevice { public: RenderDevice(int width, int height, char* const caption);
0
1737
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 refresh. Here's a helpful test program I've found from Mindf**k's glut tutorial... #include <iostream> #include <GL/glut.h> #include <cstdlib> using namespace std; void createMenu(void);
0
2119
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via callback.setHandler1(callback1) this only seems to affect pythons ability to trigger an "event" in c. PyObject *Handler is always NULL even after I call Register_Handler(...). I thought there was some magic here that was assigning the pointer *Handler to my python...
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9169
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7633
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.