Sign in to follow this  

Problem w/ RHW in my Vertex Class (C++)

This topic is 4162 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

Whenever I declare my Vertex class, I currently use x/y/z/color/u/v, and my DrawPrimitiveUP() calls work fine. However, if I add in a rhw value in between z and color (and adjust the D3DFVF_'s accordingly), I have to change my z value to 0.0f and my stuff hardly even shows up on the screen (shows up at the top left). (My rhw is set to 1.0f at this point.) I don't see why this is happening, I've never had to change my rhw code. Here's an example of what makes a "point" show up at the top left of the screen instead of in the middle where it should be:
// NOTE:  MAJOR clipping in this file - I just have the bare minimum
// as to what code is wrong

#define D3DFVF_CUSTOM (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)

struct CVertex
{
float x, y, z, rhw;
DWORD color;
float u, v;
};

CVertex vtxPoint;

void Setup()
{
// major clip here
vtxPoint.x = 0.0f;
vtxPoint.y = 0.0f;
vtxPoint.z = 0.0f;
vtxPoint.rhw = 1.0f;
vtxPoint.color = 0xffffffff;
vtxPoint.u = 0.0f;
vtxPoint.v = 0.0f;
}

void Render()
{
pd3dDevice->SetFVF(D3DFVF_CUSTOM);
pd3dDevice->DrawPrimitiveUP(D3DPT_POINTLIST, 1, &vtxPoint, sizeof(CVertex));
}


Yes, my Matrixes are setup correctly (even if I remove all my matrix setup code it still renders wrong). The only way to make that point back where it should be is to remove the RHW value and set the z back to 1.0f.

Share this post


Link to post
Share on other sites
D3DFVF_XYZRHW is a PRE-transformed vertex; that is, you're explicitly telling Direct3D that you've done all the vertex processing and that it should just pass it through to the clipping/rasterization stages.

Your matrix setup will be ignored as will any materials/lighting. With a vertex defined at <0,0,0,1> it should indeed be in the top-left corner. Setting Z to larger values will move it "back" behind other 3D geometry (if there is any). Pre-transformed geometry has its coordinates in screen-space.

hth
Jack

Share this post


Link to post
Share on other sites

This topic is 4162 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this