Jump to content

  • Log In with Google      Sign In   
  • Create Account


How should I handle different res. and resizing?


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 noatom   Members   -  Reputation: 769

Like
0Likes
Like

Posted 15 February 2013 - 03:49 PM

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?



Sponsor:

#2 Xanather   Members   -  Reputation: 703

Like
0Likes
Like

Posted 15 February 2013 - 10:15 PM

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.



#3 L. Spiro   Crossbones+   -  Reputation: 12329

Like
1Likes
Like

Posted 15 February 2013 - 10:17 PM

When the window gets resized (or full-screened) you have to recreate the backbuffers.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#4 noatom   Members   -  Reputation: 769

Like
-1Likes
Like

Posted 16 February 2013 - 01:46 AM

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



#5 L. Spiro   Crossbones+   -  Reputation: 12329

Like
1Likes
Like

Posted 16 February 2013 - 02:07 AM

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#6 Nyssa   Members   -  Reputation: 426

Like
0Likes
Like

Posted 16 February 2013 - 08:56 PM

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
    }
}





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