2013-08-04 149 views
0

我实现了一个名为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应用程序的类中实现此任务?

+0

[在类中使用OpenGL glutDisplayFunc]的可能重复(http://stackoverflow.com/questions/3589422/using-opengl-glutdisplayfunc-within-class) –

回答

1

首先得到这种误解:GLUT是不是 OpenGL的一部分,你不必使用它!

您不能混合GLUT和MFC。无论过剩和MFC做差不多的事情:

  • 提供了一个框架来创建Windows和处理用户输入
  • 管理应用程序的主事件循环

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


反正你得到错误告诉你以下几点:

  • glutDisplayFunc预计纯函数指针作为回调
  • 传递给glutDisplayFunc的事情是不是一个函数指针,而是一个类成员指针,它本身缺少关于它引用的类的哪个实例的信息。该实例必须作为附加参数传递或与成员指针打包在一起 - 但glutDisplayFunc将永远无法使用。

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