Jump to content
  • Advertisement
Sign in to follow this  

Texture Color Key Doesn't Completely Work? (C++/Direct3D9)

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


I'm using D3DXCreateTextureFromFileEx() to create the texture with a color key of 0xFFFF00FF (pink) (or D3DCOLOR_XRGB(255, 0, 255)) and then using D3DXSprite->Draw() to render it.

What's going on here? I assure you that the only two color values in the image are Pink (255, 0, 255) and White.

I wouldn't normally post on something like this but it's had me stumped for two days and has stopped my progress in my game engine.


Code: (the variables are specified in the parent function)

if (D3DXCreateTextureFromFileEx(m_pGraphics->GetDevice(), // Graphics Device Object
pSrcFile, // Filename
iWidth, // Width Within Image (-1 for Whole Image)
iHeight, // Height Within Image (-1)
D3DX_DEFAULT, // Mip Levels
D3DFMT_A8R8G8B8, /* Format - 32 bit if not already, D3DFMT_UNKNOWN to load from file */
D3DX_FILTER_NONE, // Mip Filter
dwColorKey, // Color Key (255, 0, 255)
&m_ImageInfo, // Image Information (out)
NULL, // Palette (for 256 colors)
&m_pTexture) != S_OK) // Texture object (out)

Share this post

Link to post
Share on other sites
The source image file is a 64x64 .jpg, and I have also tried 24-bit .bmp with no success. The color key isn't stored in any way. As far as I know I just have to call it from the D3DXCreateTextureFromFileEx() function. I have heard of getting alpha values from .tga files and such but if this would work like it used to for me years ago it'd be much easier.

Share this post

Link to post
Share on other sites
I'm an idiot.

I was saving to a low quality .jpg that converted pixels to different colors.

I just slapped myself.

Thanks for reading.


Share this post

Link to post
Share on other sites
You shouldn't be using JPEG for textures at all - JPEG is a lossy format, and the compression it uses becomes very obvious when the image is zoomed or tiled - something that happens to textures most of the time.

I'd recommend PNG or DDS.

Share this post

Link to post
Share on other sites
I switched to PNG, thanks for the tip.

I haven't done any C++ in over a year, but I'm taking a C++ class at the third college I'm going to this semester so I figured I'd present him with a game at the end of the semester for some extra credit and make an A for the first time in my life.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!