Thread: Invisible geometry :( D3D vertex prob?

  1. #1
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72

    Invisible geometry :( D3D vertex prob?

    Hey, all im trying to do is make a simple cube in DirectX 9. However, despite it all compiling i have inivisble geometry. I have my lights switched on, materials set etc. So that leads me to think its a prob when I set my vertices, the code is:

    Code:
    bool CGfxEntityCube::Initialise()
    {
    gD3dDevice->CreateVertexBuffer(8*sizeof(CUBEVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_CUBEVERTEX, D3DPOOL_MANAGED, &m_vb, NULL);
    
    CUBEVERTEX pVertices[]={{ 0.0, 0.0, 0.0,},
    						{ 0.0, 1.0, 0.0,},
    						{ 1.0, 0.0, 0.0,},
    						{ 1.0, 1.0, 0.0,},
    						{ 1.0, 0.0, 1.0,},
    						{ 1.0, 1.0, 1.0,},
    						{ 0.0, 0.0, 1.0,},
    						{ 0.0, 1.0, 1.0,}};
    
    VOID *vertices;
    
    m_vb->Lock(0, sizeof(pVertices), (void**)&vertices, 0);
    
    memcpy(vertices, pVertices, sizeof(pVertices));
    
    m_vb->Unlock();
    
    gD3dDevice->CreateIndexBuffer(36*3*2, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_ib, NULL);
    
    WORD pIndices[]={0, 1, 2,
    				 2, 1, 3,
    				 2, 3, 4,
    				 4, 3, 5,
    				 4, 5, 6,
    				 6, 5, 7,
    				 6, 7, 0,
    				 0, 7, 1,
    				 1, 7, 3,
    				 3, 7, 5,
    				 0, 2, 6,
    				 2, 4, 6};
    
    VOID *indices;
    
    m_ib->Lock(0, sizeof(pIndices), (void**)&indices, 0);
    
    memcpy(indices, pIndices, sizeof(pIndices));
    
    m_ib->Unlock();
    
    return TRUE;
    }
    Is that ok? any other ideas where im going wrong?

    All i want is a simple life, a life of OpenGL
    Last edited by gazsux; 04-05-2003 at 03:31 PM.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    When you are creating your index buffer why are you passing 36 * 3 * 2 ?? just pass sizeof(pIndices) instead. This is a lot more flexible and I don't know why you multiplied it by 3? I'd have to see some more code to see what else might be wrong.

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    I'm no expert with DirectX, but I think I found your problem. I checked all your verticies and all your indicies, and those look correct, and they are wound correctly. I think the problem lies in these lines

    Code:
    VOID *vertices;
    
    m_vb->Lock(0, sizeof(pVertices), (void**)&vertices, 0);
    
    memcpy(vertices, pVertices, sizeof(pVertices));
    and
    Code:
    VOID *indices;
    
    m_ib->Lock(0, sizeof(pIndices), (void**)&indices, 0);
    
    memcpy(indices, pIndices, sizeof(pIndices));
    It appears to me that you are declaring void pointers named verticies and indicies, and then you are using them to store data? Unless m_ib->lock allocates some memory for your operations, you are going to run into some serious, serious problems with the pointers...once again, I'm not a DirectX expert, but if your problem is that you aren't allocating memory, at least it's easy to fix.
    Away.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by blackrat364
    I'm no expert with DirectX, but I think I found your problem. I checked all your verticies and all your indicies, and those look correct, and they are wound correctly. I think the problem lies in these lines

    Code:
    VOID *vertices;
    
    m_vb->Lock(0, sizeof(pVertices), (void**)&vertices, 0);
    
    memcpy(vertices, pVertices, sizeof(pVertices));
    and
    Code:
    VOID *indices;
    
    m_ib->Lock(0, sizeof(pIndices), (void**)&indices, 0);
    
    memcpy(indices, pIndices, sizeof(pIndices));
    It appears to me that you are declaring void pointers named verticies and indicies, and then you are using them to store data? Unless m_ib->lock allocates some memory for your operations, you are going to run into some serious, serious problems with the pointers...once again, I'm not a DirectX expert, but if your problem is that you aren't allocating memory, at least it's easy to fix.
    Thats not the problem. When you call CreateIndexBuffer and CreateVertexBuffer you specify the size and Direct3D will allocate the storage for you.

  5. #5
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    My bad. Sorry, disregard my previous post.
    Away.

  6. #6
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    why are you passing 36 * 3 * 2 ?? just pass sizeof(pIndices) instead
    I didnt use sizeof, since at that point pIndices doesnt have a size. But it would be better.

    The debugger is giving an error:
    Direct3D9: (ERROR) :All attenuation factors are 0 for non-directional light
    Direct3D9: (ERROR) :SetLight failed.

    But i think this code is ok, so im unsure why its fails:
    Code:
    void CVisualisation::CreateDirectionalLight()
    {
    // Fill in a light structure defining our light
    D3DLIGHT9 light;
    D3DXVECTOR3 vecDir;
    
    ZeroMemory(&light, sizeof(D3DLIGHT9));
    
    light.Type=D3DLIGHT_DIRECTIONAL;
    light.Diffuse.r=0.6f;
    light.Diffuse.g=0.6f;
    light.Diffuse.b=0.6f;
       
    vecDir=D3DXVECTOR3(0.0f,-0.3f,-0.5);
       
    D3DXVec3Normalize((D3DXVECTOR3*)&light.Direction, &vecDir);
    
    // Tell the device about the light and turn it on
    light.Range=1000.0f;
    gD3dDevice->SetLight(0, &light);
    gD3dDevice->LightEnable(0, TRUE); 
    
    }
    
    void CVisualisation::CreatePointLight(const D3DVECTOR &pos)
    {
    // Fill in a light structure defining our light
    D3DLIGHT9 light;
    
    ZeroMemory(&light, sizeof(D3DLIGHT9));
    
    light.Type=D3DLIGHT_POINT;
    light.Diffuse.r=1.0f;
    light.Diffuse.g=1.0f;
    light.Diffuse.b=1.0f;
       
    // Point lights have no direction but do have a position
    light.Position=pos;
       
    // Tell the device about the light and turn it on
    light.Attenuation0=0.0f;
    light.Range=200.0f;
    gD3dDevice->SetLight(1, &light);
    gD3dDevice->LightEnable(1, TRUE);
    
    }

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    For your point light you need to set the attenuation to a non-zero value. Do this..

    Code:
    light.Attenuation0 = 1.0f;
    This value is ignored for directional lights but all of the attenuations for non-directinal lights should never all be zero.

    EDIT:
    Which light is failing? I'm assuming the point light. Why don't you translate the HRESULT and find out what the error message is. That will probably be the most helpful.

  8. #8
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    I found the problem, there was a problem with the light attentuation as pointed out and also with my matrices, the projection matrix was messed up somehow. So after all that i now have a big black blob on my screen, rewarding huh! :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error help making no sense
    By tunerfreak in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2007, 07:55 PM
  2. Total newb directx invisable geometry question
    By -pete- in forum Game Programming
    Replies: 5
    Last Post: 08-13-2006, 01:45 PM
  3. Implemented vertex arrays, prob. rendering
    By BobMcGee123 in forum Game Programming
    Replies: 8
    Last Post: 07-22-2006, 08:00 PM
  4. DX9 visualization problem
    By darcome in forum Game Programming
    Replies: 4
    Last Post: 03-05-2003, 12:40 PM
  5. Pixel Shaders.
    By Cheeze-It in forum Game Programming
    Replies: 1
    Last Post: 05-21-2002, 01:16 AM