• Advertisement
Sign in to follow this  

Help with my Debug Drawer

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

 
struct line_vertex
{
    float x, y, z;
    D3DXCOLOR color;
};

const DWORD line_fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;

class DebugDrawDX : public duDebugDraw
{
public:
    DebugDrawDX();
    virtual ~DebugDrawDX() { }    
    virtual void depthMask(bool state);
    virtual void texture(bool state);
    virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f);
    virtual void vertex(const float x, const float y, const float z, const D3DXCOLOR& color);
    virtual void end();  
    virtual void Draw();
    
    IDirect3DVertexBuffer9* VB; // unique vertexes
    std::vector<line_vertex> line_vertices;
    duDebugDrawPrimitives mode;

    DWORD m_prim_count;
    
};
DebugDrawDX::DebugDrawDX()
{
    VB = 0;
    m_prim_count = 0;
    mode = DU_DRAW_LINES;
    line_vertices.clear();
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void DebugDrawDX::depthMask(bool state)
{
    if (state)
    {
        d3d::GetInstance().GetDevice()->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
    }
    else
    {
        d3d::GetInstance().GetDevice()->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
    }
}

void DebugDrawDX::texture(bool state)
{
    
}

void DebugDrawDX::begin(duDebugDrawPrimitives prim, float size)
{    
    d3d::GetInstance().GetDevice()->SetRenderState(D3DRS_LIGHTING, FALSE);
    d3d::GetInstance().GetDevice()->SetRenderState(D3DRS_POINTSIZE, size);
    mode = prim;
}

void DebugDrawDX::vertex(const float x, const float y, const float z, const D3DXCOLOR& color)
{
    struct line_vertex vertex = { x, y, z, color };
    line_vertices.push_back(vertex);

}

void DebugDrawDX::end()
{
     
    d3d::GetInstance().GetDevice()->CreateVertexBuffer(line_vertices.size() * sizeof(line_vertex), 0,
        line_fvf, D3DPOOL_MANAGED, &VB, NULL);

    VOID* pVerts = NULL;
    // put stuff into vertex buffer
    VB->Lock(0, line_vertices.size()*sizeof(line_vertex), (void**)&pVerts, 0);
    memcpy(pVerts, &line_vertices[0], line_vertices.size()*sizeof(line_vertex));
    VB->Unlock();

    m_prim_count = line_vertices.size()/2;

    
}

void DebugDrawDX::Draw()
{
    _D3DPRIMITIVETYPE drawtype;
    switch (mode)
    {
    case DU_DRAW_POINTS:        
        drawtype = D3DPT_LINELIST;                
        break;
    case DU_DRAW_LINES:        
        drawtype = D3DPT_LINELIST;
        break;
    case DU_DRAW_TRIS:        
        drawtype = D3DPT_TRIANGLELIST;
        break;
    case DU_DRAW_QUADS:
        drawtype = D3DPT_TRIANGLELIST;
        break;

    }

    if (!VB)
        return;

    if (m_prim_count <= 0)
        return;
    

    D3DXMATRIX iden;
    d3d::GetInstance().GetDevice()->SetTransform(D3DTS_WORLD, D3DXMatrixIdentity(&iden));
    d3d::GetInstance().GetDevice()->SetStreamSource(0, VB, 0, sizeof(line_vertex));
    d3d::GetInstance().GetDevice()->SetFVF(line_fvf);
    d3d::GetInstance().GetDevice()->DrawPrimitive(drawtype, 0, m_prim_count);
    d3d::GetInstance().GetDevice()->SetRenderState(D3DRS_LIGHTING, TRUE);
}

The Debug Drawer is supposed to draw 4 lines in a loop which is yellow in color....

Finally, all the stuff is blue, I've got outer render loops there, which call this inner loop....

void CMyApp::RenderNavmesh()
{
    //// Drawing other navmesh related stuff
    NavigationSysMgr::getInstance()->GetNavigationSys("CB_Warehouse")->GetNavMesher()->DrawAnnotation();
}
Edited by lucky6969b

Share this post


Link to post
Share on other sites
Advertisement

struct line_vertex
{
    float x, y, z;
    D3DXCOLOR color;
};

const DWORD line_fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;

 

Your color should be a DWORD ARGB since you used D3DFVF_DIFFUSE

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement