我正在尝试为OpenGL 4.3创建渲染上下文。 我已经创建了一个临时渲染上下文,以便加载所有扩展,然后销毁这个临时渲染上下文,它可以工作,所有功能都被加载。
现在我必须创建最终的渲染上下文,但似乎我找不到好的像素格式。
这是我用来尝试查找像素格式并创建最终渲染上下文的函数:
int attributeListInt[19];
int pixelFormat[20];
unsigned int formatCount;
int result;
PIXELFORMATDESCRIPTOR pixelFormatDescriptor;
int attributeList[5];
float fieldOfView, screenAspect;
char *vendorString, *rendererString;
m_hDeviceContext = GetDC(m_hWnd);
if (!m_hDeviceContext)
return false;
attributeListInt[0] = WGL_SUPPORT_OPENGL_ARB;
attributeListInt[1] = TRUE;
attributeListInt[2] = WGL_DRAW_TO_WINDOW_ARB;
attributeListInt[3] = TRUE;
attributeListInt[4] = WGL_ACCELERATION_ARB;
attributeListInt[5] = WGL_FULL_ACCELERATION_ARB;
attributeListInt[6] = WGL_COLOR_BITS_ARB;
attributeListInt[7] = 32;
attributeListInt[8] = WGL_DEPTH_BITS_ARB;
attributeListInt[9] = 24;
attributeListInt[10] = WGL_DOUBLE_BUFFER_ARB;
attributeListInt[11] = TRUE;
attributeListInt[12] = WGL_SWAP_METHOD_ARB;
attributeListInt[13] = WGL_SWAP_EXCHANGE_ARB;
attributeListInt[14] = WGL_PIXEL_TYPE_ARB;
attributeListInt[15] = WGL_TYPE_RGBA_ARB;
attributeListInt[16] = WGL_STENCIL_BITS_ARB;
attributeListInt[17] = 8;
attributeListInt[18] = 0;
result = wglChoosePixelFormatARB(m_hDeviceContext, attributeListInt, NULL, 20, pixelFormat, &formatCount);
if (result != 1)
return false;
bool bCreatedSuccessfully = false;
for (int i = 0; i < formatCount && !bCreatedSuccessfully; i++)
{
result = SetPixelFormat(m_hDeviceContext, pixelFormat[i], &pixelFormatDescriptor);
if (result == 1)
bCreatedSuccessfully = true;
}
if (!bCreatedSuccessfully)
return false;
if (m_bOpenGL43)
{
attributeList[0] = WGL_CONTEXT_MAJOR_VERSION_ARB;
attributeList[1] = 4;
attributeList[2] = WGL_CONTEXT_MINOR_VERSION_ARB;
attributeList[3] = 3;
}
else
{
attributeList[0] = WGL_CONTEXT_MAJOR_VERSION_ARB;
attributeList[1] = 3;
attributeList[2] = WGL_CONTEXT_MINOR_VERSION_ARB;
attributeList[3] = 3;
}
attributeList[4] = 0;
m_hRenderingContext = wglCreateContextAttribsARB(m_hDeviceContext, 0, attributeList);
if (m_hRenderingContext == NULL)
return false;
result = wglMakeCurrent(m_hDeviceContext, m_hRenderingContext);
if (result != 1)
return false;
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CW);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
if (bVSyncEnalbed)
result = wglSwapIntervalEXT(1);
else
result = wglSwapIntervalEXT(0);
if (result != 1)
return false;
m_bInitialized = true;
return true;
我的问题是wglChoosePixelFormatARB返回10个可用的像素格式,但它们似乎都没有,因为SetPixelFormat总是返回FALSE。
有什么想法吗?