I am here to show you how to draw sprites. Please, thank me if I helped you.
First, we shall define our byte array. In drawing sprites, a byte array is required to draw from. To convert an image into a byte array, I take a hex editor and open the image in it. I then copy all of the bytes, and run them in my custom made program. What would be easier for you is to just google a 'file to byte array converter' and use one. NOTE: This will be INSANELY long bytes since its defining an image.
After we are through with the byte array conversion and blah, we define it in our code. In this example, we are defining it in a header file called "Sprites.h":
Code:
#ifndef _CSPRITES_H
#define _CSPRITES_H
BYTE Sprite_Byted[] = { 0x89 , 0x50 , 0x4e , 0x47 , 0x0d , 0x0a , 0x1a , 0x0a , 0x00 , 0x00 , 0x00 , 0x0d , 0x49 }; //replace with your byte ;) mine was longer, but it would've taken up a page of code, haha
#endif
Now then, that is our header file.
After we are done with our header file, its time to write some real code. In this part, it creates the sprite so that it is ready to be drawn. I put this into my file that defined my D3DMenu structs.
Code:
D3DXVECTOR3 pSprite;
LPDIRECT3DTEXTURE9 texSprite;
LPD3DXSPRITE sSprite;
#include "Sprites.h"
void CreateSprite(LPDIRECT3DDEVICE9 pDevice)
{
pSprite.x=0.0f; pSprite.y=0.0f; pSprite.z=0.0f; // SPRITES POSITION
if(texSprite == NULL)D3DXCreateTextureFromFileInMemoryEx(pDevice
,&Sprite_Byted,sizeof(Sprite_Byted),135,500,D3DX_DEFAULT,0,D3DFMT_UNKNOWN // (135,500) are the X and Y size of the sprite. :)
,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,0,NULL,NULL,&texSprite);
if(sSprite==NULL) D3DXCreateSprite(pDevice, &sSprite);
}
The next bit of code goes into where it shows/hides the menu. Put it after the code where it checks if the menu is supposed to be drawn or not (visible/not visible). This is the most important part.
Code:
CreateSprite(pDevice);
sSprite->Begin(D3DXSPRITE_ALPHABLEND);
sSprite->Draw(texSprite, NULL, NULL, &pSprite, 0xFFFFFFFF);
sSprite->End();
sSprite->OnLostDevice();
sSprite->OnResetDevice();
Voila, you now have spiced up your menu with a background. Thanks button is below
If you have problems, just PM me or reply in this thread. This HAS been tested several times in some of my D3Ds and each time has worked.