• Advertisement
Sign in to follow this  

Cleaner and shorter ask for help on rendering 2 VBs.

This topic is 4494 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 rewrote this topic because it was a big mess. Now I've condensed the bug into the following problem. This code bugs up: http://www.rafb.net/paste/results/5gUIgO31.html
void Renderer::AppendLayers(const vector<LAYERDATA>& layerData)  
{
    VOID *pData;
    VOID *pData2;       
 
    ReleaseLayers();
    m_VLayersToRender.push_back(RENDERLAYER());                     // Append a layer
 
    m_pDirect3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, BGCOLOUR, 1.0f, 0);  
    m_pDirect3DDevice->BeginScene();
 
 
ERRCON("AppendLayers() - Adding a VB for a moving coloured quad");
    m_VLayersToRender.back().v_PaintingData.push_back(RENDERDATA());
    m_VLayersToRender.back().v_PaintingData.back().texturePtr   = NULL;
    m_VLayersToRender.back().v_PaintingData.back().fvf          = D3DFVF_MOVINGCOLOUREDVERTEX;
    m_VLayersToRender.back().v_PaintingData.back().size         = sizeof(MYMOVINGCOLOUREDVERTEX);
  
    m_pDirect3DDevice->CreateVertexBuffer(layerData[0].v_MovingColVerts.size() * sizeof(MYMOVINGCOLOUREDVERTEX),D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,D3DFVF_MOVINGCOLOUREDVERTEX,D3DPOOL_DEFAULT, &(m_VLayersToRender.back().v_PaintingData.back().vb),NULL);
 
    m_VLayersToRender.back().v_PaintingData.back().vb->Lock(0,0,(void**)&pData,0);      
    memcpy(pData,&(layerData[0].v_MovingColVerts.front()), sizeof(MYMOVINGCOLOUREDVERTEX) * layerData[0].v_MovingColVerts.size());                  
    m_VLayersToRender.back().v_PaintingData.back().vb->Unlock();
ERRCON("Added");
 
 
// HERE
 
ERRCON("AppendLayers() - Added a VB for a non-moving coloured quad");
    m_VLayersToRender.back().v_PaintingData.push_back(RENDERDATA());
    m_VLayersToRender.back().v_PaintingData.back().texturePtr   = NULL;
    m_VLayersToRender.back().v_PaintingData.back().fvf          = D3DFVF_FIXEDCOLOUREDVERTEX;
    m_VLayersToRender.back().v_PaintingData.back().size         = sizeof(MYFIXEDCOLOUREDVERTEX);
  
    m_pDirect3DDevice->CreateVertexBuffer(layerData[0].v_FixedColVerts.size() * sizeof(MYFIXEDCOLOUREDVERTEX),D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,D3DFVF_FIXEDCOLOUREDVERTEX,D3DPOOL_DEFAULT, &(m_VLayersToRender.back().v_PaintingData.back().vb),NULL);

    m_VLayersToRender.back().v_PaintingData.back().vb->Lock(0,0,(void**)&pData2,0);     
    memcpy(pData2,&(layerData[0].v_FixedColVerts.front()), sizeof(MYFIXEDCOLOUREDVERTEX) * layerData[0].v_FixedColVerts.size());                    
    m_VLayersToRender.back().v_PaintingData.back().vb->Unlock();
ERRCON("Added");
 
 
// Render the moving quad
    m_pDirect3DDevice->SetFVF(m_VLayersToRender[0].v_PaintingData[0].fvf);                  
    m_pDirect3DDevice->SetStreamSource(0, m_VLayersToRender[0].v_PaintingData[0].vb, 0, m_VLayersToRender[0].v_PaintingData[0].size);   
    m_pDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0,     2); // 2 triangles for now.
 
// Render the fixed quad
    m_pDirect3DDevice->SetFVF(m_VLayersToRender[0].v_PaintingData[1].fvf);                  
    m_pDirect3DDevice->SetStreamSource(0, m_VLayersToRender[0].v_PaintingData[1].vb, 0, m_VLayersToRender[0].v_PaintingData[1].size);   
    m_pDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0,     2); // A variable is usually used.
 
 
    m_pDirect3DDevice->EndScene();
    m_pDirect3DDevice->Present(NULL,NULL,NULL,NULL);                // Lump it all on screen
 
} // ------------ AppendLayers() end -------------- //





However, if I cut the 3 lines under "// Render the moving quad" and paste them at "// HERE", it displays both quads properly. Compiled as it is above, only the 2nd quad appears as expected.. the first quad is a garbled mess, and the wrong colour. Why? [Edited by - Defend on January 1, 2006 2:01:05 PM]

Share this post


Link to post
Share on other sites
Advertisement
Ah sorry heh, I just thought I'd leave the CreateVertexBuffer() calls like that to kind of keep it neater to the eye.

#Gamedev have suggested that its probably my old VC++ 6.0. I'm installing VC EE 2005 now.

Share this post


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

  • Advertisement