I’m trying to find out how to read the entire screen into a PBO (for transfering int cuda for post processing if it matters). I managed to find how to do it under linux (X windows) with GLX but I can’t seem to find out how to do it with WGL.
Under linux something like this works:
Display *dpy = XOpenDisplay(NULL);
Window root = DefaultRootWindow(dpy);
GLint att[] = {GLX_RGBA, None};
XVisualInfo *vis = glXChooseVisual(dpy, 0, att);
GLXContext glc = glXCreateContext(dpy, vis, NULL, true);
glXMakeCurrent(dpy, root, glc);
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, WIDTH, HEIGHT, GL_BGRA, UNSIGNED_BYTE, NULL);
I tried the following under windows but all it gets me is a blank buffer
HDC hdc;
HGLRC hglrc;
hdc = GetDC(hWnd);
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1, /* version */
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24, /* 24-bit color depth */
0, 0, 0, 0, 0, 0, /* color bits */
0, /* alpha buffer */
0, /* shift bit */
0, /* accumulation buffer */
0, 0, 0, 0, /* accum bits */
32, /* z-buffer */
0, /* stencil buffer */
0, /* auxiliary buffer */
PFD_MAIN_PLANE, /* main layer */
0, /* reserved */
0, 0, 0 /* layer masks */
};
int iPixelFormat;
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, iPixelFormat, &pfd);
hglrc = wglCreateContext (hdc);
wglMakeCurrent (hdc, hglrc);
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGB, UNSIGNED_BYTE, NULL);