问题
I have the following function I've defined that i use with glDebugCallback
, which works perfectly fine with GCC and Clang on Linux. However on Windows, the following code does not want to register as a debug callback for OpenGL:
inline void messageCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length, const GLchar* message,
const void* userParam) {
// ...
}
and then I set it up with
glDebugMessageCallback(messageCallback, nullptr);
After looking up what the glew headers have, it shows:
typedef void (GLAPIENTRY *GLDEBUGPROC)(GLenum source, GLenum type, GLuint id, GLenum severity,
GLsizei length, const GLchar* message,
const void* userParam);
but I'm getting an error message that says
Error (active) E0167 argument of type "void (*)(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)" is incompatible with parameter of type "GLDEBUGPROC"
I've been trying to figure out why it fails only with MSVC... but I'm quite stuck since it looks like it matches verbatim. The fact it compiles on GCC/Clang is also a bit confusing as well, I'm not sure what I'm missing or why this is happening.
Note that the inline
keyword does not affect the result, I tried it without the keyword and the same problem is there. I just kept it there because I wanted to copy and paste the exact thing. I also put this through a diff checker to see if I did the parameters wrong in any way, but they are identical.
This is within Visual Studio 2017, using C++17, glew 2.1.0, modern Opengl, etc. My OpenGL version is 4.6 as well.
回答1:
You probably need to include the GLAPIENTRY
qualifier:
void GLAPIENTRY messageCallback(...)
This specifies a calling convention that tells the compiler to modify the way the function's arguments are passed. On some platforms it makes no difference, but I would guess it probably does on Windows.
来源:https://stackoverflow.com/questions/55755492/function-unable-to-match-gldebugproc-only-on-msvc-uses-same-glew-version-2-1-0