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?