i know terminology of question must wrong, please bear me , try see things layman's point of view (i have no formation in computer technology, i'm self taught enthusiast. closest formal education in programming language school's robotics club).
what want able use managed directx 12 "background" of application, game loop , all. and, if possible, able have wpf controls ribbon or toolbox or menu around actual directx game. i've been looking on internet , find old stuff windows , directx 9.0; i'm hoping there's new these days.
i tryed windows form approach, this:
using system; using system.windows; using system.windows.interop; using microsoft.directx.direct3d; using dcolor = system.drawing.color; public partial class mainwindow : window { device device; public mainwindow() { initializecomponent(); initdevice(); } private void initdevice() { try { presentparameters parameters = new presentparameters(); parameters.windowed = true; parameters.swapeffect = swapeffect.discard; intptr windowhandle = new windowinterophelper(this).handle; device = new device(0, devicetype.hardware, windowhandle, createflags.hardwarevertexprocessing, parameters); } catch(exception e) { messagebox.show("initdevice threw exception\n" + e.message, "error", messageboxbutton.ok, messageboximage.error); } } private void render() { device.clear(clearflags.target, dcolor.lightgreen, 0f, 1); device.present(); } }
no exception thrown, window never rendered @ all. application runs, window doesn't show up. didn't think work, because there's no game loop , render
doesn't invoked anywhere, didn't expect window not being displayed. if comment out line invokes initdevice(), wpf's blank window shown normally
then discovered compositiontarget.rendering
event gets called once every frame (or tick?), handler event must used game loop.
and tried this:
using system; using system.drawing; using system.io; using system.windows; using system.windows.media; using system.windows.forms.integration; using microsoft.directx.direct3d; using dcolor = system.drawing.color; using system.windows.forms; public partial class mainwindow : window { device device = null; memorystream stream; picturebox display; windowsformshost host; public mainwindow() { initializecomponent(); initdevice(); compositiontarget.rendering += compositiontarget_rendering; } private void compositiontarget_rendering(object sender, eventargs e) { render(); } private void initdevice() { try { presentparameters parameters = new presentparameters(); parameters.windowed = true; parameters.swapeffect = swapeffect.discard; device = new device(0, devicetype.hardware, display, createflags.hardwarevertexprocessing, parameters); stream = new memorystream(); device.setrendertarget(0, new surface(device, stream, pool.managed)); } catch(exception e) { system.windows.messagebox.show("initdevice threw exception\n" + e.message, "error", messageboxbutton.ok, messageboximage.error); } } private void render() { device.clear(clearflags.target, dcolor.lightgreen, 0f, 1); device.present(); display.image = image.fromstream(stream); } private void window_loaded(object sender, routedeventargs e) { host = new windowsformshost(); display = new picturebox(); host.child = display; maingrid.children.add(host); } }
still no window shown, though application running , not crashing.
finally tried same thing without handling compositiontarget.rendering
, using dispatchertimer instead, , called render inside tick
event handler. same result: no window.
can point me right direction?
this project should help. supports direct3d 11, principles same directx 12.
that said, why need directx 12 instead of sticking directx 11? answer should more technical "12 bigger 11."