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


LockRect errors (D3D9)

Recommended Posts

So you''re using D3D then?

If so, by far the most usual way of doing this is to use a texture format with an alpha channel. Any areas you want to be totally transparent have an alpha value of 0, and areas you want to be opaque have an alpha value of 1 (i.e. 255 with an 8bit alpha channel, 15 with a 4bit alpha channel etc).

You can use alpha test to accept/reject pixels based on the value in the alpha channel. Alpha blending doesn''t need to be enabled for alpha test either.

Most of the methods of making the above work based on an RGB colour value would still involve getting the pixels of that colour into the alpha channel. The easiest would be to do this when you load the surface/texture, the D3DX texture loading functions already have a "colour key" value and it''ll do this work for you. Alternatively you could use the pixel pipeline to convert the colour at runtime (for example using a pixel shader to set alpha to 0 when the pixel is a certain colour or 1 when it''s not).

Simon O''Connor
ex -Creative Asylum
Programmer &
Microsoft MVP

Share this post

Link to post
Share on other sites

D3DXCreateTextureFromFileEx(g_pD3DDevice, "mouseMap.bmp", D3DX_DEFAULT,
D3DCOLOR_XRGB(0,0,0), NULL, NULL, &pTex);

DWORD pixel;
DWORD Offset;
int i, j;
pTex->LockRect(0, &info,NULL,D3DLOCK_READONLY);
for(i=0; i<64; i++){
for(j=0; j<32; j++){
Offset = (j * info.Pitch) + (i*2);
pixel = *(DWORD *)((DWORD)(info.pBits) + Offset);
outFile< }

When I run the above code, my program crashes once I call pTex->LockRect(...)

Share this post

Link to post
Share on other sites
I changed it to managed and it still didn't work.

Also, I do have the debug runtime (I believe). How do I set it up to tell me these things?

[edited by - Sfpiano on July 5, 2003 7:16:54 PM]

Share this post

Link to post
Share on other sites