Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

Direct3D colour key

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

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, 
        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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!