【发布时间】:2018-10-05 11:27:58
【问题描述】:
我正在尝试使用上下文访问整个屏幕。
这是我当前的代码(目前只有这个文件):
#include <stdio.h>
#include <Windows.h>
#include <GL/gl.h>
#include <gl/glu.h>
#include <GL/glext.h>
int main(int argc, char *argv[]) {
HDC hdc = GetDC(NULL);
HGLRC hglrc;
hglrc = wglCreateContext(hdc);
// Handle errors
if (hglrc == NULL) {
DWORD errorCode = GetLastError();
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL );
printf("Failed with error %d: %s", errorCode, lpMsgBuf);
LocalFree(lpMsgBuf);
ExitProcess(errorCode);
}
wglMakeCurrent(hdc, hglrc);
printf("%s\n", (char) glGetString(GL_VENDOR));
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hglrc);
return 0;
}
问题出在开头的这段代码中:
HDC hdc = GetDC(NULL);
HGLRC hglrc;
hglrc = wglCreateContext(hdc);
并且程序的输出(在错误处理if语句中打印)是
Failed with error 2000: The pixel format is invalid.
调用 GetDC(NULL) 被指定为检索整个屏幕的 DC,所以我不确定这里出了什么问题。我该如何解决这个问题?
编辑:添加更多信息
【问题讨论】:
-
您在哪里选择和设置像素格式?