我正在尝试编写一个使用 GLEW 的小类,但我在石墙前,因为我不明白如何绕过编译器给我的问题。
在 VS2012 Express 中使用此代码
void OpenGlRendering::InitWindow(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitContextVersion(4, 0);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutSetOption(
GLUT_ACTION_ON_WINDOW_CLOSE,
GLUT_ACTION_GLUTMAINLOOP_RETURNS
);
glutInitWindowSize(CurrentWidth, CurrentHeight);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);
if(WindowHandle < 1) {
exit(EXIT_FAILURE);
}
glutReshapeFunc(OpenGlRendering::ResizeFunction);
glutDisplayFunc(RenderFunction);
glutIdleFunc(IdleFunction);
glutTimerFunc(0, TimerFunction, 0);
glutCloseFunc(Cleanup);
glutKeyboardFunc(KeyboardFunction);
}
void OpenGlRendering::ResizeFunction(int Width, int Height)
{
CurrentWidth = Width;
CurrentHeight = Height;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}
void OpenGlRendering::IdleFunction(void)
{
glutPostRedisplay();
}
我有这个编译器错误:
IntelliSense:“void (OpenGlRendering:: * )(int Width, int Height)”类型的参数与参数类型“void (*)(int, int)”不兼容
在使用某些类来清理代码中的混乱之前,它很好,因为该函数驻留在声明为普通函数的 main.cpp 中
void ResizeFunction(int Width, int Height)
{
CurrentWidth = Width;
CurrentHeight = Height;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}
并被这样称呼
glutReshapeFunc(OpenGlRendering::ResizeFunction);