Archived

This topic is now archived and is closed to further replies.

jeanmyr

Problem to copy a texture to another

Recommended Posts

Hi. I want to copy a texture from a source surface to a destination surface. The purpose of my operation is to refresh this texture after a per-pixel access. The source texture is created from a file, and the destination is an empty texture. But I don''t succeed this operation perfectly. A lot of textures are partially copied. For example, the 1024x768 textures are fully copied, but not the 800x600 textures. I still use the Pitch variable from the Lock() function. It is possible this variable must be use with a power of 2 dimention texture for a correct functionning ? So, if someone has a solution... Thanks for all.

Share this post


Link to post
Share on other sites
well I''m not really sure what to answer as I''m not fully aware if you''re talking about textures or bitmaps. I guess your code to show us how you do it would be welcomed here so we could really see where the problem lies. (hopefully it''s short , not a 100 line spaghetti code or noone will take a look at it..)

With best regards,
Mirek Czerwiñski
http://kris.top.pl/~kherin/

Share this post


Link to post
Share on other sites
Ok. this is the problematical routine :

LPDIRECT3DTEXTURE8 Texture;
LPDIRECT3DTEXTURE8 FinalTexture;
int HeightPicture;
int WidthPicture;

void RestorePicture(TEXTFMT TextureFormat)
{
D3DLOCKED_RECT LkRect1;
D3DLOCKED_RECT LkRect2;

if (TextureFormat==RM_16BITS)
{
if (FAILED(FinalTexture->LockRect(0, &LkRect1, NULL, D3DLOCK_NOSYSLOCK)))
return;
if (FAILED(Texture->LockRect(0, &LkRect2, NULL, D3DLOCK_NOSYSLOCK)))
return;

WORD* pData1 = (WORD*)(LkRect1.pBits);
WORD* pData2 = (WORD*)(LkRect2.pBits);

// Copy the ressource texture to final texture - 16Bits version.
memcpy(pData1, pData2, (LkRect2.Pitch)*(HeightPicture/4));

FinalTexture->UnlockRect(0);
Texture->UnlockRect(0);
}
else if (TextureFormat==RM_32BITS)
{
if (FAILED(FinalTexture->LockRect(0, &LkRect1, NULL, D3DLOCK_NOSYSLOCK)))
return;
if (FAILED(Texture->LockRect(0, &LkRect2, NULL, D3DLOCK_NOSYSLOCK)))
return;

DWORD* pData1 = (DWORD*)(LkRect1.pBits);
DWORD* pData2 = (DWORD*)(LkRect2.pBits);

// Copy the ressource texture to final texture - 32Bits version.
memcpy(pData1, pData2, (LkRect2.Pitch)*(HeightPicture));

FinalTexture->UnlockRect(0);
Texture->UnlockRect(0);
}
}

Share this post


Link to post
Share on other sites
you cant have non power of two texture widths or heights. even if you create non power of two texture widths/heights d3d will automagically create a proper sized texture (not gauranteed so its better to do things correctly). since the texture you get back is actually bigger then you requested your drawing code is not drawing it properly (most likly). remeber 1.0 in the texture coordinate space is the furthest right portion of the texture that is ALLOCATED not what you request. so be a good lad and check the texture size you get back form d3d. then use YourTexWidth/RealWidth as the farthest u coordinate. same goes for the height (except you use height instead of width for those who are completly lost).

Share this post


Link to post
Share on other sites