Sign in to follow this  

Loading an Image with DirectX

This topic is 2817 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

One way:

1. Create a LPD3DXSPRITE object and initialize it
2. Create a LPDIRECT3DTEXTURE9 object and initialize it using D3DXCreateTextureFromFile or D3DXCreateTextureFromFileEx and the bitmap file
3. Use the LPD3DXSPRITE object to draw the texture

You can find info on how to do these things on MSDN.

Share this post


Link to post
Share on other sites

LPD3DXSPRITE d3dspt; // the pointer to our Direct3D Sprite interface
LPDIRECT3DTEXTURE9 sprite; // the pointer to the sprite

D3DXCreateSprite(gdevice, &d3dspt); // create the Direct3D Sprite object

D3DXCreateTextureFromFileEx(gdevice, // the device pointer
"Sprites//Menu//Panel2.png", // the new file name
D3DX_DEFAULT, // default width
D3DX_DEFAULT, // default height
D3DX_DEFAULT, // no mip mapping
NULL, // regular usage
D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
D3DPOOL_MANAGED, // typical memory handling
D3DX_DEFAULT, // no filtering
D3DX_DEFAULT, // no mip filtering
D3DCOLOR_XRGB(255, 0, 255), // the hot-pink color key
NULL, // no image info struct
NULL, // not using 256 colors
&sprite); // load to sprite

in Beginscene you need

d3dspt->Begin(D3DXSPRITE_ALPHABLEND); // // begin sprite drawing with transparency
// draw the sprite
D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner
D3DXVECTOR3 position(350.0f, 0.0f, 0.0f); // position at 50, 50 with no depth
d3dspt->Draw(sprite, NULL, ¢er, &position, D3DCOLOR_ARGB(127, 255, 255, 255));

d3dspt->End(); // end sprite drawing

Share this post


Link to post
Share on other sites
I added that and now I get these errors:

1>Universe Stick.obj : error LNK2019: unresolved external symbol _D3DXCreateTextureFromFileExW@56 referenced in function "long __cdecl InitWindow(struct HINSTANCE__ *,int)" (?InitWindow@@YAJPAUHINSTANCE__@@H@Z)
1>Universe Stick.obj : error LNK2019: unresolved external symbol _D3DXCreateSprite@8 referenced in function "long __cdecl InitWindow(struct HINSTANCE__ *,int)" (?InitWindow@@YAJPAUHINSTANCE__@@H@Z)

And I do have the DirectX Libraries linked.

Share this post


Link to post
Share on other sites

This topic is 2817 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this