Jump to content
  • Advertisement
Sign in to follow this  

Horizontal Tearing problem with DirectX 9 2D

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

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;
LPDIRECT3DSURFACE9 newbackbuffer;
LPD3DXSPRITE new_sprite_handler;

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

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

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,

Share this post

Link to post
Share on other sites
You need to enable VSync in order to prevent tearing:
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!