Sign in to follow this  
Sync Views

Direct3D colour key

Recommended Posts

How can I set the colour key to be always the bottom left pixel of the image? Is there away to find out what the bottom left pixel is before loading the image or setting the colour key after loading rather than on load?
IDirect3DTexture9 *load_texture(char *path)
{
  IDirect3DTexture9 *texture;
  D3DXIMAGE_INFO scr_info;

  //Use a magenta colourkey
  D3DCOLOR colourkey = 0xFFFF00FF;

  // Load image from file
  if (FAILED(D3DXCreateTextureFromFileEx (d3d_device, path, 0, 0, 1, 0, 
        D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 
        colourkey, &scr_info, NULL, &texture)))
	    return NULL;

  //Return the newly made texture
  return texture;
}

Share this post


Link to post
Share on other sites
0) Pretty much everyone handles this by just picking a standard colour-key colour.
1) Why bottom-left?
2) It depends on the file format and how much of the work you intend to do yourself. I don't think you can "re-key" an already-loaded image, but I haven't actually worked with DirectX directly, so I don't really know.
3) Returning NULL for a failed texture load might not be such a good idea. You might want instead to return a pointer to some shared, easily recognizable "dummy" texture (or perhaps, a recognizable one while debugging, and a fully transparent one for release). This avoids lots of debugging hell when you forget to check for NULL return values, and lots of extra work when you remember. ;) See also.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this