title: Window resizing and scaling images / Redeclaring back buffer size / C++ / DIRECTX 9.0
body: <p><strong>C++ / Windows 8 / Win api / DirectX 9.0</strong></p>
  
  <p>I am having real big issues with this:</p>
  
  <p><a href="https://github.com/jimmyt1988/TheGame/tree/master/TheGame" rel="nofollow noreferrer">https://github.com/jimmyt1988/TheGame/tree/master/TheGame</a></p>
  
  <p>Problem is that I have defined some adjust coordinate functions. They are for when a window is resized and I need to offset all of my coordinates so that my mouse cooridnates are working out the correct collisions and also to scale and yet keep ratio locked for the images I am drawing to the screen.</p>
  
  <p>For example, If I had a screen at 1920 x 1080 and then resized to 1376 x 768, I need to make sure that the bounding boxes for my objects (for when my mouse hovers over them) is adjusted on the mouse coordinates I use to use to check if the mouse was in the bounding box.</p>
  
  <p>I found out that I originally had problems because when I resized my window, directX was automatically scaling everything.. and on top of that, I too was rescaling things, so they would get utterly screwed... I was told by someone that I need to re-declare my screen buffer width and height, which I have done keeping in mind there is a border to my window and also a menu at the top.</p>
  
  <p>Can anyone see why... regardless of doing all this stuff, I am still getting the incorrect results.</p>
  
  <p>If you manage to run my application: Pressing the 1 key will make the resolution 1920 x 1080, pressing the 2 key will make it 1376 x 768. The resize is entirely wrong: <a href="https://github.com/jimmyt1988/TheGame/blob/master/TheGame/D3DGraphics.cpp" rel="nofollow noreferrer">https://github.com/jimmyt1988/TheGame/blob/master/TheGame/D3DGraphics.cpp</a></p>
  
  <pre><code>float D3DGraphics::ResizeByPercentageChangeX( float point )
  {
      float lastScreenWidth = screen.GetOldWindowWidth();
      float currentScreenWidth = screen.GetWindowWidth();
  
  
      if( lastScreenWidth &gt; currentScreenWidth + screen.GetWidthOffsetOfBorder() )
      {
          float percentageMoved = currentScreenWidth / lastScreenWidth;
          point = point * percentageMoved;        
      }
  
  
      return point;
  }
  
  
  float D3DGraphics::ResizeByPercentageChangeY( float point )
  {
      float lastScreenHeight = screen.GetOldWindowHeight();
      float currentScreenHeight = screen.GetWindowHeight();
  
  
      if( lastScreenHeight &gt; currentScreenHeight + screen.GetHeightOffsetOfBorderAndMenu() )
      {
          float percentageMoved = currentScreenHeight / lastScreenHeight;
          point = point * percentageMoved;
      }
  
  
      return point;
  }
  </code></pre>
  
  <p>and yet if you put the return point above this block of code and just do nothing to it, it scales perfectly because of blooming directX regardless of this which is being called correctly (presparams are previously declared in the D3DGraphics construct and a reference held in the class its self:</p>
  
  <pre><code>void D3DGraphics::ResizeSequence()
  {
      presParams.BackBufferWidth = screen.GetWindowWidth() - screen.GetWidthOffsetOfBorder();
      presParams.BackBufferHeight = screen.GetWindowHeight() - screen.GetHeightOffsetOfBorderAndMenu();
      d3dDevice-&gt;Reset( &amp;presParams );
  }
  </code></pre>
  
  <p>This is the problem at hand:</p>
  
  <p><img src="https://i.stack.imgur.com/E0nNS.jpg" alt="enter image description here"></p>
  
  <p>Here is the code that makes this abomination of a rectangle:</p>
  
  <pre><code>void Game::ComposeFrame()
  {
      gfx.DrawRectangle( 50, 50, screen.GetWindowWidth() - screen.GetWidthOffsetOfBorder() - 100, screen.GetWindowHeight() - screen.GetHeightOffsetOfBorderAndMenu() - 100, 255, 0, 0 );
  
  }
  </code></pre>
  
  <p><strong>EDIT::::::::::::::::</strong></p>
  
  <p>I noticed that On MSDN it says:</p>
  
  <blockquote>
    <p>Before calling the IDirect3DDevice9::Reset method for a device, an
    application should release any explicit render targets, depth stencil
    surfaces, additional swap chains, state blocks, and D3DPOOL_DEFAULT
    resources associated with the device.</p>
  </blockquote>
  
  <p>I have now released the vbuffer and reinstantiated it after the presparams and device are reset.</p>
  
  <p><strong>EDIT::::::::::::</strong></p>
  
  <p>I placed an HRESULT on my reset in which I now manage to trigger an error... But, well.. it doesn't really help me! : <a href="https://i.stack.imgur.com/lqQ5K.jpg" rel="nofollow noreferrer">http://i.stack.imgur.com/lqQ5K.jpg</a></p>
  
  <p><img src="https://i.stack.imgur.com/lqQ5K.jpg" alt="enter image description here"></p>