Sign in to follow this  
MartinSmith160

Horizontal Tearing problem with DirectX 9 2D

Recommended Posts

Hi Guys

Im having a strange problem that I would appreciate some help with. I have wrote a simple 2D DirectX 9 GameEngine and all is up and running. There is one problem with it though. When I move a sprite around the window tearing occurs frequently. Its like one half of the sprite is drawn in the old coordinates and the rest in the new position.

I thought this was simple a double buffering issue but I have already set up double buffering to work. Here is the code for setting up the device and the back buffer.

[source lang="cpp"]D3DDISPLAYMODE dm;
LPDIRECT3DDEVICE9 newDevice;
LPDIRECT3DSURFACE9 newbackbuffer;
LPD3DXSPRITE new_sprite_handler;

this->d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm);

//set configuration options for Direct3D
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = !targetWindow->IsFullScreen();
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 = clientWindowRect.right;
d3dpp.BackBufferHeight = clientWindowRect.bottom;
d3dpp.hDeviceWindow = targetWindow->GetHWND();

//create Direct3D device
this->d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
targetWindow->GetHWND(),
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp,
&newDevice);


newDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0);


if(newDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &newbackbuffer) != D3D_OK)
st_engine->LogError("BackBuffer Failed to create");[/source]

Is there anything im missing here. I tried changing the backbuffer count down to 0 so it should be single buffered and it looks the same. That implies to me that even tho im saying use double buffering its not. Any help on this would be greatly appreciated.

Thanks in advance,
Martin.

Share this post


Link to post
Share on other sites
Hi Overdrive, thanks for the response.

I changed the d3dpp.PresentationInterval to D3DPRESENT_INTERVAL_ONE and it solved the tearing. It did however make the movement look slightly jerky. Strange. The frame rate didnt seem to drop so im not sure what this could be. Ill look into it.

Thanks for the help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this