• Advertisement

Archived

This topic is now archived and is closed to further replies.

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

This topic is 5128 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement