• Advertisement
Sign in to follow this  

How should I handle different res. and resizing?

This topic is 1799 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

So I here is the initialization of a game:

 

//initialize Direct3D
		this->p_d3d = Direct3DCreate9(D3D_SDK_VERSION);
		if (this->p_d3d == NULL) {
			return 0;
		}
	
		//get system desktop color depth
		D3DDISPLAYMODE dm;
		this->p_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm);
	
		//set configuration options for Direct3D
		D3DPRESENT_PARAMETERS d3dpp;
		ZeroMemory(&d3dpp, sizeof(d3dpp));
		d3dpp.Windowed = (!fullscreen);
		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		d3dpp.EnableAutoDepthStencil = TRUE;
		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
		d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;
		d3dpp.BackBufferFormat = dm.Format;
		d3dpp.BackBufferCount = 1;
		d3dpp.BackBufferWidth = width;
		d3dpp.BackBufferHeight = height;
		d3dpp.hDeviceWindow = p_windowHandle;
	
		//create Direct3D device
		this->p_d3d->CreateDevice(
			D3DADAPTER_DEFAULT,
			D3DDEVTYPE_HAL,
			this->p_windowHandle,
			D3DCREATE_HARDWARE_VERTEXPROCESSING,
			&d3dpp,
			&this->p_device);
	
		if (this->p_device == NULL) return 0;
	
		//clear the backbuffer to black
		this->ClearScene(D3DCOLOR_XRGB(0,0,0));
	
		//create pointer to the back buffer
		this->p_device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &this->p_backbuffer);
	
	    //use ambient lighting and z-buffering
		this->p_device->SetRenderState(D3DRS_ZENABLE, TRUE);
		this->p_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
        this->p_device->SetRenderState(D3DRS_LIGHTING, true);
		this->SetAmbient(this->p_ambientColor);
	
		//initialize 2D renderer
		HRESULT result = D3DXCreateSprite(this->p_device, &this->p_sprite_handler);

 

 

I put the code here just to show that there is no viewport creation,just in case.

My problem is,that when I resize the window,the images get distorted.I tried to think about a solution but I can't find one.

 

Can someone make a suggestion?

Share this post


Link to post
Share on other sites
Advertisement

I have not done really any Direct3D API programming before (mostly XNA) but id assume it be around the fact that you need to change the backbuffer width/height when the form gets re-sized. This means you would need make your game handle resizing in the first place, this could be the resizing of render targets etc... etc...

 

Personally I would only allow the user to resize (change the resolution of the game) in the menu of the game where I wont have to change much where as I would if the main game was running.

Share this post


Link to post
Share on other sites

that's not the problem...i know from the past that the images will still be stretched...

Share this post


Link to post
Share on other sites

They are stretched because the back buffers’ sizes do not match that of the window.  Recreate them when the window is resized, with the correct dimensions.

 

 

L. Spiro

Share this post


Link to post
Share on other sites

When windows sends your app a message such as WM_SIZE you should recreate the back buffer. After it's been resized the back buffer will not be stretched. You can use the following to get the new size from the message pump:

 

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) 
    {
    case WM_SIZE:
    {
        int screenWidth = LOWORD(lParam);
        int screenHeight = HIWORD(lParam);

        // do backbuffer resizing here

        break;
    }
    //... handle any other msgs
    }
}

Share this post


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

  • Advertisement