Archived

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

alpha over several textures

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

My sprite-class works perfectly, except for one thing: When I draw two sprites over eachother, the background (any other object than sprites) is drawn on the sprites transparent region. It should be both the background an any sprites behind it. What I am wondering, is if there is a flag I have to set to make D3D include other sprites as the source when doing alpha blending (something like this: SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA)), either set when initializing the engine, or in the sprites Render() function. My D3DXSprite wrapper handles this fine, so I guess there is something missing in my render procedure? Best regards, Perry
Real programmers don''t comment their code, it was hard to write, it should be hard to understand

Share this post


Link to post
Share on other sites
I have a similar problem. Here's my solution:

First, I usually choose D3DBLEND_SRCALPHA for the source blend and D3DBLEND_INVSRCALPHA for the destination blend.

Regardless of the alpha blending states, D3D only blends what you draw with what already has been drawn. So the trick is to draw everything in reverse order. For example, if you have three objects A, B, and C and you know that their order from back to front is B, C, A, then draw them B, C, then A. If A is drawn first, then B and C will not be blended behind A because blending only goes one way.

Another solution is to disable z writes:

SetRenderState(D3DRS_ZWRITEENABLE, FALSE);

If you are only doing 2D, this is the best solution. If you want 3D objects, use choice one.

Hope this helps.



"There are only three types of people in this world: those who can count, and those who can't."

Just3D
Justin Nordin
J Squared Productions
www.jsquaredproductions.com

[edited by - Just3D on March 4, 2003 5:38:06 PM]

Share this post


Link to post
Share on other sites
I first tried re-arranging the sprites, but found that the same problem re-appleared when my camera moved to the other side of the sprites. I guess I''ll write a sorting algorithm later on, but for my demo, this is not worth it.

I then went over to trying out the D3DRS_ZWRITEENABLE state, and this worked perfectly! You indicated that it might not work well in 3D scenes, but I can''t see that anything is wrong. I put it in the Render function of my sprite-class, and set it to false just before I call DrawPrimitive, and re-enable it right afterwards - maybe you have only tried to set it once and for all when initializing?

Other hints/tips on this theme is very much appreciated!



Real programmers don''t comment their code, it was hard to write, it should be hard to understand

Share this post


Link to post
Share on other sites
Glad it worked.

What I meant by not working well was that if you ever needed full 3D objects in your scene and you needed to move the camera, the polygons will not be drawn in the correct order with z writes turned off. But for 2D things, this is generally not a problem.

If you did want to use my aforementioned method 1, you would have to go about coding a manual polygon sort algorithm, but if method 2 works, then there''s no need to worry about it.

Best of luck.



"There are only three types of people in this world: those who can count, and those who can''t."

Just3D
Justin Nordin
J Squared Productions
www.jsquaredproductions.com

Share this post


Link to post
Share on other sites