Archived

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

textures ??

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

i have one file with a lot of textures for different sprites. one of mine function looks in this file how many sprites there are and which are the coordinates. i store this in a array of RECT. For d3dxsprite::draw method i must load the right piece of texture in an otherone, where only the texture for this sprite is in. therefor i create a new texture. but the size must be a power of 2. but the sprite isn''t. what a holy ... ! so i thought i use the next bigger possible size. the result: i get an exeption while memcpy. i know the reason and i think it''s logical. but i think there must be an other way to do this, as filling the rest of the texture with unused values. take a look and you will understand my problem and what i want to do. perhaps there is an other, proper way. so please help. HRESULT CSprite::Render( int SpriteNum ) { HRESULT Failure; LPDIRECT3DTEXTURE8 pSpriteTexture; D3DLOCKED_RECT LkRect1; D3DLOCKED_RECT LkRect2; if(!bInitialized) return E_FAIL; Failure = pTexture->LockRect( 0, &LkRect1, &( SpritesCoordinates[ SpriteNum ] ), D3DLOCK_NOSYSLOCK ); Failure = g_pd3dDevice->CreateTexture( Rect.right-Rect.left, Rect.top-Rect.bottom, 0, NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pSpriteTexture ); Failure = pSpriteTexture->LockRect( 0, &LkRect2, NULL , D3DLOCK_NOSYSLOCK ); // Kopieren der Pixel WORD* pData1 = ( WORD* )( LkRect1.pBits ); WORD* pData2 = ( WORD* )( LkRect2.pBits ); memcpy( pData1, pData2, width * height * BYTESPERPIXEL ); Failure = pTexture->UnlockRect( 0 ); Failure = pSpriteTexture->UnlockRect( 0 ); pSprite->Begin(); Failure = pSprite->Draw(pSpriteTexture, NULL, &Scaling, &RotCenter, Rotation, &Translation, ModulateColor); pSprite->End(); return S_OK; }

Share this post


Link to post
Share on other sites
I'm probably not understanding your problem correctly, but why do you need to copy the texture? The D3DXSprite->Draw method has a parameter for you to tell it where in the source texture to get its information. Instead of:

Failure = pSprite->Draw(pSpriteTexture,
NULL,
&Scaling,
&RotCenter,
Rotation,
&Translation,
ModulateColor);

How about:

Failure = pSprite->Draw(pSpriteTexture,
&SourceRect, //This is the source rectangle of the sprite
&Scaling,
&RotCenter,
Rotation,
&Translation,
ModulateColor);

If you have got an array of RECT, then just pass the correct RECT in, and it should only display that part of the source texture. Then you won't have to copy textures.

Also, what are you doing with the value of "Failure". As far as I can see, you set it, but don't test it.

Sorry if I haven't understood,
John B

Edited by - JohnBSmall on February 19, 2002 1:55:04 PM

Share this post


Link to post
Share on other sites