Jump to content
  • Advertisement
Sign in to follow this  
RobertJamesDennington

D3DXSprite produces strange colours during movement

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

Hello

I am building an RPG engine in C++ which makes use of D3DXSprite to draw 16x16 tiles from a tilesheet. In order to prevent the need for looping through the map tiles and drawing them individually every frame, the map loading function creates a new texture and draws the map tiles onto it. The larger texture is then drawn each frame.

Unfortunately, I have this annoying bug. Whenever these large map textures are moving they become slightly blurry, which gives a 'pulsing' effect. I can barely see it on my own monitor, but on my brother's computer it's really noticeable and detracts from the experience of the game a LOT. The sprites are pixel art which should therefore be pixel-perfect, and while it looks fine when the frames are still, the motion blur is quite irritating.

If I hit 'print-screen' then the colours flash back to normal as the screenshot is taken, and then return to their incorrect state on the following frame, so it is impossible for me to screenshot.

I'm pretty new at DirectX having only been working with it for a couple of months, so I am completely clueless here. Does anyone have any idea what I'm doing wrong? (I have been Googling around for a while, and found various different topics talking about texture filtering and such, but whatever I tried failed).

Thanks in advance for your help.

[spoiler]
Here are some of the functions I am using as they currently stand, in case you can see something I've done wrong.

bool MapManager::createMapTexture(wstring MAPID)
{
if(mapofmaps[MAPID].complete)
{
if(!appsys.sprites.customspr[L"map-below-"+MAPID].loaded)
{
LPDIRECT3DSURFACE9 pRenderSurface = NULL, pBackBuffer = NULL;
appsys.display.device->CreateTexture(mapofmaps[MAPID].width*16,mapofmaps[MAPID].height*16,1,D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &appsys.sprites.customspr[L"map-below-"+MAPID].texture, NULL);
appsys.sprites.customspr[L"map-below-"+MAPID].texture->GetSurfaceLevel(0, &pRenderSurface);
appsys.display.device->GetRenderTarget(0,&pBackBuffer);
appsys.display.device->SetRenderTarget(0,pRenderSurface);

appsys.display.device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0,0,0,0), 1.0f, 0);

appsys.display.device->BeginScene();
appsys.display.device->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );

appsys.display.sprite->Begin(D3DXSPRITE_ALPHABLEND);

for(int i=0; i< mapofmaps[MAPID].height; i++)
{
for(int j=0; j < mapofmaps[MAPID].width; j++)
{
int dest_tilenum = i*mapofmaps[MAPID].width + j;
appsys.sprites.drawTile((EnumSprites)(SPRITE_CRMAP_TILES_BEGIN+mapofmaps[MAPID].tiles[dest_tilenum].bottom.tileset), mapofmaps[MAPID].tiles[dest_tilenum].bottom.h, mapofmaps[MAPID].tiles[dest_tilenum].bottom.v, j*16, i*16);
}
}

appsys.display.sprite->End();
appsys.display.device->EndScene();

appsys.display.device->SetRenderTarget(0,pBackBuffer);
pRenderSurface->Release();
pBackBuffer->Release();
appsys.sprites.customspr[L"map-below-"+MAPID].loaded = true;
}


void SpriteManager::load(EnumSprites EnumNam)
{
if(sprites[EnumNam].texture == NULL)
{
sprites[EnumNam].info = new D3DXIMAGE_INFO();
D3DXCreateTextureFromFileEx(appsys.display.device, sprites[EnumNam].path, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, NULL, sprites[EnumNam].info, NULL, &(sprites[EnumNam].texture));
sprites[EnumNam].loaded = true;
}
}
void SpriteManager::drawCustom(wstring Tag, float x, float y)
{
if(customspr[Tag].loaded)
{
appsys.display.sprite->Draw(customspr[Tag].texture, NULL, &D3DXVECTOR3(customspr[Tag].originX,customspr[Tag].originY,0), &D3DXVECTOR3(x,y,0.1f), 0xFFFFFFFF);
}
}

void SpriteManager::drawTile(EnumSprites EnumNam, UINT tileH, UINT tileV, float x, float y, bool customOrigin, float originX, float originY)
{
load(EnumNam);
if(sprites[EnumNam].tiles.is_tileset)
{
if((tileH <= sprites[EnumNam].tiles.countHorz) && (tileV <= sprites[EnumNam].tiles.countVert))
{
if(!customOrigin)
{
originX = sprites[EnumNam].originX;
originY = sprites[EnumNam].originY;
}
RECT temp = {tileH*sprites[EnumNam].tiles.sizeHorz, tileV*sprites[EnumNam].tiles.sizeVert, (tileH+1)*sprites[EnumNam].tiles.sizeHorz, (tileV+1)*sprites[EnumNam].tiles.sizeVert};
appsys.display.sprite->Draw(sprites[EnumNam].texture, &temp, &D3DXVECTOR3(originX,originY,0), &D3DXVECTOR3(x,y,0.1f), 0xFFFFFFFF);
}
}
}

void DisplayManager::Draw()
{
HRESULT hr = device->TestCooperativeLevel();

if(hr == D3DERR_DEVICELOST)
{
Sleep(500);
beginReset();
}
else if(hr == D3DERR_DEVICENOTRESET)
{
//Lost but we can reset it now
device->Reset(&param);
endReset();
}
else
{
device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, colours[ECOL_C_TYPE_DARK], 1.0f, 0);
device->BeginScene();
device->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);

sprite->Begin(D3DXSPRITE_ALPHABLEND);
appsys.states.getCurrentState()->Draw();
sprite->End();

device->EndScene();
device->Present(NULL,NULL,NULL,NULL);
}
}

[/spoiler]

Share this post


Link to post
Share on other sites
Advertisement
Hi Tinytimrob i too had the same problem. I think removing D3DCLEAR_ZBUFFER from the line appsys.display.device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0,0,0,0), 1.0f, 0);may help you.:)

Share this post


Link to post
Share on other sites
Cheap LCD panels can have artifacts when images are moving with high framerates and high contrast because they are made for movies with lower framerates.

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!