gpt4 book ai didi

c++ - OpenGL 3.1 上下文创建后的 GL_INVALID_ENUM/GL_INVALID_OPERATION

转载 作者:行者123 更新时间:2023-11-28 02:17:21 27 4
gpt4 key购买 nike

我有另一个希望不是那么愚蠢的问题 - 我想清理一些我从 OpenGL1.3 更新到 3.1 的旧代码。所以我现在在最后一步将上下文创建更改为类似这样的内容(下面自己的代码): https://www.opengl.org/wiki/Tutorial:_OpenGL_3.1_The_First_Triangle_%28C%2B%2B/Win%29

我正在使用 GLEW 1.13.0,如果我只对旧的上下文创建额外执行 glewInit,一切正常,但在切换到纯 3.1 上下文之后:

glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); is giving me GL_INVALID_ENUM
glAlphaFunc( GL_GREATER, 0.5 ); is giving me GL_INVALID_OPERATION
glDisable( GL_ALPHA_TEST ); is giving me GL_INVALID_ENUM
glEnable(GL_NORMALIZE); is giving me GL_INVALID_ENUM

现在根据我的阅读,这些在 OpenGL3.1 中都没有弃用 - 我错过了什么?

目前看起来是这样的:

hWnd = (HWND)GetWindow();
hDC = GetDC( hWnd );

INT DesiredColorBits = 32;
INT DesiredStencilBits = 8;
INT DesiredDepthBits = 24;

PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, 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 = DesiredColorBits;
pfd.cDepthBits = DesiredDepthBits;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.cStencilBits = DesiredStencilBits;

INT nPixelFormat = ChoosePixelFormat( hDC, &pfd );
printf("Using pixel format %i", nPixelFormat);
if (!SetPixelFormat( hDC, nPixelFormat, &pfd ))
return 0;

hRC = wglCreateContext( hDC );
wglMakeCurrent(hDC, hRC);

//init glew
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
return 0;

INT MajorVersion=3;
INT MinorVersion=1;

if (WGLEW_ARB_create_context && WGLEW_ARB_pixel_format)
{
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize= sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.iLayerType = PFD_MAIN_PLANE;

const INT iPixelFormatAttribList[] =
{
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_COLOR_BITS_ARB, DesiredColorBits,
WGL_DEPTH_BITS_ARB, DesiredDepthBits,
WGL_STENCIL_BITS_ARB, DesiredStencilBits,
0 // End of attributes list
};
INT iContextAttribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, MajorVersion,
WGL_CONTEXT_MINOR_VERSION_ARB, MinorVersion,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0 // End of attributes list
};

INT iPixelFormat, iNumFormats;
wglChoosePixelFormatARB(hDC, iPixelFormatAttribList, NULL, 1, &iPixelFormat, (UINT*)&iNumFormats);

// pfd oldstyle crap...
if (!SetPixelFormat(hDC, iPixelFormat, &pfd))
return 0;

hRC = wglCreateContextAttribsARB(hDC, 0, iContextAttribs);
}

if(hRC)
{
printf("GL_VENDOR : %s", glGetString(GL_VENDOR));
printf("GL_RENDERER : %s", glGetString(GL_RENDERER));
printf("GL_VERSION : %s", glGetString(GL_VERSION));
printf("GLEW Version : %s", glewGetString(GLEW_VERSION));

wglMakeCurrent(hDC, hRC);
}
else
return 0;

我删除了代码,如果我遗漏了什么,我深表歉意,但是上下文已经初始化,我得到:

Using pixel format 9
GL_VENDOR : NVIDIA Corporation
GL_RENDERER : GeForce GT 740M/PCIe/SSE2
GL_VERSION : 4.4.0
GLEW Version : 1.13.0

代码中的第一部分初始化旧样式上下文以便初始化 GLEW,而我对 3.1 创建中的 PFD 部分有点不确定(尽管许多示例都是这样显示的)。尽管如此,我尝试了来自不同示例和教程的几个不同变体,并且在尝试设置上述状态时它总是导致 GL_INVALID_OPERATION 和 GL_INVALID_ENUM。

最佳答案

GL_PERSPECTIVE_CORRECTION_HINT 不再位于核心中,3.1 中也没有。引用the OpenGL wiki有关详细信息,但 3.1 中允许的枚举(并且在 4.5 之前保持不变)是:

  • GL_LINE_SMOOTH_HINT
  • GL_POLYGON_SMOOTH_HINT
  • GL_TEXTURE_COMPRESSION_HINT
  • GL_FRAGMENT_SHADER_DERIVATIVE_HINT

也就是说,不要为创建 3.1 上下文而烦恼。如果可以,请选择 4.4/4.5,如果要支持上一代,3.3 是合理的最小值。

关于c++ - OpenGL 3.1 上下文创建后的 GL_INVALID_ENUM/GL_INVALID_OPERATION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33669773/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com