我对 OpenGL 比较陌生,我想在我的 C++ Win32 项目中添加抗锯齿功能。我目前在收到 WM_CREATE 消息时在窗口过程中获取设备上下文,然后使用像素格式描述符创建 OpenGL 上下文,如下所示:
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
//...
switch (msg) {
case WM_CREATE:
log("Starting WM_CREATE...");
hDC = GetDC(hWnd);
//Pixel Format
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;
format = ChoosePixelFormat(hDC, &pfd);
if (!SetPixelFormat(hDC, format, &pfd)) {
log("Error: Could not set pixel format.");
PostQuitMessage(1);
break;
}
//Create Render Context
hRC = wglCreateContext(hDC);
if (!wglMakeCurrent(hDC, hRC)) {
log("Error: Could not activate render context.");
PostQuitMessage(1);
break;
}
//Initialize GLEW
if (glewInit()) {
log("Error: Could not initialize GLEW.");
PostQuitMessage(1);
break;
}
//Other initialization goes here
//...
break;
//...
}
return 0;
}
为了让抗锯齿功能发挥作用,我知道我需要使用 WGL_ARB_multisample 之类的扩展。似乎很少有如何实际使用它的例子,尤其是在 GLEW 中。我将如何修改我的代码以使其正常工作?谢谢。