Archived

This topic is now archived and is closed to further replies.

Creating a D3D texture without D3DXCreateTextureFromFile()

This topic is 5600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How could I create a texure without using D3DXCreateTextureFromFile() just using the raw colour data? The texture data I want is inside another format that I can read into memory easy enough but how do I turn that into a texture. Thanks

Share this post


Link to post
Share on other sites
This is a simple way, not necessarily the best way


  

LPDIRECT3DTEXTURE8 myTexture;
HRESULT returnvalue;
D3DLOCKED_RECT lr;

returnvalue = g_pd3dDevice->CreateTexture(width,
height, 1, 0 ,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &myTexture);

if (FAILED(returnvalue))
{
return E_FAIL;
}

returnvalue = myTexture->LockRect(0, &lr, NULL, 0);
if (FAILED(returnvalue)){
return E_FAIL;
}


UCHAR* pRect = (UCHAR*) lr.pBits;

long o=0;

// just memcpy your image to pRect here

// Remember to have your image in the same format as the texture


returnvalue = myTexture->UnlockRect(0);
if (FAILED(returnvalue)){
return E_FAIL;
}

Share this post


Link to post
Share on other sites
Thanks, that was a big help.

Still not quite working (it won''t let me use D3DFMT_R8G8B8 for some reason) but its getting closer.

Share this post


Link to post
Share on other sites