View Full Version : GenerateTexture function
Azorbix
04-29-2005, 10:14 PM
Simply you give it the rendering device, a texture interface, and a specified colour and it will generate a single coloured texture for you.
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{
if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)) )
return E_FAIL;
WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
|(WORD)(((colour32>>20)&0xF)<<8)
|(WORD)(((colour32>>12)&0xF)<<4)
|(WORD)(((colour32>>4)&0xF)<<0);
D3DLOCKED_RECT d3dlr;
(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
WORD *pDst16 = (WORD*)d3dlr.pBits;
for(int xy=0; xy < 8*8; xy++)
*pDst16++ = colour16;
(*ppD3Dtex)->UnlockRect(0);
return S_OK;
}
usage:
GenerateTexture(g_pD3Ddev, &g_pD3Dtexture, D3DCOLOR_ARGB(255, 0, 168, 255));
Jordon
04-30-2005, 02:11 AM
Dawg thats the shit thanks :banana: i am use this for sure, save me lot of time :laugh:
thanks Azo, this saves me a large chunk of filesize.. had the problem mentioned here - http://forum.game-deception.com/showthread.php?t=7272
for those interested (or lazy maybe:laugh: ) - d3d8 CreateTexture takes one less parameter than d3d9's, so here's the d3d8 version of Azorbix's code:
HRESULT GenerateTexture(IDirect3DDevice8 *pD3Ddev, IDirect3DTexture8 **ppD3Dtex, DWORD colour32)
{
if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex)) )
return E_FAIL;
WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
|(WORD)(((colour32>>20)&0xF)<<8)
|(WORD)(((colour32>>12)&0xF)<<4)
|(WORD)(((colour32>>4)&0xF)<<0);
D3DLOCKED_RECT d3dlr;
(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
WORD *pDst16 = (WORD*)d3dlr.pBits;
for(int xy=0; xy < 8*8; xy++)
*pDst16++ = colour16;
(*ppD3Dtex)->UnlockRect(0);
return S_OK;
}
Thanks Alot Azorbix this REALLY helps. :ditsy:
s0beit
05-18-2006, 11:53 AM
edit: solved, gj, im an idiot.
cool, useful for chams :-) ty.
Beats using D3DXCreateTextureFromFileInMemory.
Just wanted to let you guys know that this has helped me a lot.
Thanks :)
alolleranaskf
01-31-2007, 07:48 PM
Here's for masm32:
CreateColoredTexture proc pd3dDevice:DWORD, ppTexture:DWORD, color:DWORD
LOCAL LockedRect:D3DLOCKED_RECT
push ebx
mov ebx, ppTexture
ICall pd3dDevice::IDirect3DDevice9.CreateTexture, 1, 1, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, ebx, NULL
mov ebx, [ebx]
ICall ebx::IDirect3DTexture9.LockRect, 0, ADDR LockedRect, NULL, 0
mov eax, color
mov ecx, LockedRect.pBits
mov [ecx], eax
ICall ebx::IDirect3DTexture9.UnlockRect, 0
pop ebx
ret
CreateColoredTexture endp
I haven't tested it but it should work; remember, you need ObjAsm32.
R4z8r
05-31-2007, 06:12 PM
I still dont understand shi*t of asm :\
but Gj on the c++ one azorbix!!
battiboy
09-10-2012, 09:02 AM
Sorry to bump such an old thread, but I keep getting D3DERR_INVALIDCALL from CreateTexture. Any ideas?
Game is CSS btw.
Casual_Hacker
09-10-2012, 09:25 AM
Sorry to bump such an old thread, but I keep getting D3DERR_INVALIDCALL from CreateTexture. Any ideas?
Game is CSS btw.
http://www.gamedeception.net/threads/24396-Direct3D9Ex-and-D3DXCreateTextureFromFile
Powered by vBulletin® Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.