Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

How Can work with DirectX & LPDIRECT3DTEXTURE9

Help
2013-10-04
2013-11-13
  • sampad abbas
    sampad abbas
    2013-10-04

    hello to all
    i need to use FreeImage to load image & render this image with directx so need to create LPDIRECT3DTEXTURE9 but i don't know to how do this,please help me?

     
  • sampad abbas
    sampad abbas
    2013-11-13

    finally i found a code that work probably:
    void CreateTexture(const wchar_t filename)
    {
    FreeImage_Initialise();
    byte
    bitmap;

    unsigned int type = 0, num = 3;
    
    FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeU(filename);
    if (fif == FIF_UNKNOWN)
        return;
    FIBITMAP *dib = FreeImage_LoadU(fif, filename);
    type = FreeImage_GetBPP(dib);
    if (type != 32)
    if (!dib&&!(dib = FreeImage_ConvertTo32Bits(dib)))
        return;
    int Width = FreeImage_GetWidth(dib);
    int Height = FreeImage_GetHeight(dib);
    type = FreeImage_GetBPP(dib);
    FreeImage_FlipVertical(dib);
    //(filename, bitmap, width, height); // Wrapped FreeImage
    
    // Create empty IDirect3DTexture9*
    g_pd3dDevice->CreateTexture(Width, Height, 1, 0,
        D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &g_pTexture, 0);
    if (!g_pTexture)
    {
        //throw std::("CreateTexture failed");
    }
    bitmap = (byte*) FreeImage_GetBits(dib);
    D3DLOCKED_RECT rect;
    g_pTexture->LockRect(0, &rect, 0, D3DLOCK_DISCARD);
    byte* dest = (byte*) (rect.pBits);
    memcpy(dest, bitmap, sizeof(unsigned char) * Width * Height * 4);
    g_pTexture->UnlockRect(0);
    

    }