D3D9 DrawPrimitive Gradiente Color

0

I'm trying to make a color picker system, and for this I need a color gradient.

I'm trying to use DrawPrimitive to draw a square with color vertex. but the result is not what I wanted, the gradient is not so pretty in comparison to other programs

My Gradient:

enter image description here

Gradient Photoshop/ImGui/Other programs seem to:

enter image description here

void GradientColor(float x, float y, float width, float height)
{
    static struct D3DVERTEX
    { 
        float x, y, z, rhw;
        DWORD color;
    };

    D3DVERTEX vertices[4];

    vertices[0].x = x;
    vertices[0].y = y;
    vertices[0].z = 0.f;
    vertices[0].rhw = 1.f;
    vertices[0].color = 0xffffffff; //White

    vertices[1].x = x + width;
    vertices[1].y = y;
    vertices[1].z = 0.f;
    vertices[1].rhw = 1.f;
    vertices[1].color = 0xffff0000; //Red

    vertices[2].x = x;
    vertices[2].y = y + height;
    vertices[2].z = 0.f;
    vertices[2].rhw = 1.f;
    vertices[2].color = 0xff000000; //Black

    vertices[3].x = x + width;
    vertices[3].y = y + height;
    vertices[3].z = 0.f;
    vertices[3].rhw = 1.f;
    vertices[3].color = 0xff000000; //Black


    static LPDIRECT3DVERTEXBUFFER9 pVertexObject = NULL;
    static void *pVertexBuffer = NULL;

    if (!pVertexObject) {
        if (FAILED(device->CreateVertexBuffer(sizeof(vertices), 0,
            D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &pVertexObject, NULL)))
            return;
    }
    if (FAILED(pVertexObject->Lock(0, sizeof(vertices), &pVertexBuffer, 0)))
        return;

    memcpy(pVertexBuffer, vertices, sizeof(vertices));
    pVertexObject->Unlock();

    device->SetStreamSource(0, pVertexObject, 0, sizeof(D3DVERTEX));
    device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
    device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

}

I know the difference is not big, but it's perceptible, Thanks for all.

c++
direct3d
color-picker
directx-9
asked on Stack Overflow Mar 22, 2019 by Ph4nton

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0