## Recommended Posts

I translated the world matrix to values of z greater than 0, (also applied some scaling) and I set the view and projection matrices to identity (for testing), added some ambient light just in case, then I run the following code but nothing is visible:
#define D3DFVF_CUSTOM_VERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)

struct CUSTOM_VERTEX
{
FLOAT     x, y, z;     // The position
FLOAT     nx, ny, nz;  // The normal
FLOAT     tu, tv;      // The texture coordinates
// ...some constructors here...
};

pD3DDevice->CreateVertexBuffer(
8 * sizeof(CUSTOM_VERTEX),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFVF_CUSTOM_VERTEX,
D3DPOOL_DEFAULT,
&m_pVB_Board,
NULL);

if(m_pVB_Board)
{
CUSTOM_VERTEX *buffer;
{
buffer[0] = CUSTOM_VERTEX(D3DXVECTOR3(-0.5f, -0.5f,  0.0f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(0, 1));
buffer[1] = CUSTOM_VERTEX(D3DXVECTOR3(-0.5f,  0.5f,  0.0f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(0, 0));
buffer[2] = CUSTOM_VERTEX(D3DXVECTOR3( 0.5f, -0.5f,  0.0f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(1, 1));
buffer[3] = CUSTOM_VERTEX(D3DXVECTOR3( 0.5f,  0.5f,  0.0f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(1, 0));
buffer[4] = CUSTOM_VERTEX(D3DXVECTOR3( 0.5f, -0.5f,  0.0f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(1, 1));
buffer[5] = CUSTOM_VERTEX(D3DXVECTOR3( 0.5f,  0.5f,  0.0f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(1, 0));
buffer[6] = CUSTOM_VERTEX(D3DXVECTOR3(-0.5f, -0.5f,  0.0f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(0, 1));
buffer[7] = CUSTOM_VERTEX(D3DXVECTOR3(-0.5f,  0.5f,  0.0f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(0, 0));
m_pVB_Board->Unlock();
}

pD3DDevice->SetStreamSource(0, m_pVB_Board, 0, sizeof(CUSTOM_VERTEX));
pD3DDevice->SetFVF(D3DFVF_CUSTOM_VERTEX);
pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2);
}

I just started to use the DXUT framework a few days ago and I only managed to draw transformed vertices
#define D3DFVF_CUSTOM_TVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1)
I've lost a whole day over this, tried all sorts of parameters, but with the same result. The matrices are good, all DirectX functions report S_OK... What's wrong?

##### Share on other sites
Have you tried clearing your backbuffer to a non-black colour to see if anything is showing up, just in black? Have you tried switching to transformed verts (D3DFVF_XYZRHW) to work out if it's a problem with your matrices (I know you said they're fine, but how are you sure?)? Have you tried disabling lighting and culling via the renderstates? Are you using the debug runtimes? Any relevant debug output? Any D3D related debug output at all? Are you calling Present() after BeginScene() and EndScene()? Is your window visible?

##### Share on other sites
Unfortunately, yes, I've already checked all that, except switching to transformed vertices (which I'll do tomorrow for testing and I think it will work cause D3DFVF_XYZRHW seems to work) but I still need to use untransformed vertices...

##### Share on other sites
Quote:
 Original post by LeChuckIsBackI translated the world matrix to values of z greater than 0, (also applied some scaling)

1. Can you post the code where you do that?

A common trap many people fall into is forgetting that many of the D3DXMatrix* functions write to all of the matrix, so for example passing the same matrix to D3DXMatrixRotationX() then D3DXMatrixRotationY() only produces a matrix which rotates around Y because the second call overwrote the first. You need to multiply the matrices together to produce the end result. There is sample code in the "Matrices" tutorial in the SDK.

Quote:
 and I set the ... projection matrices to identity (for testing)

2. That could cause some issues with Z buffering so change it back before any other tests/debugging (debugging one problem that's being hidden by another problem takes a lot longer...).

Quote:
 added some ambient light just in case

3. Have you set a valid D3D material for the lighting? If you haven't then your light and ambient values will be multiplied by black.

##### Share on other sites
Quote:
 2. That could cause some issues with Z buffering so change it back before any other tests/debugging (debugging one problem that's being hidden by another problem takes a lot longer...).

Yes, you're right - it run instantly! I forgot that without a proper projection matrix, the Z coordinate of the vertices will not be squashed into the 0..1 range of the z-buffer. So... they were all simply clipped away [pig]...

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627652
• Total Posts
2978421

• 10
• 12
• 22
• 13
• 33