2013-08-04 148 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將永遠無法使用。

或換句話說:你試圖做的事情是不可能的(沒有建立一些包裝或使用一些骯髒的黑客)。