Interesting Alpha-Blending Issue with DirectX 8

Posted on 2005-04-08
Medium Priority
Last Modified: 2008-02-01

I am writing a product that uses DirectX 8.a and I have reached a standstill.

Here is what I am doing:
I have a scene made by small cubes arranged in a fractal order (pretty random)
in x, y, z coordinates. Firstly I draw these with simple color, no texture, and alfa blending. Then I have a plane made by 2 triangles which I draw using color, texture and alfa blending in front of the scene. The goal is to let the user draw with a "pen" onto the plane, and to let him/her see a change in the scene behind (reordering the cubes). The problem is that I cannot seem to find the correct rendering states to allow both parts to be easily discerned (both are fully colored, but the cubes have a gray background and they are centered in about 2/3 of the scene).

The cubes have a transparency of 0x7f and I tried using several transparencies for the plane with no avail.
Currently, the plane has 0xff transparency on the diffuse color,

Can anyone point me in the right direction? What rendering states and texture stages should I use?

Thank you very much!

Tudor Tihan
Question by:TTDeath
  • 3
  • 2
  • 2
  • +2
LVL 25

Expert Comment

ID: 13740465
I'm afraid that not many of us in the Programming TA know much about this. So, I've creating a pointer to here for you:

Hopefully that will help get you some solutions. :)

Good luck with it. Kind;
LVL 17

Expert Comment

ID: 13743964
If you can get an admin to move this Q, or close it and reopen under DirectX, that'd help...

Author Comment

ID: 13744116
Ok, so lets make it easier to answer.

I need links to online information about renderning states or a reference
to a book that explains them (but has other good directx topics, so
it would pay to buy it).

Other than that, I have managed to find a more or less reasonable answer:
    g_pd3dDevice.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    g_pd3dDevice.SetTextureStageState(0, D3DTSS_ALPHAARG2,  D3DTA_DIFFUSE);
for the plane. But I have no idea what the rules behind these states are. Can anyone
point me in the right direction? (and no, circular explanations a la Microsoft DX SDK are not enough).

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 23

Assisted Solution

gecko_au2003 earned 400 total points
ID: 13744618
MSDN Article :


MVPS article :


An extra article :


My Google search :


hopefully those point you in the correct direction as I saw quite a few things that were in the area you were talking about :)
LVL 23

Expert Comment

ID: 13744636
I found this site which seems pretty useful with regards to the texture setting :)


The next part / URL seems to be in c++ but might point you in the right direction :


At least that is the idea lol
LVL 17

Accepted Solution

davebytes earned 1600 total points
ID: 13745822
Just so you know, I generally like to be explicit, since there's no guarantee you didn't change states earlier.  that is:

    g_pd3dDevice.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    g_pd3dDevice.SetTextureStageState(0, D3DTSS_ALPHAARG1,  D3DTA_TEXTURE);
    g_pd3dDevice.SetTextureStageState(0, D3DTSS_ALPHAARG2,  D3DTA_DIFFUSE);

But, if you aren't using the texture alpha EVER, just do:
    g_pd3dDevice.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
    g_pd3dDevice.SetTextureStageState(0, D3DTSS_ALPHAARG2,  D3DTA_DIFFUSE);

if this isn't clear, it says "multiply the alpha from the texture on the object by the alpha in the vertex diffuse color".  That value is used in blending the pixel color with the frame buffer, depending on your blending state.  The usual blend is src+invsrc, which uses the alpha amount in the above calculation to decide how much of the source color to blend with what amount of the destination (frame buffer) color.  The usual setup is:

    g_pd3dDevice.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    g_pd3dDevice.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    g_pd3dDevice.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

If you have questions, I can probably answer them better as you hit them.  FYI, my reason for wanting this 'moved' is this IS a DirectX question, and I get no directx 'points' for answering here.  Just so you know...

A decent example is #7 on this page:

The MSDN docs actually do a reasonable math explanation of each of the blend functions, but again if you have particular questions, fire away.


Expert Comment

ID: 13748478
Also this might help, although it's in C and not Java.

LVL 17

Expert Comment

ID: 13748782
I should note that I've yet to find one place, aside from MSDN details on the 'equations', that does a good job detailing more than two or three example usages.  If you have particular Qs, I'd be glad to answer them (additive blending, which might be useful in some cases, or texture alpha, or color knockouts, etc...).


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Make the most of your online learning experience.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question