Is there any possibility of capturing opengl output of child process?
Child should not have a different window. Output should be captured and displayed by parent instead.
I know that i can create a layer that my child could use to create opengl callbacks in my parent application. And send data by socket or pipe.
Edit: I write main and child applications.
CodePudding user response:
OK, here's a rundown of how I think this can be done. This is totally untested, so YMMV.
Create your window in the parent process. According to this page, you need to create it with the
CS_OWNDC
style, which means it has the sameHDC
permanently associated with it.Launch your child process. You can pass the
HWND
to it as a command line parameter, converted to hex-ascii, say, or you can devise some other method.In the child process, call
GetDC
to retrieve theHDC
of the parent's window and pass it towglCreateContext
(I imagine you know all about doing that sort of thing).In the child process, draw, draw, draw.
Before exiting the child process, make sure you call
ReleaseDC
to free up any resources allocated byGetDC
.
This ought to work. I know that Chrome uses a separate process for each browser tab, for example (so that if the code rendering into any particular tab should crash, it affects that tab only).
Also, if you're thinking of jumping through all these hoops just because you want to reload some (different) DLLs, maybe you're looking for LoadLibrary
and GetProcAddress
instead. Hmmm, maybe I didn't need to write all that :)