C++ OpenGL 4.3的像素格式

C++ OpenGL 4.3的像素格式,c++,opengl,C++,Opengl,我正在尝试为OpenGL4.3创建一个渲染上下文。 为了加载所有扩展,我创建了一个临时渲染上下文,然后销毁了这个临时渲染上下文,它工作了,所有功能都加载了 现在我必须创建最终渲染上下文,但似乎找不到好的像素格式 这是我用来尝试查找像素格式并创建最终渲染上下文的函数: int attributeListInt[19]; int pixelFormat[20]; unsigned int formatCount; int result; PIXELFORMATDESCRIPTOR pixelForm

我正在尝试为OpenGL4.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;
int属性限制[19];
int像素格式[20];
无符号整数格式计数;
int结果;
像素格式描述符像素格式描述符;
int属性列表[5];
浮动视野、屏幕外观;
char*vendorString,*renderString;
m_hDeviceContext=GetDC(m_hWnd);
如果(!m_hDeviceContext)
返回false;
attributeListInt[0]=WGL\u支持\u OPENGL\u ARB;
属性限制[1]=真;
属性限制[2]=WGL\u DRAW\u TO\u WINDOW\u ARB;
属性限制[3]=真;
属性限制[4]=WGL\u加速度\u ARB;
属性限制[5]=WGL\u全加速度\u ARB;
属性限制[6]=WGL\u COLOR\u BITS\u ARB;
属性限制[7]=32;
attributeListInt[8]=WGL\u DEPTH\u BITS\u ARB;
属性限制[9]=24;
attributeListInt[10]=WGL\u DOUBLE\u BUFFER\u ARB;
属性限制[11]=真;
属性限制[12]=WGL\U交换方法\U ARB;
属性限制[13]=WGL\U交换\U ARB;
属性限制[14]=WGL\u像素类型\u ARB;
属性限制[15]=WGL_类型RGBA_ARB;
属性限制[16]=WGL\u模板\u位\u ARB;
属性限制[17]=8;
属性限制[18]=0;
结果=wglChoosePixelFormatARB(m_hDeviceContext、attributeListInt、NULL、20、pixelFormat和formatCount);
如果(结果!=1)
返回false;
bool bCreatedSuccessfully=false;
对于(int i=0;i
我的问题是wglChoosePixelFormatARB返回10种可用的像素格式,但它们似乎都不对,因为SetPixelFormat总是返回FALSE


有什么好主意吗?

试试24小时的
WGL\u COLOR\u BITS\u ARB
。这是仅RGB组件的总计数。因此,对于每个颜色分量8位,值应该是24。如果您也需要alpha,那么有一个单独的
WGL\u alpha\u BITS\u ARB
值。也许可以尝试摆脱
WGL\u SWAP\u方法\u ARB
。您应该能够依靠它选择最佳的交换方法。我尝试了删除
WGL\u交换方法\u ARB
和设置
WGL\u颜色\u位\u ARB
的24,但仍然没有任何结果。唯一改变的是,现在wglChoosePixelFormatARB返回20像素格式,而不是10像素格式。我在某些平台上遇到了WGL_ACCELERATION_ARB的问题。好的,我找到了解决方案。当我创建临时渲染上下文以加载OpenGL 4.3时,我正在为我真正尝试创建渲染上下文的同一窗口设置像素格式。所以我也在一个临时窗口中加载了扩展,一切正常。