Jump to content
  • Advertisement
Sign in to follow this  

Issues resizing swap chain (DX9)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

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 tongue.png).
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];


HRESULT hr = d3ddev->Reset(&d3dpp);

if(hr != D3D_OK)
MessageBox(NULL, "Call to Reset() failed!", "ERROR", MB_OK | MB_ICONEXCLAMATION);


Restore device objects is:
void DXHandler::restoreDeviceObjects()
d3ddev->GetSwapChain(0, &swapchains[0]);

for(int i = 1; i < 4; i++)
d3dpp.BackBufferHeight = screenSize.x;
d3dpp.BackBufferWidth = screenSize.y;
d3dpp.hDeviceWindow = hWnd;

d3ddev->CreateDepthStencilSurface(d3dpp.BackBufferHeight, d3dpp.BackBufferWidth, d3dpp.BackBufferFormat, d3dpp.MultiSampleType, d3dpp.MultiSampleQuality, true, &depthStencils, NULL);

d3ddev->CreateAdditionalSwapChain(&d3dpp, &swapchains);


d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE);
d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);
d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));

D3DXCreateTeapot(d3ddev, &meshTeapot, NULL);

Any ideas?


Share this post

Link to post
Share on other sites
Going from the picture, the problem seems to be with the cameras that you're using to render the teapot, not the swap-chain.

Are you using 4 different cameras, and how do you configure them?

Share this post

Link to post
Share on other sites
Each one is rendered like:
swapchains[1]->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
d3ddev->SetRenderTarget(0, pBackBuffer);

d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);


// set the view transform
D3DXMATRIX matView; // the view transform matrix
&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
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;
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);



swapchains[1]->Present( NULL, NULL, hWnd[1], NULL, 0 );


(Thats the top right window render code)
They are all initialized with the device restore code

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!