Sign in to follow this  

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

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


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->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.


Share this post

Link to post
Share on other sites
Ah! Sorry for my stupidity. I'm using things yet I don't even know what they do... Thanks for the help. I found a new method of rendering 2D things though, at least :D.

Share this post

Link to post
Share on other sites

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