> I have as part of an application a circular dial, behind which is
> part of a bitmap. At least thats the impression intended to be
> the user. In actual fact there is a dashboard background over which I
> to overlay this circular portion of the bitmap.
> My first idea is to have a texture with a circular part which has
> outside the circle, alpha 0 inside, and to multi-texture this with the
> bitmap. Is there any other way to do this without multi texturing? (I
> PS is another way).
Well, my first inclination would be to render the dial to a quad first,
with z-write enable off, then draw the dashboard overtop of it with a
cutout in the alpha channel. Of course, this would mean alpha blending
the entire dashboard (or at least the area of the dial if you broke that
into a separate render), though if you just wanted a hard cutout (pixels
either fully opaque or transparent, no in between) you could use alpha
testing without blending. The other shortcoming here would be that if
you had multiple dials you could not place them any closer than their
diagonal dimensions would allow, or their quads would overlap while they
rotate (I'm assuming you are rotating the dial behind that cutout?)
Drawing the dials after the dash could be done with a single texture,
containing an alpha channel mask, but with two texture stages. Actually
it could be done with one texture stage, however as the mask rotates you
would likely see differences in the filtering of the mask, not to
mention if it was at all off center or asymmetrical the mask would
rotate eccentrically. Also using two stages would allow for an
arbitrary mask to be applied rather than requiring a centered circular
mask. Here's how you could set it up with two stages:
* Put the mask in the alpha channel of the texture (full alpha inside
the dial, transparent outside, opposite of what you described), and set
this texture for both stages.
* Set the quad up with one set of texture coordinates, fixed at
(0.0,0.0) -> (1.0,1.0) to map the entire texture to the quad, and set
the texture coordinate index of both stages to point to these
* Apply a texture coordinate transformation to the first stage to rotate
the bitmap. Leave the second stage set to pass through the vertex
* Set the first stage as:
* and the second stage:
* After rendering the two stages, you'll have an output from the pixel
pipeline that has a color from the rotated texture and an alpha value
from the stationary mask. Apply alpha blending with D3DRS_SRCBLEND set
to D3DBLEND_SRCALPHA and D3DRS_DESTBLEND set to D3DBLEND_INVSRCALPHA.
I think that should do the trick! Hope that helps.
Microsoft DirectX MVP
The opinions expressed in this message are my own personal views and do
not reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation