Skip to main content
gamedev.net
🔒 Locked

Sprite Rendering Problem

Started by Panax Jan 2, 2003 at 11:49 PM 7 replies 700+ views
Original Post
Panax
Panax
When I render my sprites the color I tell not to show up doesnt except for a small border around the sprite. Ive checked in my paint programs and the colors surrounding the sprite itself are exactly the same color as anyother of the colors I want to be invisible... any ideas as to what is happening? I am using the ID3DXSprite interface for my rendering... Thanks in advance!
Panax
Panax
Yeah Im running XP Pro... I havent tested it on any other OS
Roof Top Pew Wee
Roof Top Pew Wee
If you're having the problem I think you are, I've tackled this over and over.

There can be 2 problems. You can get a line on the border of the quad, or you can get a black outline around the sprite. I believe this is due to D3D blending the bitmap. I have found no way to get around this. I have tried setting D3DTSS_MAGFILTER and D3DTSS_MINFILTER to every value, and no go. I see a few posts like this every oncew in a while, and no one ever seems to post a solution that works

If the outline is lines around the sprite, then you can increase the width and height by one pixel on the top, bottom, left and right, so that you have a black border around your sprite. this should eliminate all line borders around the sprite.

As for the black outline of the sprite, I have no clue.

Sorry,

--Vic--

[edited by - Roof Top Pew Wee on January 3, 2003 3:22:30 AM]
Panax
Panax
Sorry forgot to tag the source


  
HRESULT CSprite::Load(const char* FileName, int nWidth, int nHeight, int nNumFrames)
{
Log.WriteInfo("Loading Sprite: %s", FileName);

HRESULT hResult;

// Release anything prev allocated

SafeRelease(m_pSpriteTex);

D3DXIMAGE_INFO info;
hResult = D3DXCreateTextureFromFileEx(m_pDevice, // D3D Device

FileName, // File Name

276,//D3DX_DEFAULT, // Width: Take From File

128,//D3DX_DEFAULT, // Height: Take From File

1, // Mip Levels

0, // Render Target?

D3DFMT_A8R8G8B8, // 32-bit with Alpha

D3DPOOL_MANAGED, // D3D Manages Memory

D3DX_DEFAULT, // Filter: Default Filtering

D3DX_DEFAULT, // Mip Filter

m_ColorKey, // Color Key (NOTE Alpha Value)

&info, // Extra Info

NULL, // Pallette

&m_pSpriteTex); // Texture


if( FAILED(hResult) )
{
Log.WriteError("Failed to load sprite: %s.", FileName);
return hResult;
}

D3DSURFACE_DESC desc;
m_pSpriteTex->GetLevelDesc(0, &desc);
m_nTexWidth = desc.Width;
m_nTexHeight = desc.Height;

// Calculate scale for 1:1 rendering

m_Scaling.x = ((float)info.Width / desc.Width);
m_Scaling.y = ((float)info.Height / desc.Height);

m_nSpriteWidth = (int)(nWidth / m_Scaling.x);
m_nSpriteHeight = (int)(nHeight / m_Scaling.y);
m_nNumFrames = nNumFrames - 1;

m_Scaling.x *= m_nScale;
m_Scaling.y *= m_nScale;

//

// Init Active Surface

//

hResult = D3DXCreateTexture(m_pDevice,
nWidth,
nHeight,
1,
0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
&m_pActiveTex);

if( FAILED(hResult) )
{
Log.WriteError("\tFailed to init active surface.");
return E_FAIL;
}


//

// Create ID3DXSPRITE

//

hResult = D3DXCreateSprite(m_pDevice, &m_pSprite);
if( FAILED(hResult) )
{
Log.WriteError("\tFailed to Create ID3DXSPRITE.");
return E_FAIL;
}

m_bInitialized = true;

SetActiveFrame(0);

Log.WriteInfo("Sprite Loaded Successfully.");

return S_OK;
}


[edited by - Panax on January 3, 2003 3:06:00 PM]
Slickmantincan
Slickmantincan
I notice this happens with DX7 DirectDraw as well. If I resize the sprite I see the pink around the sprite that should be transparent.
Pseudo
Pseudo
hehehe, I loving seeing people have the same problems I''ve had. kinda makes me feel warm and fuzzy all over.

Anyways, the problem is infact because the texture is stretched to a power of 2 size (512), and in doing so, is resampled at the new size. This means that some pixels in the larger image, are inbetween pixels on the original image, and are averaged to make a final pixel. if they are inbetween an opaque and a transparent pixel, it will still get averaged and that is the outline you see. For example if your transp. color is magenta, then when its resampled, it might be slightly darker than magenta, so the color key''ing wont make it transparent (and shouldnt) thus you see a border.

here''s how to fix it:
1) Manually load the graphics and make sure you take this into consideration when you resample.

or

2) Make sure your graphics are already in power of 2 sizes so they aren''t resampled

or

3) Setup a color key range, so even the border colors are transparent (this doesn''t work perfectly)


Hope this helps.
Panax
Panax
Ok I managed to fix my problem.. thanks for all the help!

Here is the source for the Load funtion (that works this time).. below I will describe what has changed.


  
HRESULT CSprite::Load(const char* FileName, int nWidth, int nHeight, int nNumFrames)
{
Log.WriteInfo("Loading Sprite: %s", FileName);

HRESULT hResult;

// Release anything prev allocated

SafeRelease(m_pSpriteTex);

D3DXIMAGE_INFO info;
hResult = D3DXCreateTextureFromFileEx(m_pDevice, // D3D Device

FileName, // File Name

D3DX_DEFAULT, // Width: Take From File

D3DX_DEFAULT, // Height: Take From File

1, // Mip Levels

0, // Render Target?

D3DFMT_A8R8G8B8, // 32-bit with Alpha

D3DPOOL_MANAGED, // D3D Manages Memory

D3DX_FILTER_NONE,// Filter: No Filtering

D3DX_FILTER_NONE,// Mip Filter

m_ColorKey, // Color Key (NOTE Alpha Value)

&info, // Extra Info

NULL, // Pallette

&m_pSpriteTex); // Texture


if( FAILED(hResult) )
{
Log.WriteError("Failed to load sprite: %s.", FileName);
return hResult;
}

D3DSURFACE_DESC desc;
m_pSpriteTex->GetLevelDesc(0, &desc);
m_nTexWidth = desc.Width;
m_nTexHeight = desc.Height;

// Calculate scale for 1:1 rendering

m_Scaling.x = ((float)info.Width / desc.Width);
m_Scaling.y = ((float)info.Height / desc.Height);

m_nSpriteWidth = nWidth;
m_nSpriteHeight = nHeight;
m_nNumFrames = nNumFrames - 1;

m_Scaling.x *= m_nScale;
m_Scaling.y *= m_nScale;

//

// Init Active Surface

//

hResult = D3DXCreateTexture(m_pDevice,
nWidth,
nHeight,
1,
0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
&m_pActiveTex);

if( FAILED(hResult) )
{
Log.WriteError("\tFailed to init active surface.");
return E_FAIL;
}


//

// Create ID3DXSPRITE

//

hResult = D3DXCreateSprite(m_pDevice, &m_pSprite);
if( FAILED(hResult) )
{
Log.WriteError("\tFailed to Create ID3DXSPRITE.");
return E_FAIL;
}

m_bInitialized = true;

SetActiveFrame(0);

Log.WriteInfo("Sprite Loaded Successfully.");

return S_OK;
}


Ok what I had to change was the filters... instead of using the default filters (which was what was causing my problem) I had to specify that I did not want it to filter.

And tada no more borders on my sprites!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.