floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.53k stars 467 forks source link

render to existing window handle #1051

Closed morganholly closed 1 month ago

morganholly commented 1 month ago

is there any way to render to an existing window handle? i would like to use sokol in an audio plugin library (and i know of another considering the same), and the normal way to do things is rendering to a window created by the software hosting the plugin. it would be very nice to have an easy way to get sokol going on an existing window handle. if there isn't a nice abstracted way to do this, do you have any suggestions on where in the (i presume sokol-gfx) code to look for each platform so i can set it up myself?

floooh commented 1 month ago

For D3D11/DXGI you can look at this minimal window system glue setup:

https://github.com/floooh/sokol-samples/blob/master/d3d11/d3d11entry.c

Basically start after the CreateWindowExW() call.

Here's the similar code for Metal+MTKView:

https://github.com/floooh/sokol-samples/blob/master/metal/osxentry.m

I don't have a similar simple example for GL, since those use GLFW:

https://github.com/floooh/sokol-samples/blob/master/glfw/glfw_glue.c

That part is otherwise taken care of by the the sokol_app.h header, and may be a bit more robust:

morganholly commented 1 month ago

mac and windows is higher priority than linux so if i can't get linux support soon that wouldn't be the worst thing. thank you very much for this