Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Another LockRect question.

KMHPKMHP Member Posts: 2
Hello just a little FYI this problem actually spurred me to register just so I could ask this question. I've read the other LockRect posting and this problem is different I assure you. Ok, so the problem is that I'm trying to use LockRect to figure out the exact dimensions of an item contained on a texture. Specifically in application to making a bitmap font with near exact kerning.

So here it goes, I call LockRect to collect information at such and such location on the texture. Run through the pixels and determine the extremes width wise. The texture resource is in the managed pool not default so LockRect does succeed, well sort of, it reads in the whole texture. I tested the bitmap by placing a red pixel at index 64,0. If the RECT passed in as the third parameter is {0,0,64,64} it should not see that blasted red pixel. Long story short, it does. So I loaded a larger texture and performed the same deal only placing a red pixel much further down. It still ignores the third parameter.

Do I have a misunderstanding of what the third parameter of LockRect accomplishes? Why does it read in the whole texture? I'm lost so any help would be appreciated and I apologize for being verbose if you hated reading my problem. :)

concise code:
[size=2][color=Green]RECT tLocation; // The location on the texture where I want to be looking.
D3DLOCKED_RECT tSearch; // The information captured from the texture at tLocation.

int nX = 0, nY = 0, nWidth = tSize.x, nHeight = tSize.y; // tSize = 64,64
while ( true )
SetRect( &tLocation, nX, nY, nX + nWidth, nY + nHeight ); // Reset Location.
if ( FAILED( tSprite.d3dTexture->LockRect( 0, &tSearch, &tLocation, D3DLOCK_READONLY ) ) )
ERRBOX( "Failed to LockRect" );
DWORD* Texels = (DWORD*)tSearch.pBits; // Should only be 4096 texels?
tSprite.d3dTexture->UnlockRect( 0 );

Actually in thinking about this I have a few more questions. First is pitch taken into account when capturing a specific RECT of the texture? Or does it become a simple array of exact pixel measurements?

Attempted Workaround: ( FAILED )
I created an offscreen surface to copy to from the texture. Succeeded at that but still had the same problem with it pooling the entire surface instead of a specified rectangle.
Sign In or Register to comment.