___RJ___ Moderator
Posts : 15 Join date : 2012-01-18 Age : 32 Location : Cebu
| Subject: Drawing Sprite Fri Jan 27, 2012 4:49 pm | |
| - Quote :
- ill show u how this can be done, im using it and works really good:
u'll need to detour Reset and Present/ES/BS
Some Globals:
- Code:
-
LPDIRECT3DTEXTURE9 TextureMenu; //Texture for ur menu LPD3DXSPRITE Sprite; //sprite to draw
//draw sprite function #define flt (float) void DrawTexture(int x, int y, LPDIRECT3DTEXTURE9 dTexture) { Sprite->Begin(D3DXSPRITE_ALPHABLEND); Sprite->Draw(dTexture,NULL,NULL,&D3DXVECTOR3(flt x,flt y, 0.0f), 0xFFFFFFFF); Sprite->End(); return; }
first of all create ur reset sprite/texture functs:
- Code:
-
void PreSprite() { if (Sprite && TextureMenu) //if they arent null { Sprite->OnLostDevice(); //release Sprite = NULL; //null ptr TextureMenu->Release(); //release TextureMenu = NULL; //null ptr } }
void PostSprite(LPDIRECT3DDEVICE9 pDevice) { D3DXCreateSprite(pDevice, &Sprite); //create sprite D3DXCreateTextureFromFileInMemory(pDevice, &myMenu, sizeof(myMenu), &TextureMenu); //create texture menu (i do that from file in memory) if (Sprite) //if sprite isnt null { Sprite->OnResetDevice(); //reset } }
now where ur drawing (Present/ES/BS): - Code:
-
if (Sprite==NULL) //if sprite is null PostSprite(pDevice); //recreate it else DrawTexture(100,100,TextureMenu);
and finally in Reset:
- Code:
-
HRESULT WINAPI hhkReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* Pars) { PreSprite(); HRESULT hrtn = oReset(pDevice, Parsi); return hrtn; }
remember u have to reset/release/recreate ur fonts,textures and sprites, to make them working in CA, and i suggest to use CD3DFont to avoid text-disappearing and checking for device changes
credits to me
|
|