• 9
• 10
• 11
• 13
• 9
• entries
743
1924
• views
582177

# HUD stuff

105 views

Got a crosshair up and running:

Obviously the more important step is being now able to render any kind of HUD stuff over the top of a 3D screen.

I tried messing about with D3DXMatrixOrtho... stuff as Todo suggested, but I couldn't get it to work in the end.

So instead, I created a second vertex format with a RHW component and texture co-ordinates. It seems that I can now specify a vertex buffer of those with actual screen co-ordinates, then all I need to do is, after all the scene rendering, set the FVF to the new vertex format, switch of z-buffer testing and set the HUD vertex buffer as the stream source.

Obviously I've also had to switch alpha testing on for the crosshair then off for the main rendering since I believe it is quite expensive. I'm using the beast that is D3DXCreateTextureFromFileEx() for now to just autoset the alpha for any black pixels to 0. Better future options are the custom image format I developed with my 2D Direct3D games or maybe the DX Texture tool and .dds files or something.

Don't really care since all that is already well within capabilities. Just pleased to be able to render HUD stuff really.

For some reason though, and help if you can, while the texture alpha seems to be working, I've added a diffuse colour to the vertex format I use for the HUD and obviously assigned a colour to each of the crosshair vertices.

Now, I can modulade the colour of the crosshair using these per-vertex colours, but changing the alpha value of the colour of each vertex does not appear to have any effect.

I know the alphatest stuff is set up right since it is masking out the background of the crosshair texture image, but when I wrote my D3D 2D library, I could also then modulate the alpha of a vertex via the alpha component of the colour member of each vertex. Doesn't seem to work here.

Anyone got any thoughts on that? Appreciate is a bit of a long shot to expect anyone to be able to provide an answer from that rambling.

[EDIT] Christophedo's solved this for me. Vertex alpha working perfectly well now.

I remember having trouble with something like this a while back [smile]. I think it had something to do with D3D only using texture alpha and discarding vertex alpha. Try something like this so it modulates between the two:

D3DXSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
D3DXSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
D3DXSetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );



I may be wrong, but hopefully that helps [grin].

Looking good, you're really getting through this stuff quickly.

Quote:
 Original post by Christophedo I remember having trouble with something like this a while back [smile]. I think it had something to do with D3D only using texture alpha and discarding vertex alpha. Try something like this so it modulates between the two: *** Source Snippet Removed *** I may be wrong, but hopefully that helps [grin].

You are such a star. That worked perfectly. Thanks very much indeed.