• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

Interesting Alpha-Blending Issue with DirectX 8


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
  • 3
  • 2
  • 2
  • +2
2 Solutions
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;
If you can get an admin to move this Q, or close it and reopen under DirectX, that'd help...
TTDeathAuthor Commented:
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).

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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 :)
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
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.

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

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...).

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now