# how to render on a window which has a bigger backbuffer

This topic is 2062 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]

##### Share on other sites

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

##### Share on other sites

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 );
device->Present( &vRect, 0, 0, 0); // vRect determines which portion of the buffer to present

Edited by Buckeye

##### Share on other sites

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 );
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.

##### Share on other sites

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.

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.

Edited by Buckeye

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 18
• 34
• 9
• 16
• 22