Problem accessing the pixels of a texture

Hello!
I'm currently writing a bitmap font renderer and for that I need to access the individual pixels of a texture that contains all the characters that make up the font so I can calculate the kerning values. I've got this working, but I'm having some issues with accessing the pixels.

My texture is a 170x170 pixel DDS file (the issue is reproducable with a TGA as well) which I have loaded into memory. I create it like this:

D3DXCreateTextureFromFileInMemoryEx(lpDevice, pResource->pData, pResource->ulSize, D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0xFFFF00FF, &d3dImageInfo, NULL, &pTexture);

If I load my texture as described above, then lock it and loop over its width and height and set every pixel to, let's say 0xFFFF0000, it actually only does that for a rectangle that is roughly 100x100 pixels in size. If I change my texture creation code to this however:

D3DXCreateTextureFromFileInMemoryEx(lpDevice, pResource->pData,

pResource->ulSize, 170, 170, 1, 0, D3DFMT_UNKNOWN,

D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0xFFFF00FF,

&d3dImageInfo, NULL, &pTexture);

meaning if I specify the width and height of the texture, it actually fills the entire texture and my kerning measurement code works nicely.

I'm completely out of ideas and any help is much appreciated. I can't specify the width and height manually, because I want to keep my code as generic as possible.

Thanks a lot in advance.

[1517 byte] By [HarryHunt] at [2007-12-23]
# 1

Passing D3DX_DEFAULT as the size to one of the D3DX texture loading functions causes it to resize the texture to size that is a power of two. Most video cards require textures to have dimensions that are a power of two, unless the texture is used in certain restricted contexts. You can use D3DXGetImageInfoFromFileInMemory() to find the dimensions of your file and use those sizes when loading your texture. A better idea would be to use a DDS/TGA file with power of two dimensions.

Is there any reason why you're loading a memory image into a texture to do your kerning pair calculations, instead of just using the memory image directly? This probably isn't something you want to be doing at load time in your application.

RossRidge at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...
# 2
Thank you so much! You nailed it!
The reason why I load the image into a texture is because I need the texture for the actual drawing of the characters anyway, so I figured I might as well use the texture to calculate the kerning values.

Thanks again!

HarryHunt at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...