作为另一个函数的参数

时间:2013-08-04 06:59:08

标签: opengl mfc glut gdal glutcreatewindow

我正在实现一个名为FilesWorkFlow的类:

//this function is called by other functions of the class to set openGL data type
//based on GDAL data type
void FilesWorkFlow::setOpenGLDataType(void)
{
    switch (eType)
    {
    case GDT_Byte:
        type = GL_UNSIGNED_BYTE;
        break;
    case GDT_UInt16:
        type = GL_UNSIGNED_SHORT;
        break;
    case GDT_Int16:
        type = GL_SHORT;
        break;
    case GDT_UInt32:
        type = GL_UNSIGNED_INT;
        break;
    case GDT_Int32:
        type = GL_INT;
    }
}


//this function is called by other functions of the class to draw scene
void FilesWorkFlow::RenderScene(void)
{
    GLint iWidth = (GLint)RasterXSize;
    GLint iHeight = (GLint)RasterYSize;
    setOpenGLDataType();
    glClear(GL_COLOR_BUFFER_BIT);
    glRasterPos2i(0,0);
    glDrawPixels(iWidth,iHeight,format,type,pImage);
    glFlush();
}


//this function is called by other functions of the class to setup the 
//rendering state
void FilesWorkFlow::SetupRC(void)
{
    glClearColor(0.0f,0.0f,0.0f,1.0f);
}

void FilesWorkFlow::Show(void)
{
    int argc = 1;
    char **argv;
    argv[0] = "OPENGL";
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE);
    glutCreateWindow("Image");
    glutDisplayFunc(RenderScene);
    SetupRC();
    glutMainLoop();
}  

这是将在MFC应用程序中使用的类的一部分,用于渲染创建窗口,在其上呈现tiff图像,但在行glutDisplayFunc(RenderScene)我得到错误

argument of type "void (FilesWorkFlow::*)()" is incompatible with parameter of type "void (__cdecl *)()"  

即使将代码编写为glutDisplayFunc((_cdecl)RenderScene)也无济于事。如何解决此问题并在将在MFC应用程序中使用的类中实现此任务?

1 个答案:

答案 0 :(得分:1)

首先要解决这个误解: GLUT 不是是OpenGL的一部分,你不必使用它!

您不能混用GLUT和MFC。 GLUT和MFC都做同样的事情:

  • 提供用于创建Windows并处理用户输入的框架
  • 管理应用程序的主要事件循环

你不能在同一个程序中有两个不同的东西尝试做同样的事情。


无论如何,您收到的错误会告诉您以下内容:

  • glutDisplayFunc 期望普通函数指针作为回调
  • 传递给 glutDisplayFunc 的东西不是函数指针,而是一个类成员指针,它本身缺少有关它引用的类的哪个实例的信息。该实例必须作为附加参数传递或者使用成员指针打包 - 但 glutDisplayFunc 将永远无法使用该实例。

或者换句话说:你尝试做的事情是不可能的(没有建立一些包装或使用一些肮脏的黑客)。