Jump to content

  • Log In with Google      Sign In   
  • Create Account

Horizontal Tearing problem with DirectX 9 2D


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
2 replies to this topic

#1 MartinSmith160   Members   -  Reputation: 146

Like
1Likes
Like

Posted 18 September 2012 - 01:33 AM

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.

Sponsor:

#2 Overdrive   Members   -  Reputation: 187

Like
2Likes
Like

Posted 18 September 2012 - 03:53 AM

You need to enable VSync in order to prevent tearing:
Replace:
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
With:
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

#3 MartinSmith160   Members   -  Reputation: 146

Like
0Likes
Like

Posted 18 September 2012 - 06:26 AM

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.




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