TTGroup
TTGroup

Reputation: 3713

DirectX: Draw bitmap image scale up in viewport caused low quality?

I'm using DirectX to draw the images with RGB data in buffer. The fllowing is sumary code:

    // create the vertex buffer
    D3D11_BUFFER_DESC bd;
    ZeroMemory(&bd, sizeof(bd));
    bd.Usage = D3D11_USAGE_DYNAMIC;                // write access access by CPU and GPU
    bd.ByteWidth = sizeOfOurVertices;             // size is the VERTEX struct * pW*pH
    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;       // use as a vertex buffer
    bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;    // allow CPU to write in buffer
    dev->CreateBuffer(&bd, NULL, &pVBuffer);       // create the buffer

    //Create Sample for texture
    D3D11_SAMPLER_DESC desc;
    desc.Filter = D3D11_FILTER_ANISOTROPIC;
    desc.MaxAnisotropy = 16;
    ID3D11SamplerState *ppSamplerState = NULL;
    dev->CreateSamplerState(&desc, &ppSamplerState);
    devcon->PSSetSamplers(0, 1, &ppSamplerState);

//Create list vertices from RGB data buffer
    pW = bitmapSource->PixelWidth;
    pH = bitmapSource->PixelHeight;
    OurVertices = new VERTEX[pW*pH];    
    vIndex = 0;
    unsigned char* curP = rgbPixelsBuff;
    for (y = 0; y < pH; y++)
    {
        for (x = 0; x < pW; x++)
        {
            OurVertices[vIndex].Color.b = *curP++;
            OurVertices[vIndex].Color.g = *curP++;
            OurVertices[vIndex].Color.r = *curP++;
            OurVertices[vIndex].Color.a = *curP++;
            OurVertices[vIndex].X = x;
            OurVertices[vIndex].Y = y;
            OurVertices[vIndex].Z = 0.0f;
            vIndex++;
        }
    }
    sizeOfOurVertices = sizeof(VERTEX)* pW*pH;

    // copy the vertices into the buffer
    D3D11_MAPPED_SUBRESOURCE ms;
    devcon->Map(pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);    // map the buffer
    memcpy(ms.pData, OurVertices, sizeOfOurVertices);                 // copy the data
    devcon->Unmap(pVBuffer, NULL);     
    // unmap the buffer

    // clear the back buffer to a deep blue
    devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));

    // select which vertex buffer to display
    UINT stride = sizeof(VERTEX);
    UINT offset = 0;
    devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset);

    // select which primtive type we are using
    devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

    // draw the vertex buffer to the back buffer
    devcon->Draw(pW*pH, 0);

    // switch the back buffer and the front buffer
    swapchain->Present(0, 0);

When the viewport's size is smaller or equal the image's size => everything is ok. But when viewport's size is lager image's size => the image's quality is very bad.

I've searched and tried to use desc.Filter = D3D11_FILTER_ANISOTROPIC;as above code (I've tried to use D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR or D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINTtoo), but the result is not better. The following images are result of displaying:

enter image description here Someone can tell me the way to fix it.

Many thanks!

Upvotes: 0

Views: 1037

Answers (1)

VuVirt
VuVirt

Reputation: 1917

You are drawing each pixel as a point using DirectX. It is normal that when the screen size gets bigger, your points will move apart and the quality will be bad. You should draw a textured quad instead, using a texture that you fill with your RGB data and a pixel shader.

Upvotes: 1

Related Questions