Not able to draw a simple sprite

Started by
5 comments, last by longbough 15 years, 6 months ago
Hello everybody, I want to draw a simple sprite in a window, but I wasted the last hours with this. I´m following the tutorials on directxtutorial.com. Actually this one here: http://www.directxtutorial.com//Tutorial9/D-GameDisplay/dx9D1.aspx Everything works fine, no compile errors no warnings. Nothing! But if I run the compiler to see it, a black window opens. I read and followed every tutorial before and everything works fine. I could draw and transform vertices and meshes, but simple sprites are not possible. Does anybody have an idea about this? I searched google and this forum before but nothing helped.These two didn´t helped me either. http://members.gamedev.net/jhoxley/directx/DirectXForumFAQ.htm#D3D_7 http://members.gamedev.net/jhoxley/directx/DirectXForumFAQ.htm#D3D_22 I know its something simple, but i cannot find it. Thanks a lot. longbough
Advertisement
Hi,
Do you check the return values, when you create the sprite, the texture, etc ? Does everything look fine when you debug the application step by step ?

I tried something like this

if(FAILED(d3d = Direct3DCreate9(D3D_SDK_VERSION)))
{
MessageBox(NULL, L"The Direct3DCreate9 function failed", L"Error", MB_OK);
PostQuitMessage(0);
}

and played a lot with all debug settings i found in some debug-tutorials, but nothing helped. Its hard for me, to get into debugging, because i am still a noob at this.

Finally I found two errors in the debugger.

1.First, he tells me, that he doesn´t find my Sprite File.
I have only one cpp and one png file in the same folder.
This is my code for the png.
D3DXCreateTextureFromFile(d3ddev, L"Panel1.png", &sprite);

2.Some thousand times he printed this line:
D3DX: pTexture pointer is invalid

Have you set the correct "Working Directory" in the project properties ? You can also try with the full path of the texture file.
The second error is only a consequence : if the texture creation failed, then the pointer is invalid and you can't use it.
if you're using VC++ which I'm assuming you are, then while you're running through the IDE the paths are relative to the directory of the solution file, when you're running the app through the EXE file itself, the paths have to be relative to the EXE. Try running the EXE and see if it still won't show up. Otherwise, try copying the png to the directory of the solution file.

-Alex

Thank you both for your replies.

It was the solution/exe directory thing. I copied the png in the exe folders, so the exe´s worked. The same with the solution folder and the IDE.
But how can I build the png in the exe?
All the tutorials I saw, put the sprites into the IDE directories on the left(ccp, .h, resources).

Thank you again and have a nice Sunday

longbough

This topic is closed to new replies.

Advertisement