C ++ Directx 3D:绘制具有替代颜色的矩形

时间:2013-12-23 21:15:46

标签: c++ directx-9

我是DirectX(3D)的新手,并且需要在Borland C ++中在屏幕顶部绘制连续矩形。我可以按照教程http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-1绘制矩形。

但我的问题是: 1.我将从屏幕的右到左连续绘制矩形。 2.现在,在绘制这个矩形时,每30秒它应该改变颜色。前30秒,说蓝色,接下来是30秒绿色。再过30秒后再次蓝色和30后再次变绿。像这样的颜色应该是替代的。

我能够绘制矩形,每隔30秒就会改变颜色。首先它会为某些像素绘制蓝色,30秒后它将绘制绿色。但是当它将颜色变为绿色时,它也会改变蓝色部分。 (这个功能每50ms由一个定时器功能调用,我正在重新绘制完整的屏幕。)

任何人都可以建议上述方法的任何替代方法,或者想方设法在矩形上绘制交替的矩形/颜色吗?

struct CUSTOMVERTEX {
        FLOAT x, y, z, rhw; // from the D3DFVF_XYZRHW flag
        DWORD color; // from the D3DFVF_DIFFUSE flag
    };

CUSTOMVERTEX OurVertices[4];

if (!d3ddev)
        return;

    float xscale = texWidth / 1024.0;
    if (xscale < 1.0)
        xscale = 1.0;

    VOID* pVoid; // the void* we were talking about

    mark->Lock(0, 0, (void**) & pVoid,  0);


        OurVertices[0].x = (float)x1 * xscale;
        OurVertices[0].y = 5;
        //OurVertices[0].z = 0;
        OurVertices[0].rhw = 1.0f;

        OurVertices[1].x = (float)x2 * xscale;
        OurVertices[1].y = 5;
        //OurVertices[1].z = 0;
        OurVertices[1].rhw = 1.0f;

        OurVertices[2].x = (float)x1 * xscale;
        OurVertices[2].y = 15;
        //OurVertices[2].z = 0;
        OurVertices[2].rhw = 1.0f;

        OurVertices[3].x = (float)x2 * xscale;
        OurVertices[3].y = 15;
        //OurVertices[3].z = 0;
        OurVertices[3].rhw = 1.0f;

        if (!drawMMarker)
        {
            OurVertices[0].color = D3DCOLOR_XRGB(64, 64, 64);
            OurVertices[1].color = D3DCOLOR_XRGB(64, 64, 64);
            OurVertices[2].color = D3DCOLOR_XRGB(64, 64, 64);
            OurVertices[3].color = D3DCOLOR_XRGB(64, 64, 64);

        }
        else
        {
            OurVertices[0].color = D3DCOLOR_XRGB(128, 128, 128);
            OurVertices[1].color = D3DCOLOR_XRGB(128, 128, 128);
            OurVertices[2].color = D3DCOLOR_XRGB(128, 128, 128);
            OurVertices[3].color = D3DCOLOR_XRGB(128, 128, 128);
            drawMMarker = false;
        }
        memcpy(pVoid, OurVertices, sizeof(OurVertices));

        // copy vertices to the vertex buffer
        mark->Unlock(); // unlock v_buffer

        d3ddev->SetFVF(CUSTOMFVF);
        d3ddev->SetStreamSource(0, mark, 0, sizeof(CUSTOMVERTEX));
        d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

将从计时器调用上述例程。

0 个答案:

没有答案