Load texture alpha channel from separate file

Started by
2 comments, last by Martoon 20 years, 1 month ago
I''m currently using D3DXCreateTextureFromFile() to create my textures. However, this doesn''t give me the flexibility to do two things that I need: 1. Load the RGB data from one image file, and load the alpha data from a separate grayscale image file. 2. Create a texture that only loads an alpha channel, so I can render as a solid color, but use the texture''s alpha as a blending factor. I realize I can just load the grayscale texture as RGB and use D3DBLEND_SRCCOLOR instead of D3DBLEND_SRCALPHA, but this wastes a lot of texture memory on the RGB data when all I need is an 8-bit alpha channel. Can someone give me some tips on how to go about doing this? The SDK samples and code snippets in the docs tend to use D3DXCreateTextureFromFile() to demonstrate texture loading. I''m guessing I''ll need to use IDirect3DDevice9::CreateTexture() to create my texture, and D3DXLoadSurfaceFromFile() to load my RGB and alpha separately. I''m just confused as to how I copy the loaded surfaces into the RGB and alpha channels of the texture. Any help appreciated.
Advertisement
Excuse me if my posts seem vague but it has been awhile since i have done this myself as i now have them wrapped up and it is late and i need an aspirin .
But yes you need to manually create the texture with the format along the lines of r8g8b8a8. Then open your texture files manually wether they are bmp or raw etc and then lock the surface of your texture and copy the rgba streams to your texture. Make sure that after you have done this that you unlock it.
If you are using bmp files etc, you will need to find the appropiate code for loading them into memory so that you can extract the actual image data.
I normally just use dds or raw files and remove the hassles of 2 seperate files. Also loadtexturefromfile loves dds files.
If you want to use dds textures simple use the
Directx Texture Tool that comes with the dxsdk to convert your images into dds format.

Cheers, Spectre.

www.opticuslabs.com/alphatexgen

The source is there too. Does exactly what you want. If you have any questions just ask.

~Wave


[edited by - Wavewash on March 21, 2004 2:29:09 PM]
Thanks, guys! Wave, the source for your app looks like it has everything I need.

Interesting side note: The DirectX Texture Tool wouldn''t run on my machine. It said it couldn''t create the D3D device (said this with my desktop set to either 16bit or 32bit). I had to rebuild it with device type set to HAL instead of reference. No idea why I can''t create a reference device on my machine. It''s a Dell laptop with a geForce 4200 go mobile, so it may just be the hardware is kind of funky.

This topic is closed to new replies.

Advertisement