Jump to content

  • Log In with Google      Sign In   
  • Create Account


How do I keep the screen from squishing and stretching?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 sunnysideup   Members   -  Reputation: 105

Like
0Likes
Like

Posted 06 November 2012 - 12:08 AM

I've programmed a simple little app that renders a triangle to the screen. Whenever I maximize the screen or drag the resize bars the triangle squishes and stretches along with the window. I wrote a function that uses IDXGISwapChain::ResizeBuffers() to resize the swap chain's buffers in response to a WM_SIZE message but it doesn't seem to fix the distortion. Am I misunderstanding the purpose of IDXGISwapChain::ResizeBuffers()?

Here's my OnResize() function. I'm either doing something wrong, or ResizeBuffers doesn't do what I though it did. Sorry if this is a dumb question Posted Image

[source lang="cpp"]HRESULT OnResize(LPARAM lParam){ g_pImmediateContext->OMSetRenderTargets(0, 0, 0); // Release any extraneous instances of swap chain's buffers. The render // target view typically holds references to swap chain's buffers. g_pRenderTargetView->Release(); UINT width = LOWORD(lParam); UINT height = HIWORD(lParam); // Resize swap chain's buffers. HRESULT hr = g_pSwapChain->ResizeBuffers(1, width, height, DXGI_FORMAT_R8G8B8A8_UNORM, 0); if(FAILED(hr)) { MessageBox(NULL, "[ERROR] Failed to resize buffers.\nOnResize() in rederer.cpp", "ERROR", MB_ICONERROR | MB_OK); return hr; } // Get buffer and create render target view. ID3D11Texture2D* pBackBuffer = nullptr; hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer); if(FAILED(hr)) { MessageBox(NULL, "[ERROR] Failed to get back buffer.\nOnResize() in renderer.cpp", "ERROR", MB_ICONERROR | MB_OK); return hr; } hr = g_pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_pRenderTargetView); pBackBuffer->Release(); if(FAILED(hr)) { MessageBox(NULL, "[ERROR] Failed to create render target view." "\nOnResize() in renderer.cpp", "ERROR", MB_ICONERROR | MB_OK); return hr; } g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, NULL); // Set up viewport. D3D11_VIEWPORT vp; vp.Width = (float)width; vp.Height = (float)height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; g_pImmediateContext->RSSetViewports(1, &vp); return S_OK;}[/source]


And here's the little snippet inside of WndProc() where I call it.

[source lang="cpp"]case WM_SIZE: if(g_pSwapChain) { OnResize(lParam); } return 0;[/source]


Thanks for the help.

Sponsor:

#2 sunnysideup   Members   -  Reputation: 105

Like
0Likes
Like

Posted 06 November 2012 - 12:11 AM

Eeek. It doesn't look like the code hilighting came out right. Sorry about that guys :/

#3 sunnysideup   Members   -  Reputation: 105

Like
0Likes
Like

Posted 06 November 2012 - 01:07 AM

I think I might be able to better clarify what I'm getting at. I've rendered an equalateral trianlge with vertices (0.0, 0.5, 0.5), (0.5, -0.5, 0.5), and (-0.5, -0.5, 0.5) without any projection transformation. How can I make it so that the the triangle remains equalateral whenever the user resizes the window? Isn't this what ResizeBuffers() is supposed to do or would this require a projection transformation or something like that?

Edited by sunnysideup, 06 November 2012 - 01:08 AM.


#4 NumberXaero   Prime Members   -  Reputation: 1306

Like
1Likes
Like

Posted 06 November 2012 - 01:59 AM

Are you updating your projection matrix?

Edited by NumberXaero, 06 November 2012 - 02:00 AM.


#5 sunnysideup   Members   -  Reputation: 105

Like
0Likes
Like

Posted 06 November 2012 - 02:17 AM

Are you updating your projection matrix?


There's no projection transformation. This is actually just a slightly modified version of the triangle tutorial in the SDK docs. I (perhaps stupidly) thought that resizing the swap chain's buffers would cause the triangle to retain it's shape when the window is resized. I'm guessing that would require a projection transformation? If I wanted to make a 2D game for example where the sprites were rendered to a square, would I need to do a projection transformation on the square. Pardon my ignorance.

Edited by sunnysideup, 06 November 2012 - 02:20 AM.


#6 Gavin Williams   Members   -  Reputation: 642

Like
0Likes
Like

Posted 06 November 2012 - 06:44 AM

I'd say you are working in clip space, which is -1 to 1 in x & y, and that space will stretch. So you will need to use world / view / projection matrices for getting everything the way you want it.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS