Sign in to follow this  

NOTHING visible, please help

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

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;
  if(SUCCEEDED(m_pVB_Board->Lock(0, 0, (void **)&buffer, D3DLOCK_DISCARD)))
  {
    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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by LeChuckIsBack
I 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 this post


Link to post
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]...

Share this post


Link to post
Share on other sites

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