r/csharp • u/bronylike • Jul 22 '24
how to continuously update an image
I'm making a 3d rendering engine, and I've gotten as far as to put the projected image into the window. but I would like it to be animated. just updating the image doesn't work as the window doesn't update until the image stops updating, and also it blocks input.
0
Upvotes
2
u/ccifra Jul 23 '24
It looks like you are using WPF with an image in the Window backed by a writeable bitmap.
You are doing some things in an odd order, for example you are rendering before you call app.run which means you are not pumping messages yet and the visual tree of the window may not be quite ready.
Have you set any breakpoints in the app? Do you get to app.run call? Are you seeing any exceptions?
12
u/Arcodiant Jul 22 '24
What are you using to present the image on the window?
The normal approach is to double-buffer; draw an image off-screen to a buffer, then swap the image on-screen with the off-screen buffer to update almost instantaneously.
1
u/bronylike Jul 22 '24
for those asking, here is the code as I have it at the moment, there are no graphics APIs, just c# code.
1
u/pjc50 Jul 22 '24
Post some code.
1
u/UninformedPleb Jul 22 '24
SwapChains and RenderTargets are what you're looking for.
What is a SwapChain?
Render Targets Overview
Also, play around with SharpDX for a bit. Yes, it's discontinued, but it's still a good place to start learning how the guts of a rendering loop work. It's DirectX-focused, but the core concepts translate over to OpenGL and Vulkan too. And once you've grokked the main concepts, if you want to skip some of the low-level stuff, Monogame is still pretty basic and has plenty of room for learning projects that don't automatically do everything for you. Monogame is what you'd probably build as you made several repeated attempts at making a generalized library/framework/engine with SharpDX.