我想创建一个渲染环境来使用 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/