How do I make a Quad appear in a specific spot on the screen, regardless of Camera?

Started by
4 comments, last by darkawakenings 20 years, 2 months ago
The subject pretty much says it all. I want a stats bar across the bottem of my screen. How do I display this without worrying about where the camera is i want to just use screen coordinates rather than 3d world coordinates. I''m using DX8.
Advertisement
There are several ways to do that.

Here's one way that came to mind:
Render everything from that one camera.
Set a different camera (at position 0,0,-1 pointing down the z axis) using orthogonal projection.
Clear ZBUFFER and STENCIL BUFFER ONLY! DO NOT CLEAR TARGET!
Position your stat bar at the x & y screen coords you want it.
Render the stat bar.


Since you clear the zbuffer the bar will be put on top of everything else you drew, and since it uses orthogonal z doesn't matter for size, so x & y is always the screen position.

[edited by - Erzengeldeslichtes on February 6, 2004 3:39:28 PM]
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
Look into using transformed vertices. That would mean using something like this:
#define STATUSVERTEX_FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
struct STATUSVERTEX
{
D3DXVECTOR4 pos; //notice it''s a 4-D Vector
D3DCOLOR diffuse; //Or tex coords or whatever
};

Then create and load your vertex buffer with four vertices as a triangle strip (I assume you can do this), then render in your main loop with your main camera.
As ms291052 said, use transformed vertices. As transformed vertices, the x and y values you provide are in "screen" space. 0,0 is the top left corner of your window. X,Y are some distance away from that.

Use D3DXVECTOR4. The x, y, and z positions are what you will set for the position. I can''t remember, but I think z is used only to determine the order of objects on the screen. It does not provide camera depth. Set it to 0.0 if you don''t need overlapping. I think Z should always be between 0.0 and 1.0. Set w (which is the placeholder for the RHW component) to 1.0 to make the projection correct for what you want.

Chris
Chris ByersMicrosoft DirectX MVP - 2005
What you want is D3DXMatrixOrthoLH() (or the RH version if you prefer). You can specify the projection in screen coordinates, percent, 0 to 1, or whatever makes sense to you, but it will basically be a 2D space spanning whatever dimensions you set it up with. Just disable z testing and draw whatever you want over the screen.
Do be aware that if you change resolution, you''d have to change your coordinates, so they shouldn''t be hard coded. A much cleaner way is to have normalized (between 0 and 1) screen coordinates in your vertices, but before you send them over to the vertex buffer multiply it by the current resolution.

This topic is closed to new replies.

Advertisement