在 OpenGL Win32 上激活多重采样
Activating Multisample on OpenGL Win32
我想在win32 API中的OpenGL上下文上设置MSAA。一切正常,但 MSAA 只是不想激活。这是我用于构建上下文的代码:
void Display::CreateGLContext(HWND hWND) {
mHDC = GetDC(hWND); //get current windows device context
int nPixelFormat;
PIXELFORMATDESCRIPTOR pfd; // Create a new PIXELFORMATDESCRIPTOR (PFD)
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); // Clear our PFD
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); // Set the size of the PFD to the size of the class
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; // Enable double buffering, opengl support and drawing to a window
pfd.iPixelType = PFD_TYPE_RGBA; // Set our application to use RGBA pixels
pfd.cColorBits = 32; // Give us 32 bits of color information (the higher, the more colors)
pfd.cDepthBits = 16; // Give us 32 bits of depth information (the higher, the more depth levels)
pfd.iLayerType = PFD_MAIN_PLANE; // Set the layer of the PFD
/* Choose best matching format*/
nPixelFormat = ChoosePixelFormat(mHDC, &pfd);
/* Set the pixel format to the device context*/
SetPixelFormat(mHDC, nPixelFormat, &pfd);
HGLRC tempRC = wglCreateContext(mHDC);
wglMakeCurrent(mHDC, tempRC);
if (glewInit() != GLEW_OK) {
MessageBox(mHWND, "Eroare", "glew", MB_OK);
}
int nPixelFormat2;
BOOL bValidPixFormat;
UINT nMaxFormats = 1;
UINT nNumFormats;
float pfAttribFList[] = { 0, 0 };
int piAttribIList[] = {
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_COLOR_BITS_ARB, 32,
WGL_RED_BITS_ARB, 8,
WGL_GREEN_BITS_ARB, 8,
WGL_BLUE_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, 16,
WGL_STENCIL_BITS_ARB, 0,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
WGL_SAMPLES_ARB, 16,
0, 0 };
bValidPixFormat = wglChoosePixelFormatARB(mHDC, piAttribIList, pfAttribFList, nMaxFormats, &nPixelFormat2, &nNumFormats);
if (!bValidPixFormat)
{
MessageBox(NULL, "Invalid Pixel Format", "Error! (SetupWGLPixelFormat)", MB_OK);
}
SetPixelFormat(mHDC, nPixelFormat2, &pfd);
mGLRenderContext = wglCreateContext(mHDC);
wglMakeCurrent(mHDC, NULL);
wglDeleteContext(tempRC);
wglMakeCurrent(mHDC, mGLRenderContext);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
}
代码工作正常,它是在主类中创建 hWnd 后调用的,而不是在 WndProc 中WM_CREATE情况下...可能出了什么问题?
我看到您要求 16 个样本的部分。但是我没有看到您启用GL_MULTISAMPLE
的部分.如果没有它,呈现到多采样缓冲区与呈现到单个采样缓冲区没有什么不同。
此外,我建议您对多重采样渲染目标使用帧缓冲区对象,而不是默认帧缓冲区。是的,默认帧缓冲可以通过窗口调整大小,这很好。但是,通过使用帧缓冲对象,您可以控制何时解析多重采样。
此外,它还允许您防止驾驶员讨厌的控制面板选项弄乱您的样品计数;)
我发现了问题。基本上你不能在本文提到的同一窗口中调用 SetPixelFormat:https://www.khronos.org/opengl/wiki/Creating_an_OpenGL_Context_(WGL)#Proper_Context_Creation
解决方案基本上是创建一个虚拟窗口(不可见)启用opengl并将其删除。我已经从这里复制了代码,它对我有用 使用 WGL 创建现代 OpenGL 上下文?
相关文章:
- 如何将stdout重定向到stderr
- QTableView:endMoveRows在模型中重置水平页眉大小
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 编写时C++中的输入重定向问题
- 如何用RISC-V GD32VF103CBT6开发板卸载精确的ADC过采样
- 如何避免在仅标头库中C++类/变量重定义
- 更改"child's parent's style sheet"时如何将孩子的样式表重置为 Qt 默认样式表?
- 通过重命名C++中的符号来减小二进制大小
- 切换大小写后如何阻止变量重置?
- 获取通过重定向传入的输入文件的名称?
- 在头文件和 cpp 文件中使用一次 #pragma 时出现结构重定义错误
- C++:错误重定义和先前声明
- 避免模板类中的重定义错误
- 绕道重铸瓷砖层是怎么回事
- 如何以与 API 兼容的方式重命名类成员?
- Windows C++重定向库
- 通过Python Distutils(用于Python C扩展)使用可重定位的设备代码编译CUDA代码
- 如何在Visual Studio Code中重命名我的a.exe文件?
- 在未填充为 4 字节的 3 通道上进行图像重采样
- 在 OpenGL Win32 上激活多重采样