Alpha transparency in algorithm-generated textures

Started by
6 comments, last by FlyingWren 21 years, 8 months ago
When I call "D3DXCreateTextureFromFileEx," source-pixel image transparency (via color-keying) works fine. However, I need to generate a few textures in memory algorithmically. To do this, I've been using the following function call: ------------------------------- D3DXCreateTexture(DXG.pID3D_Device, texture_width, texture_height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pID3D_Texture)) ------------------------------- i then do a: ----------------------------------------------- ID3D_Texture->GetSurfaceLevel(0, &pID3D_Surface) ------------------------------------------------ ...to get a pointer to the texture's top surface (I don't need mipmaps). I can draw whatever I like on it, and it displays fine, but the only thing is that whatever I set the alpha of any given pixel to, it gets drawn regardless!! All I need is for some texels to be not drawn when I call my ID3DXSprite->Draw function. How do I get it to stop ignoring what I set the alpha to? Does my call that creates the texture not give the texture an alpha channel or something? please help if possible :[[[ [Edit: I should add that I'm getting no failures on any DirectX API calls... sniffle] [edited by - FlyingWren on August 15, 2002 6:40:48 PM]
Advertisement
sorry... had to bump this since it got scrolled off.

If anyone knows how to do this, I would sure appreciate any help... this is a project that''s on a deadline at my work and I''m getting worried :-x
Did you make sure to set your texture and render states?
Yes, though I don''t know if they''re quite right or not. Here''s what I do:


-------------------------------
// turn off lighting effects
pID3D_Device->SetRenderState(D3DRS_LIGHTING, FALSE);

pID3D_Device->SetTextureStageState (0, D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);

pID3D_Device->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

pID3D_Device->SetRenderState (D3DRS_ALPHABLENDENABLE,TRUE);
pID3D_Device->SetRenderState (D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
pID3D_Device->SetRenderState (D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
-----------------------------------------

...minus the error-checking. Is that correct? That''s what I read to do on some various webpages.

What''s even weirder is that the alpha stuff is not working on a Matrox Parhelia, but works fine on a Matrox G400. Help...? :[
Try checking the returned texture format on the machine with the Parhelia. See if its still D3DFMT_A8R8G8B8.
also you should be using lockrect/unlock or similar to lock the texture data and not getting the texture level. its more efficent and less error prone.

though it seems to me some renderstate is wrong. possible the alphaop is wrong (should be modulate).
also you should be using lockrect/unlock or similar to lock the texture data and not getting the texture level. its more efficent and less error prone. possible the Parhelia drivers are finiky about doing things this way since its technically the "wrong" way to change a texture. also look into the docs on dynamic textures. possible you need to call a function (forgot its name) to let d3d know the copy was updated. lockrect()/unlock() will handle this for you (ie you use them on the actual texture object and never get the surface object since you dont need to). the method you use will not thus some drivers automagically handle other do not.

please see the d3d samples on dynamic txtures. i know you are not changing the textures every frame, but you still should do it correctly even if its only done once at start.
hello

u want to set a color key type a thing with a texture thats created in memory right? and u wanna set the alpha valuse of the texels to transparent. well the directX sdk comes with a few helper classes as im sure u know. theres one .cpp called "d3dutil.h" and it has a function called

HRESULT D3DUtil_SetColorKey( LPDIRECT3DTEXTURE8 pTexture, DWORD dwColorKey );

this conveniently takes in ur texture and the color that u want to make transparent and handles the work for u..

goodbye




Al
**MY HQ**
[size=2]aliak.net

This topic is closed to new replies.

Advertisement