Loading an Image with DirectX
I am new to using DirectX, but does anyone know a function to display a bitmap image on the screen? If you can give me some code or a tutorial it would be lots of help. Thanks in advance!
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.
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.
LPD3DXSPRITE d3dspt; // the pointer to our Direct3D Sprite interfaceLPDIRECT3DTEXTURE9 sprite; // the pointer to the spriteD3DXCreateSprite(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 spritein Beginscene you needd3dspt->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
Now I'm getting linking errors:
1>Universe Stick.obj : error LNK2001: unresolved external symbol _D3DXCreateTextureFromFileExW@56
1>Universe Stick.obj : error LNK2001: unresolved external symbol _D3DXCreateSprite@8
1>Universe Stick.obj : error LNK2001: unresolved external symbol _D3DXCreateTextureFromFileExW@56
1>Universe Stick.obj : error LNK2001: unresolved external symbol _D3DXCreateSprite@8
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.
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.
Are you also linking to D3DX? The lib file is called d3dx9d.lib (for the debug version, which is probably what you're using).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement