Programación Específica > OpenGL

 Error Funcion Glutmousefunc

(1/3) > >>

Perla_kiko:
hola tengo el siguiente codigo:

void CGlView::onMouse(int button, int state, int x, int y)
{
if((button== GLUT_LEFT_BUTTON) & (state== GLUT_DOWN))
{
   x0=x;y0=y;
}
}
y depues la llamada a :

glutMouseFunc(onMouse);

Cuando compilo me da el siguiente error alguien sabe pq?

error C2664: 'glutMouseFunc' : cannot convert parameter 1 from 'void (int,int,int,int)' to 'void (__cdecl *)(int,int,int,int)'
        None of the functions with this name in scope match  the target type

Ruben3d:
Hola.

glutMouseFunc() pide como parámetro un puntero a una función, y tú le estás pasando el nombre de un método de una clase (aunque me resulta un poco confuso el mensaje de error).

La única forma de pasar un método es si es estático, y hay que hacerlo con el calificativo completo:

CGlView::onMouse

Si no lo haces así, la única opción es pasar una función normal.

Un saludo.

Ruben3d

Perla_kiko:
lo he probado y me da el mismo error,

Como hago para pasar un funcion normal? perdona si la pregunta parece obvia pero soy nueva en esto! :D

lo he probado asi:

glutMouseFunc(CGlView::onMouse);
glutMotionFunc(CGlView:onMotion);

Ruben3d:
El método sólo lo puedes pasar si es estático, pero me da que no lo es (aun sin haber visto la declaración).

Para usar una función has de hacerla así:


--- Código: Text ---void onMouse(int button, int state, int x, int y){    if((button== GLUT_LEFT_BUTTON) & (state== GLUT_DOWN))    {        x0=x; y0=y;    }} glutMouseFunc(onMouse); 
Si tienes problemas de visibilidad con el método de la clase, haz lo siguiente (pero sólo si te diera algún problema):

--- Código: Text ---glutMouseFunc(::onMouse); 
Un saludo.

Ruben3d

Perla_kiko:
no hay manera! ahora no me da error de compilador, pero cuando cargo la pantalla de OPENGL me da un error de sistema que te adjunto en el fichero..

Perdon por las molestias, pq hay alguna otra manera de controlar el mouse?

Te explico un poco como va mi programa, por si te ayuda un poco

Tengo una plicacion hecha en visual c++ ,donde un usuario introduce unos datos en un dialogo y segun estos datos a partir de ese dialogo se abre otro dialogo con la simulacion, todo lo relacionado lo tengo en una libreria aparte donde el metodo principal es el siguiente:

void CDialogo_simulacionDlg::OnButton1()
{
   //   OpenGL in Picture in a Dialog
   CPaintDC dc(this); // device context for painting
   CStatic *pclStatic = (CStatic *)GetDlgItem(IDC_OPENGLWIN);
   CGlView *pclGlView = new CGlView(pclStatic);
   HDC m_hDC;
    m_hDC = ::GetDC(this->m_hWnd);

    RECT rect;
   GetClientRect(&rect);

    int iWidth = -(rect.right - rect.left);
    int iHeight = rect.top - rect.bottom;

   pclGlView->OnCreate();
   pclGlView->ReSizeGLScene(iWidth, iHeight);
   pclGlView->InitGL();
   pclGlView->DrawGLScene();
   


}

y la funcion initgl:
void onMouse(int button, int state, int x, int y)
{
if((button== GLUT_LEFT_BUTTON) & (state== GLUT_DOWN))
{
   x0=x;y0=y;
}
}

void onMotion(int x, int y)
{
alpha=(alpha+(y-y0));
beta=(beta+(x-x0));
x0=x;y0=y;
}
int CGlView::InitGL(GLvoid)                              // All Setup For OpenGL Goes Here
{
   glShadeModel(GL_SMOOTH);                     // Enable Smooth Shading
   glClearColor(0.0f, 0.0f, 0.0f, 0.5f);            // Black Background
   glClearDepth(1.0f);                           // Depth Buffer Setup
   glEnable(GL_DEPTH_TEST);                     // Enables Depth Testing
   glDepthFunc(GL_LEQUAL);                        // The Type Of Depth Testing To Do
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);// Really Nice Perspective Calculations
   glutMouseFunc(onMouse);
   glutMotionFunc(onMotion);
   return TRUE;                              // Initialization Went OK
}

int CGlView::DrawGLScene(GLvoid)               // Here's Where We Do All The Drawing
{
   glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity ();
   glPushMatrix ( );
   glColor4f ( 1.0, 1.0, 1.0, 1.0 );
   glTranslatef(mx,my,mz);
   glRotatef(alpha,1.0f,0.0f,0.0f);
   glRotatef(beta,0.0f,0.0f,1.0f);
   glRotatef(r2,.0f,0.0f,1.0f);
   
   //PintarEjes();
   glColor3f(1.0f, 1.0f, 1.0f);//blanco
   Cargar_Res("prova.res");
   Cargar_Ase();
   SwapBuffers(m_hDC);
   return TRUE;                              // Keep Going
}

Espero que no te haya liado aún mas!
 :lol:

Navegación

[0] Índice de Mensajes

[#] Página Siguiente

Ir a la versión completa