我对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。我将如何修改我的代码以使其工作?感谢。
答案 0 :(得分:1)
GLEW还支持WGL和glX扩展。对于wgl,您需要wglew.h
头文件。它的工作方式与GL扩展的工作方式相同:GLEW将通过glewInit()
调用自动获取wgl扩展的函数指针。
在Windows上,您实际需要做的是以下内容:
现在,WGL_ARB_multisample本身并没有定义任何wgl扩展函数。它只是从WGL_EXT_pixel_fromat定义wglChoosePixelFormatEXT()
的新属性。这就是您必须在步骤3中调用以请求支持多重采样的像素格式。