Vertex Declaration failure

Started by
6 comments, last by cozzie 9 years, 3 months ago

Hey everyone,

I'm trying to split my position and my color as two different arrays by using a declaration instead of FVF, however when I'm creating it, I'm getting a fail.


D3DVERTEXELEMENT9 posColour_vec[] =
{
    { 0, 0, D3DDECLTYPE_FLOAT4,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0 },
    { 1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,     0 },
    D3DDECL_END()
};

Is it because I'm using POSITIONT? Do I need to change it to POSITION to be able to use another stream for my color?

Thanks!
Advertisement

I'm by no means confident in my answer, but am going to hazard a guess, since the usage of PositionT disables vertex processing, that it is not designed to work with multiple streams. Have you verified that the multiple streams are available? Are the usages you requested available on your card? Have you been able to multiple streams with untransformed positions successfully?

That's what I thought too. I'm in the process of going to XYZ and using D3DXMatrixOrthoOffCenterRH to get a 2D view instead of using RHW.

I've gotten it to work by putting both the color and the xyzrhw on the same stream. The moment that I split them up it fails.

Looking at the documentation tells me that when using POSITIONT:

  • Only stream zero can be used in such declarations.
since the usage of PositionT disables vertex processing, that it is not designed to work with multiple streams.

Yup.

POSITIONT is generally dumb.

Hey guys, I'm not sure if I'm allowed to divert the subject a little bit as I'm trying to move from POSITIONT to POSITION. Obviously I'm trying to setup a 2D view... but now when I use D3DXMatrixOrthoOffCenterRH, my screen is completely black. Any thoughts? I'm coming from OpenGL and I think that's RH.


      ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use      d3dpp.Windowed = TRUE;    // program windowed, not fullscreen
      d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
      d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D

      // create a device class using this information and information from the d3dpp stuct
      d3d->CreateDevice(D3DADAPTER_DEFAULT,
         D3DDEVTYPE_HAL,
         hWnd,
         D3DCREATE_SOFTWARE_VERTEXPROCESSING,
         &d3dpp,
         &this->d3d_device);

      HRESULT hr;

      D3DXMATRIX ortho2D;
      D3DXMATRIX identity;

      D3DXMatrixOrthoOffCenterRH(&ortho2D, 0.0f, UI::WindowSize::Instance().GetWindowWidth(), UI::WindowSize::Instance().GetWindowHeight(), 0.0f, -1.0f, 4.0f);
      D3DXMatrixIdentity(&identity);

      this->d3d_device->SetTransform(D3DTS_PROJECTION, &ortho2D);
      this->d3d_device->SetTransform(D3DTS_WORLD, &identity);
      this->d3d_device->SetTransform(D3DTS_VIEW, &identity);

This is my declaration:


      D3DVERTEXELEMENT9 posColour_vec[] =
      {
         { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
         { 1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
         D3DDECL_END()
      };

I'm setting my z to be 1.0f.

This is my Clear


this->d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

Have you adjusted the data in your vertex buffers? Pretransformed data is in the +/-1 range, but you are now using a projection that would imply you want vertex data in +width or +height ranges. So it's possible your entire scene is compressed into less than a pixel in the bottom left or something.

My vertex data is in the 0 to 800/600 range as I was using XYZRHW previously. What should I be setting my z at?

You could use 1.0f for Z.
What exact error do you get btw? (can you catch the HRESULT and retrieve the error description?)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement