Hi,

I'm hoping to read the frame buffer of a VBS2 window via the VBS2 supplied plugin functionality. Code as follows:-

HWND vbs2_hWnd = NULL;
RECT rect;
vbs2_hWnd = FindWindow(NULL,L"VBS2");
GetWindowRect(vbs2_hWnd,&rect);

HDC hdc=GetDC(vbs2_hWnd);

PIXELFORMATDESCRIPTOR pfd;


ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;


int format = ChoosePixelFormat( hdc, &pfd );
bool pixelFormatSet = SetPixelFormat( hdc, format, &pfd );
HGLRC mhRC = wglCreateContext( hdc );

bool madeCurrent = wglMakeCurrent( hdc, mhRC );
GLenum err = glGetError();
if (err!=0)
printf("wglMakeCurrent error = %d\n",err);

DWORD dwBmpSize = (rect.right-rect.left)*(rect.bottom-rect.top)*4;

lpbitmap = (char*)malloc(dwBmpSize);

glReadBuffer(GL_BACK);
err = glGetError();
if (err!=0)
printf("glReadBuffer error = %d\n",err);

err = glewInit();
if (err!=0)
printf("glewInit error = %d\n",err);
GLuint pboBuffer;
glGenBuffers(1,&pboBuffer);
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB,pboBuffer);
glBufferData(GL_PIXEL_PACK_BUFFER_ARB,dwBmpSize,0, GL_STREAM_READ);

err = glGetError();
if (err!=0)
printf("SwapBuffers error = %d\n",err);

glReadPixels(0,0,rect.right-rect.left,rect.bottom-rect.top,GL_RGBA,GL_UNSIGNED_BYTE,0);
err = glGetError();
if (err!=0)
printf("glReadPixel error = %d\n",err);
memcpy(lpbitmap,glMapBuffer(GL_PIXEL_PACK_BUFFER_A RB,GL_READ_ONLY_ARB),dwBmpSize);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);


free(lpbitmap);
wglMakeCurrent(NULL,NULL);
wglDeleteContext(mhRC);

Everything seems to work fine except there's no data (00 00 00 FF per pixel). I know the context's correct because if I swap buffers it mucks things up in precisely the way one might expect.

Is it actually possible to read another Windows image data in this way? I can imagine that writing might be contentious.

I've already done it using BitBlt etc. and this works fine, but I had hoped to get the depth data for some laser range simulation and make it run a bit quicker.

Thanks

John