2
votes

I have a simple directx application which displays some pre-transformed geometries and I want the window to not flicker when I resize it and also i want the drawings to not stretch with window size.

I noticed about the stretching problem that, if I reset the device in WM_SIZING then the actual size of the drawing retains. But resetting the device every time I resize the window seems like an expensive operation. Actually I wanted to create some simple GUI using directx, but resizing the window seems to erase the front buffer data and thus flicks.I saw many application with custom gui using opengl allows resizing also WPF application allows resizing. How do I do that?

Also I would like to know, if there is no way I can achieve the effect of real time resizing without flicker and repositioning of drawn elements then how do WPF applications manage to do that?

Also I want to ask that, if you were to design GUI(non game) system using directx and want to implement resizing support as any other application does what would be your option?

1

1 Answers

3
votes

I want the window to not flicker when I resize it

Don't handle WM_ERASEBACKGROUND and similar messages. Leave all the painting to DirectX and there will be no flicker. Any flicker is basically you (or your controls) drawing something first, then DirectX drawing it's picture over it.

and also i want the drawings to not stretch with window size.

Not possible (at least without hacks). Assuming you use DirectX 9, you have to re-initialize the device to change it's resolution, and that is slow.

I can think of some workarounds to try, for instance, to change your projection matrix so that while the viewport resolution stays the same (no reinit), things that you see through your viewport reflect the window size.

In other words, you init your viewport to 640x480 and keep it at that, but if the user resizes your window to be 1024x768, you pack 1024x768 amount of things into your 640x480 viewport, which is then stretched to fill 1024x768 window.

This should give the impression that you "resize" the viewport, but since in fact it's scaling, picture quality will drop. Which is why you might want to reinit the viewport in the end, after the user is finished with resizing the window. This way you get quick resize first and picture quality afterwards.