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


Newbie Alpha Layer Question

Recommended Posts

Hi Gang, This is a stupid newbie question, and I'm ashamed to ask it... but I've been fiddling with alpha layers for a day now, and I don't even know what I'm doing wrong. This is a real stinker, because I've written my OWN alpha routines many a time... but I just can't figure out what DirectX wants from me! Help! Here's the premise. I have this glare texture. All I want to do is drop it on the screen in 2d-- just a texture with translated/lit vertices. It's essentially a sprite, drawn with d3d. No rotation, nuthin'. BUT... I want the glare texture to be variably transparent. That is to say, fully opaque in the middle, but fading at the edges. I tried to attach an alpha surface to the texture, in the hopes that by setting alpha blend mode it would all take care of itself. But I don't even get that far! It won't let me initialize an alpha layer at all. I just make a surface, give it DDSD_ALPHABITDEPTH, set the dwAlphaBitDepth variable to 8 (and I've tried 16, too, since I'm in 16 color more) and DDSCAPS_ALPHA in the caps variable. And when I run through it, directx gives me the incredibly specific error message that one of my parameters is incorrect. Well, I spent a WHOLE DAY tweaking parameters... back and forth, this and that, and I never get anything but incorrect parameters. So: First... is this premise correct? Make a texture, attach an alpha layer, and then draw it with SRCBLEND? This WILL give me what I want, right? A texture with transparency set up depending on the value in the alpha layer (I wasn't able to turn up much in the SDK about this-- probably looking in the wrong place, but the SDK is soooo poorly organize). Second... HOW DO I INITIALIZE THAT ALPHA LAYER????? I figured I could initialize it like a Z buffer, and attach it, but like I said... invalid params... invalid params... invalid params (weep). Anyone? Anyone? Witchlord? Thanks in advance for your help! -- Goodlife P.S. Please forego any references to d3dx, etc. I wrote my own direct3d wrapper some time ago, and am looking to modify it-- not switch over to a whole new system. I understand that d3dx is easier, kinder, gentler, etc, but so is my wrapper, and when something goes wrong with my wrapper, I can figure out what the problem is, instead of trying random numbers for a half hour until things work. So please-- no d3dx or helper functions. I want to do this the manly way. Edited by - goodlife on 6/14/00 9:04:40 AM

Share this post

Link to post
Share on other sites
You just need an alpha channel in the texture itself. Not a seperate surface for alpha.

So pick a textureFormat that contains alpha info.

Jaap Suter

Mmmm, I''ll have to think of one.

Share this post

Link to post
Share on other sites
Mr. S9801758,
Do I do that by creating the surface? As far as I know, I have never picked a texture format at all. I just make a directx surface, and say DDSCAPS_TEXTURE, and boom, it''s a texture.

What is necessary to put an alpha channel on it?

Share this post

Link to post
Share on other sites
To get a texture with an alpha channel you need to have
enumerated the texture formats available to you for that
Direct3D Device. Generally searching for a texture
with the DDPF_ALPHAPIXELS flag set.

But it''s not just as simple as that since you still need
to fill the texture surface with the appropriate information
in the correct place.

Generally there exists 3 texture formats with alpha channels

1555 - 16 bit with a 1 bit alpha & 5 bit per colour
4444 - 16 bit with 4 bit for alpha & per colour
8888 - 32 bit with 8 bit for alpha & per colour

Most of the time the 1555 and 4444 will have MSB (either
bit 15 or bit''s 15->12) as the alpha component.

The best way to get these filled out is to create your texture
using the approprate tools with an alpha component in it
and convert it at run time to the correct depth.

Damn it .. just had an idea for another tutorial now !

Will have to start doing them .. sheesh...


Share this post

Link to post
Share on other sites