Drawing screen quad using orthogonal projection?

Started by
3 comments, last by undead 14 years, 3 months ago
Hi guys, So I want to draw screen quad using orthogonal projection. I already have two methods to draw screen quad: one uses frustum corner, and the other use vertex XYZRHW. The problem is I have no idea on how to do orthogonal projection. Do I start with: - defining a vertex structure with a flag like D3DFVF_XYZ - build the quad - setup camera in orthogonal mode - draw the quad Am I correct with the steps above? How do I setup a camera in orthogonal mode? I know there is this function to calculate orthogonal projection matrix: D3DXMatrixOrthoLH() but do I have to do anything else for setting up orthogonal projection? Thanks in advance for all the help. [Edited by - b_thangvn on December 24, 2009 2:52:23 AM]
Advertisement
Working on this myself..

check out http://www.gamedev.net/reference/programming/features/2d3dquads/page5.asp
Hi there,

Thanks for reply. If you don't mind, I would like to ask about the advantage and disadvantage of various methods used to draw screen-quad: frustum corner, vertex XYZRHW, and orthogonal projection. Why do people choose to use one from another? Also, how should I write a vertex shader according to the method that I choose? Thanks.

[Edited by - b_thangvn on December 25, 2009 5:48:57 AM]
Bump.
I don't know if it's been posted, I thought I read about this technique here at gamedev.

In D3D10 there's a funny way of drawing a screen quad (or a generic rect).

Use this as shader input:

struct VSIn
{
uint vertexId : SV_VertexID;
};

In your drawQuad method do the following:

m_pD3D10Device->Draw( 4, 0 );


Implement the vertex shader this way:

    VSOut output;    if (input.vertexId == 0)    {        // First vertex    }    else if (input.vertexId == 1)    {        // Second vertex    }    else if (input.vertexId == 2)    {        // Third vertex    }    else if (input.vertexId == 3)    {        // Fourth vertex    }


If you need to draw generic rects all you need to do is to use variables and fill them in drawQuad.

If it's not funny enough, you can draw a full screen quad with just a triangle. No support for generic rects in this case.

Use: Draw(3,0) and make the vertices (and texcoords) go beyond the screen, like
0,0 -> 3,0 -> 0,3. Clipping will do the work for you.

I have such a drawQuad implemented somewhere in my framework. I suppose it's not fast or clean. I use it because it's so hacky it deserved to be implemented!

[wink]

This topic is closed to new replies.

Advertisement