-3
\$\begingroup\$

I would like some help with the following. At the moment when I draw the sprite I want it to be full black with no transparency, i.e. 255 alpha channel. But what I get is half transparency. How can I fix this ?

Here is my code:

bool Black_ImageToTexture(int texWidth, int texHeight, LPDIRECT3DTEXTURE9 pTexture, 
    int xPos, int yPos)
{
    D3DLOCKED_RECT lockedRect;
    // Lock the texture
    HRESULT hResult = pTexture->LockRect(0, &lockedRect, NULL, 0);

    if (FAILED(hResult)) {
        // Failed to lock the texture for whatever reason, cannot continue
        return true;
    }

    // Cast the image data to a BYTE pointer so we can easily step over the pitch
    BYTE *pBits = (BYTE*) lockedRect.pBits;

    // For each row:
    for (UINT y = 0; y < texHeight; ++y) {
        // Get a pointer to the start of this row of texels, 
        // and then advance to next row
        DWORD *pPixel = (DWORD*)pBits;
        pBits += lockedRect.Pitch;

        // Process this row (Swap R and B channels)
        for (UINT x = 0; x < texWidth; ++x) {
            (*pPixel) = 0xFF000000;
            pPixel++; // Next pixel
        }
    }

    pTexture - > UnlockRect(0);
    return true;
}

Finally, render it:

d3dspt->Draw(test_texture, NULL, &center, NULL, D3DCOLOR_ARGB(255, 255, 255, 255));

if(FAILED( D3DXCreateTexture(g_pd3dDevice_0, 1680, 1050,
    D3DX_SKIP_DDS_MIP_LEVELS(32,D3DX_DEFAULT), D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN,
    D3DPOOL_DEFAULT, &test_texture))) 
{ 
    handle_error_code(123238); 
    return E_FAIL; 
} 
else  { 
    Black_ImageToTexture(1680, 1050, test_texture, 0, 0); 
}
\$\endgroup\$
0
\$\begingroup\$

D3DX_SKIP_DDS_MIP_LEVELS(32, D3DX_DEFAULT), 32 should have been 1 instead .

\$\endgroup\$
  • \$\begingroup\$ Feel free to accept this answer if it fixed your problem. To do so, click on the gray checkmark below the up and down arrows. \$\endgroup\$ – Alexandre Desbiens Jun 11 '15 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.