how to render on a window which has a bigger backbuffer

Started by
4 comments, last by Buckeye 10 years, 1 month ago

i found unrealengine/udk will reset the directx9 device when i change current window to a bigger resolution, so the window's client size as same as the back buffer size.

but when i change this window to smaller, it will not reset the d3d device.

my question is how to do this, just only SetViewport with the small width and height?

i have debug it in the pix for windows, this is a pic:

[attachment=19971:1.png]

[attachment=19972:2.png]

Advertisement
Hi,

The DXSDK documentation on SetViewPort (http://msdn.microsoft.com/en-us/library/windows/desktop/bb174469(v=vs.85).aspx) is quite clear.
You just have to specify the rectangle zone you want to use.
Then you use the exact same zone to render to your window.

found unrealengine/udk will reset the directx9 device when i change current window to a bigger resolution, so the window's client size as same as the back buffer size.

but when i change this window to smaller, it will not reset the d3d device.

my question is how to do this, just only SetViewport with the small width and height?

It is not realy dependant on this. Device reset will be needed only if its native back/front buffer resizes, not the window presented onto. In windowed mode, you can pass a handle of a window to the present() funtion - it can be 50x50 window with you presenting a 1600*1200 back buffer to it. A devidce will need to reset only if its native back/front buffer is resized (thus droped-recreated). SetViewport advices the present function on how to present the backbuffer only, no further effects over this function. This function also comes in handy if you wish to interpret very mouse click into projection space of buffers. This function thus can be used to present only portions of a buffer and so on. Remember, it is only your off screen buffers or back/front native buffers that needs to be droped when changed in dimension. In ful screen mode, present draws over entire screen, in windowed, to the area. viewport leaves you with some power over this presenting


SetViewport advices the present function on how to present the backbuffer only, no further effects over this function.

That's not true. Setting the viewport determines which portion of the backbuffer is to be rendered to. The Present function has parameters unrelated to the viewport settings which determine what portion of the backbuffer to present, etc. The viewport size and the source rect may be the same but don't need to be.

EDIT: To answer the OP: yes, set the viewport to the size of the current window client. Then use the same size rect as the first parameter in Present.


RECT vRect;
GetClientRect(hwnd, &vRect);
// set the area in the buffer to be rendered to
D3DVIEWPORT9 vp;
vp.x = 0;
vp.y = 0;
vp.Width = vRect.right;
vp.Height = vRect.bottom;
vp.MinZ = 0;
vp.MaxZ = 1;
device->SetViewport( &vp );
.... (do your rendering)
device->Present( &vRect, 0, 0, 0); // vRect determines which portion of the buffer to present

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

found unrealengine/udk will reset the directx9 device when i change current window to a bigger resolution, so the window's client size as same as the back buffer size.

but when i change this window to smaller, it will not reset the d3d device.

my question is how to do this, just only SetViewport with the small width and height?

It is not realy dependant on this. Device reset will be needed only if its native back/front buffer resizes, not the window presented onto. In windowed mode, you can pass a handle of a window to the present() funtion - it can be 50x50 window with you presenting a 1600*1200 back buffer to it. A devidce will need to reset only if its native back/front buffer is resized (thus droped-recreated). SetViewport advices the present function on how to present the backbuffer only, no further effects over this function. This function also comes in handy if you wish to interpret very mouse click into projection space of buffers. This function thus can be used to present only portions of a buffer and so on. Remember, it is only your off screen buffers or back/front native buffers that needs to be droped when changed in dimension. In ful screen mode, present draws over entire screen, in windowed, to the area. viewport leaves you with some power over this presenting


SetViewport advices the present function on how to present the backbuffer only, no further effects over this function.

That's not true. Setting the viewport determines which portion of the backbuffer is to be rendered to. The Present function has parameters unrelated to the viewport settings which determine what portion of the backbuffer to present, etc. The viewport size and the source rect may be the same but don't need to be.

EDIT: To answer the OP: yes, set the viewport to the size of the current window client. Then use the same size rect as the first parameter in Present.


RECT vRect;
GetClientRect(hwnd, &vRect);
// set the area in the buffer to be rendered to
D3DVIEWPORT9 vp;
vp.x = 0;
vp.y = 0;
vp.Width = vRect.right;
vp.Height = vRect.bottom;
vp.MinZ = 0;
vp.MaxZ = 1;
device->SetViewport( &vp );
.... (do your rendering)
device->Present( &vRect, 0, 0, 0); // vRect determines which portion of the buffer to present

thank you very much...

another question,

when i reset the render target, must i call setviewport agian?

because when i do a simple render test, first set a render target which is 2048x2048, and setviewport 1024x1024,

after draw call,

i reset the render target to another render target which is 2048x2048 too, after this, i have not setviewport.

but when i debug next draw call , i found the viewport is 2048x2048(by nisght), in pix for windows, it is always 1024x1024, but the result is wrong because the actually viewport size is 2048x2048, so i reset viewport size after i change the render target, it works well.

smile.png

I set the viewport, view and projection just before every render, because each render may be of a different size, a different projection and a different view position.

3windows.png

The jaggies are because I made the window small to get a reasonable size from a screen print.

These are 3 separate child windows of the main window, all rendered using the same backbuffer, just different viewports, views (eye positions), projections (aspect ratio, ortho/perspective), rendering modes (solid, wireframe), etc. After each render, device->Present( &cRect, &cRect, hRenderWnd, 0 ); where cRect is the client size of the child window for that draw. In this particular situation, I set the viewport to the client size.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement