c++ - 这个上下文创建有什么问题?

标签 c++ windows opengl

我想创建一个渲染环境来使用 opengl。 wglMakeCurrent(hdc, hrc) 正在返回 true。

但由于某些原因,OpenGL 函数被忽略了。

这里是创建上下文的代码:

int pixelFormat;

hdc = GetDC(hwnd);

PIXELFORMATDESCRIPTOR pfd;
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 = 32;
pfd.iLayerType = PFD_MAIN_PLANE;

pixelFormat = ChoosePixelFormat(hdc,&pfd);
SetPixelFormat(hdc,pixelFormat,&pfd);

hrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, hrc);

和窗口创建:

hinst = GetModuleHandle(NULL);

WNDCLASSEX wnd;
memset(&wnd, 0, sizeof(WNDCLASSEX));
wnd.hInstance = hinst;
wnd.style = CS_HREDRAW | CS_VREDRAW;
        wnd.cbSize = sizeof(WNDCLASSEX);
        wnd.lpszClassName = "__myGLApp__";
        wnd.lpfnWndProc = WndProc;
        RegisterClassEx(&wnd);

        hwnd = CreateWindowEx(WS_EX_TOOLWINDOW, 
            "__myGLApp__",
            "valami",
            WS_VISIBLE,
            xpos,
            ypos,
            width,
            height,
            NULL,
            NULL,
            hinst,
            NULL);

我哪里错了?

最佳答案

您可以使用 glGetError() 函数来获取错误代码。您还可以使用实用程序库中的函数 gluErrorString() 和 gluErrorUnicodStringEXT() 获取文本描述。像这样:

char *message;
message = gluErrorString(glGetError());
printf("OpenGL error: %s\n", message);

关于c++ - 这个上下文创建有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4981941/

相关文章:

python - 错误 - 此版本的 Visual Studio 无法打开以下项目

c++ - Visual Studio 跳过代码行

OpenGl 框全屏

python - 需要将 Windows 应用程序(在我的例子中是 Excel)带到前台 - python

windows - 使用 Windows 批处理脚本为文件夹中的每个文件应用命令

java - glBufferData 生成 GL_INVALID_OPERATION

c++ - 如何在 Visual Studio Code 中的 ubuntu 上的应用程序调试 c OpenGl 期间显示光标

c++ - 在 OpenGL 中绘制斯坦纳罗马曲面

c++ - 修改日志类以接受字符串中的变量 - C++

java.lang.UnsatisfiedLinkError : Native method not found: 错误