Some nice anti-aliased text with DirectX
I have an image which contains alpha info. How should I render it over my 3D scene? (I am displaying some game stats; the image is an anti-aliased font character which I created in my art program.)
Right now I am thinking I will have to set the image as the texture for a camera-faced primitive. I like this approach particularly because I won''t have to worry about pixel formats, plus it''s all I could come up with. Any other suggestions, though?
You cannot alpha blit using BitBlt.. you have to use a texture for that...
The pretransformed coordinates are necessary because you want
the texture to appear at the same SCREEN coordinates all the
time. Using world-coordinates (i.e. using an untransformed
primitive) will probably make it wobble a bit due to round-off
errors.
The pretransformed coordinates are necessary because you want
the texture to appear at the same SCREEN coordinates all the
time. Using world-coordinates (i.e. using an untransformed
primitive) will probably make it wobble a bit due to round-off
errors.
Here''s how to draw 2D image with alpha as a polygon:
1. Set states:
D3DRENDERSTATE_SRCBLEND = D3DBLEND_SRCALPHA
D3DRENDERSTATE_DESTBLEND = D3DBLEND_INVSRCALPHA
D3DRENDERSTATE_ALPHABLENDENABLE = true
D3DRENDERSTATE_ZENABLE = false
SetTexture( ... )
2. Do this...
void fill_rectangle( float x1, float y1, float x2, float y2, D3DCOLOR color, float z = 0.5, float rhw = 0.5 )
{
D3DTLVERTEX v[4];
if( x2 > x1 ) x2++; else x1++;
if( y2 > y1 ) y2++; else y1++;
v[0] = D3DTLVERTEX( D3DVECTOR( x1, y2, z ), rhw, color, 0, 0, 1 );
v[1] = D3DTLVERTEX( D3DVECTOR( x1, y1, z ), rhw, color, 0, 0, 0 );
v[2] = D3DTLVERTEX( D3DVECTOR( x2, y2, z ), rhw, color, 0, 1, 1 );
v[3] = D3DTLVERTEX( D3DVECTOR( x2, y1, z ), rhw, color, 0, 1, 0 );
DXFramework->DrawPrimitive( D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, v, 4, 0 );
}
1. Set states:
D3DRENDERSTATE_SRCBLEND = D3DBLEND_SRCALPHA
D3DRENDERSTATE_DESTBLEND = D3DBLEND_INVSRCALPHA
D3DRENDERSTATE_ALPHABLENDENABLE = true
D3DRENDERSTATE_ZENABLE = false
SetTexture( ... )
2. Do this...
void fill_rectangle( float x1, float y1, float x2, float y2, D3DCOLOR color, float z = 0.5, float rhw = 0.5 )
{
D3DTLVERTEX v[4];
if( x2 > x1 ) x2++; else x1++;
if( y2 > y1 ) y2++; else y1++;
v[0] = D3DTLVERTEX( D3DVECTOR( x1, y2, z ), rhw, color, 0, 0, 1 );
v[1] = D3DTLVERTEX( D3DVECTOR( x1, y1, z ), rhw, color, 0, 0, 0 );
v[2] = D3DTLVERTEX( D3DVECTOR( x2, y2, z ), rhw, color, 0, 1, 1 );
v[3] = D3DTLVERTEX( D3DVECTOR( x2, y1, z ), rhw, color, 0, 1, 0 );
DXFramework->DrawPrimitive( D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, v, 4, 0 );
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement