Im working on an editor, but I'm having issues resizing the swap chains (theres 4 (including the main device)). The main devices swap chain resizes correctly, but the 3 subsequent ones dont. Il post an image of the editor and then post some more code (easier than trying to explain ).
And the code:
On resize, this is called: void DXHandler::updateBackBuffer(int width, int height, short which)
{
screenSize[which].x = width;
screenSize[which].y = height;
d3dpp.BackBufferHeight = screenSize[which].x;
d3dpp.BackBufferWidth = screenSize[which].y;
d3dpp.hDeviceWindow = hWnd[which];
Each one is rendered like: LPDIRECT3DSURFACE9 pBackBuffer = NULL;
swapchains[1]->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
d3ddev->SetRenderTarget(0, pBackBuffer);
d3ddev->SetDepthStencilSurface(depthStencils[1]);
// set the view transform
D3DXMATRIX matView; // the view transform matrix
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (0.0f, 1.0f, -6.0f), // the camera position
&D3DXVECTOR3 (0.0f, 0.0f, 0.0f), // the look-at position
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView);
// set the projection transform
D3DXMATRIX matProjection; // the projection transform matrix
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45), // the horizontal field of view
(FLOAT)screenSize[1].x / (FLOAT)screenSize[1].y, // aspect ratio
1.0f, // the near view-plane
100.0f); // the far view-plane
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);
static float index = 0.0f;
if((bool)getVariable("TeapotRotDir") == 1)
index += 0.3f / 10;
else
index -= 0.3f / 10;
D3DXMATRIX matRotateY; // a matrix to store the rotation for each triangle
D3DXMatrixRotationY(&matRotateY, index); // the rotation matrix
d3ddev->SetTransform(D3DTS_WORLD, &matRotateY);
For your aspect ratio, you're using the size of screen index 1. You should be using the size of the appropriate screen.
Hmm? Which bit of code. The code I posted in post #4, the array values are changed depending on screen, I just posted the code of the screen at index 1 as an example.
Ah, sorry - I assumed you'd use the same function for rendering to all views, and I thought the screenSize[1] was a typo.
As for why it's becoming pixelated, that looks like your backbuffer is too small, and D3D is scaling it up to fit the window, although I can't see why that would be by looking at your code. I'd try splattering some logging into your code to spit out the size of each swap chain, and check it's what you expect it to be.
Thanks Steve, after setting it up to render the current window size, and backbuffer size, I've noticed that the .x portion of the screen size Vector2 (what should be the width) was being assigned to the back buffer height, and vice-versa for the .y portion.