PDA

View Full Version : glutMotionFunc error



TifaOng
05-05-2011, 10:16 PM
I wanted to translate an object following a mouse and these are my coding related to the mouse motion,

void mouseDrag(int x, int y)
{
int button;
int state;
GLfloat translateX;
GLfloat translateY;
if ((state == GLUT_DOWN) && (button == GLUT_LEFT_BUTTON)) // translate
{
translateX += (400-x)/ 1000.0f;
translateY += (400-y) / 1000.0f;
}
gl_draw(translateX, translateY);
glutPostRedisplay();
}

in gl_draw() i use glTranslatef(translateX,translateY, -6.0f); to translate the object.

and in main()
glutMotionFunc(mouseDrag);

But I keep getting this error : Error 2 error C2664: 'glutMotionFunc' : cannot convert parameter 1 from 'overloaded-function' to 'void (__cdecl *)(int,int)' F:\UTM courses\OpenGL Tutorials\VidTut\cube\main.cpp 475

I think it refers to the mouseDrag() function. But where is the error?

Please help.
Thank you very much!!!

ZbuffeR
05-06-2011, 12:26 AM
The "overloaded funtion" sound like a C++ problem ? Ie. if your function was declared as a pure C function, it would work.
Sorry not good enough at C++ to help more.

Alfonse Reinheart
05-06-2011, 12:51 AM
It's more likely that the function is, you know, overloaded. C++ can't tell which function you mean when you try to pass it as a parameter.

I honestly can't remember how to get the function pointer for an overloaded function, but the easiest remedy is to simply change the name of the other overloads so that it is no longer overloaded.

TifaOng
05-06-2011, 09:22 PM
mouseDrag is the only function name in my whole program,
to my understanding overloaded function is the function with same name but different parameters, but right now the functions names are all unique.

How can it be overloaded?

ZbuffeR
05-07-2011, 12:36 AM
Searching the web with your kind of error message, it seems people resolved it by explicitely casting the function pointer to desired type, with static_cast.