Archived

This topic is now archived and is closed to further replies.

BrianMJC

DrawIndexedPrimitiveUP Problem

Recommended Posts

BrianMJC    152
Hi everyone, I really hope someone can help me out with this, because after a month of trying, I give up! In my project, the call to IDirect3DDevice8->DrawIndexedPrimitiveUP does absolutely nothing. I am trying to get an isometric tile grid to appear (i.e. showing tile boundaries) by rendering rows of linestrips from top to bottom of the screen. I can get flat textures to display fine. I use that same world matrix transform calculation for my tile grid. The only difference between the two methods, besides having different sets of vertex values, is that the textures have textures (of course) and are triangle strips while I use linestrips without textures for my grid. My code is below. "Display" is a working texture class method that correctly displays textures at the requested screen coordinates. Following that is "DrawGrid," a game world class method that is supposed to display the world tile grid but does not. I verified the vertex values to be correct in DrawGrid by dumping them to a log file. "c" is a world class member of type tile pointer which is maintained as the center tile onscreen; "v" is a tile class member of type tile pointer which points to the up-left-most tile to begin rendering the grid onscreen (linestrip row by linestrip row, left to right, top to bottom). My vertex FVF is D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, and I set alpha blending, alpha testing and lighting all on at startup.
// D I S P L A Y /////////////////////////////////////////////////////////////

//

// Display texture onscreen.

//

// return value - success or failure

// fptDst - destination origin (up-left) point to render to screen, in pixels

// td - texture descriptor

//

inline estate ctexture::Display (fpoint &fptDst, stexdesc &td)

    {

    // Set texture to render.

    hr = g_pd3dDev->SetTexture (0, pd3dTexture);
    if (FAILED (hr))
        {
        sReport = "ctexture::Display -- Failed to set texture: ";
        sReport += D3DError (hr);
        Log (sReport);
        return g_ceSError;
        }

    // Solid rendering.

    hr = g_pd3dDev->SetRenderState (D3DRS_FILLMODE, D3DFILL_SOLID);
    if (FAILED (hr))
        {
        sReport = "cworld::DrawGrid - Failed to setup for wireframe rendering: ";
        sReport += D3DError (hr);
        Log (sReport);
        return g_ceSError;
        }

    // Set world transformation matrix.

    D3DXMatrixIdentity (&g_d3dxMatrix);
    g_d3dxMatrix._11 = 1.0 / g_cfVideoWidthD2;
    g_d3dxMatrix._41 = fptDst.x * g_d3dxMatrix._11;
    g_d3dxMatrix._22 = -1.0 / g_cfVideoHeightD2;
    g_d3dxMatrix._42 = fptDst.y * g_d3dxMatrix._22;
    hr = g_pd3dDev->SetTransform (D3DTS_WORLD, &g_d3dxMatrix);
    if (FAILED (hr))
        {
        sReport = "ctexture::Display -- Failed to set world transform matrix: ";
        sReport += D3DError (hr);
        Log (sReport);
        return g_ceSError;
        }

    // Setup material to reflect desired color.

    ZeroMem (d3dMaterial);
    d3dMaterial.Ambient.r = td.fc.r;
    d3dMaterial.Ambient.g = td.fc.g;
    d3dMaterial.Ambient.b = td.fc.b;
    d3dMaterial.Ambient.a = td.fc.a;
    hr = g_pd3dDev->SetMaterial (&d3dMaterial);
    if (FAILED (hr))
        {
        sReport = "ctexture::Display -- Failed to setup material: ";
        sReport += D3DError (hr);
        Log (sReport);
        return g_ceSError;
        }
    
    // Draw texture.

    hr = g_pd3dDev->DrawPrimitiveUP (D3DPT_TRIANGLESTRIP, 2, aVertex, sizeof (cvertex));
    if (FAILED (hr))
        {
        sReport = "ctexture::Display -- Failed to draw texture: ";
        sReport += D3DError (hr);
        Log (sReport);
        return g_ceSError;
        }

    return g_eState;

    }


// D R A W   G R I D /////////////////////////////////////////////////////////

//

// Draws grid showing tile borders.

//

// return status - success or failure

//

estate cworld::DrawGrid ()

    {

    uint uRowsP1;
    ctile *ptilBeg;

    uRowsP1 = uRows + 1;
    
    // Get view tile (up-leftmost tile to begin the rendering).

    ptilBeg = c->v[uZoom];
    
    // Wireframe rendering.

    hr = g_pd3dDev->SetRenderState (D3DRS_FILLMODE, D3DFILL_WIREFRAME);
    if (FAILED (hr))
        {
        sReport = "cworld::DrawGrid - Failed to setup for wireframe rendering: ";
        sReport += D3DError (hr);
        Log (sReport);
        return g_ceSError;
        }

    // Remove texture to prevent interference.

    hr = g_pd3dDev->SetTexture (0, NULL);
    if (FAILED (hr))
        {
        sReport = "cworld::DrawGrid -- Failed to remove texture: ";
        sReport += D3DError (hr);
        Log (sReport);
        return g_ceSError;
        }

    // Setup material to reflect desired color.

    D3DMATERIAL8 d3dMaterial;
    ZeroMem (d3dMaterial);
    d3dMaterial.Ambient.r = 1.0;
    d3dMaterial.Ambient.g = 1.0;
    d3dMaterial.Ambient.b = 1.0;
    d3dMaterial.Ambient.a = 1.0;
    hr = g_pd3dDev->SetMaterial (&d3dMaterial);
    if (FAILED (hr))
        {
        sReport = "ctexture::Display -- Failed to setup material: ";
        sReport += D3DError (hr);
        Log (sReport);
        return g_ceSError;
        }

    uint uNumVertices, uPrimitiveCount, *puIndexData, u;
    uPrimitiveCount = uCols;
    uNumVertices = uPrimitiveCount + 1;
    puIndexData = new uint[uNumVertices];
    for (u = 0; u < uNumVertices; u++)
        puIndexData[u] = u;

    // Begin drawing the grid.

    for (u = 0; u < uRowsP1; u++)
    
        {

        // Set world transformation matrix.

        D3DXMatrixIdentity (&g_d3dxMatrix);
        g_d3dxMatrix._11 = 1.0 / g_cfVideoWidthD2;
        g_d3dxMatrix._41 = ptilBeg->l->pos.x * g_d3dxMatrix._11;
        g_d3dxMatrix._22 = -1.0 / g_cfVideoHeightD2;
        g_d3dxMatrix._42 = ptilBeg->l->pos.y * g_d3dxMatrix._22;
        hr = g_pd3dDev->SetTransform (D3DTS_WORLD, &g_d3dxMatrix);
        if (FAILED (hr))
            {
            sReport = "ctexture::Display -- Failed to set world transform matrix: ";
            sReport += D3DError (hr);
            Log (sReport);
            return g_ceSError;
            }

        // 

        hr = g_pd3dDev->DrawIndexedPrimitiveUP (D3DPT_LINESTRIP, 0, uNumVertices, uPrimitiveCount, (void *)puIndexData, D3DFMT_INDEX32, ptilBeg->l, sizeof (cvertex));
        if (FAILED (hr))
            {
            sReport = "cworld::DrawGrid -- Failed to draw linestrip: ";
            sReport += D3DError (hr);
            Log (sReport);
            return g_ceSError;
            }

        ptilBeg = ptilBeg->s;
        
        }

    delete [] puIndexData;

    return g_eState;

    }
I really appreciate any help!

Share this post


Link to post
Share on other sites