Skip to main content
gamedev.net
🔒 Locked

(SOLVED)D3DXLoadSurfaceFromFile problem!

Started by coldness 5 replies 3k views
Original Post
coldness
coldness
Hello everyone! I want to apologize in advance if this question's been asked and/or answered! I searched, but to no avail. My problem is when I try to use the D3DXLoadSurfaceFromFile() function to try and "Blit" an image to a created surface object (actually, a pointer, but who cares about technicalities...). I'm reading "Beginning Game Programming" by Jonathan S. Harbour. In chapter 6 "Bitmaps and Surfaces", he shows how to create surfaces and load them with images using D3DXLoadSurfaceFromFile() function and then StrechRect() them to the backbuffer... I followed his code to the letter, but the image doesn't load at all! I even tried to see where the problem is, so I always setup some MessageBoxes in the problematic areas to see what's wrong exactly.. (Don't know how to use the Debugger that well).. So, what's the problem here? PS: Here's the Game_Init() Function I used (inspired by the one in the book)... int Game_Init(HWND hWnd) { HRESULT result; MessageBox(hWnd,"D3D is about to start", "D3D", MB_OK); d3d = Direct3DCreate9(D3D_SDK_VERSION); if(d3d == NULL) { MessageBox(hWnd, "Error initializing D3D", "ERROR", MB_OK); return 0; } D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = false; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = SCREEN_WIDTH; d3dpp.BackBufferHeight = SCREEN_HEIGHT; d3dpp.hDeviceWindow = hWnd; d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice); if(d3dDevice == NULL) { MessageBox(hWnd,"Error Creating D3D Device", "Device Error", MB_OK); return 0; } srand(time(NULL)); d3dDevice->Clear(0,NULL,D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); d3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer); result = d3dDevice->CreateOffscreenPlainSurface(640,480,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT, &d3dsurface, NULL); if(result != D3D_OK) return 1; if(result == D3D_OK) MessageBox(hWnd,"YES! Created surface!",NULL,MB_OK); result = D3DXLoadSurfaceFromFile(d3dsurface,NULL,NULL,"16.bmp",NULL,D3DX_DEFAULT,0,NULL); if(result != D3D_OK) { MessageBox(hWnd,"WTF?! Image didn't load!",NULL,MB_OK); return 1; } if(result == D3D_OK) MessageBox(hWnd,"YES! Loaded image!",NULL,MB_OK); d3dDevice->StretchRect(d3dsurface,NULL,backbuffer,NULL,D3DTEXF_NONE); return 1; } void Game_Run(HWND hWnd) { if(d3dDevice == NULL) return; if(d3dDevice->BeginScene()) { // d3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); d3dDevice->StretchRect(d3dsurface,NULL,backbuffer,NULL,D3DTEXF_NONE); //d3dDevice->StretchRect(d3dsurface,NULL,backbuffer,NULL,D3DTEXF_NONE); d3dDevice->EndScene(); } d3dDevice->Present(NULL, NULL, NULL, NULL); if(KEY_DOWN(VK_ESCAPE)) PostMessage(hWnd,WM_QUIT,0,0); } [Edited by - coldness on October 12, 2008 8:28:43 PM]
ET3D
ET3D
I'd suggest that you enable the debug runtime from the DirectX Control Panel application (one of the SDK utilities). In the Direct3D 9 tab choose "Use Debug Version of Direct3D 9". You can also check "Break on D3D9 Error". With the debug runtime enabled, you will get errors printed to the output panel of Visual Studio, and will likely find the problem that way.
coldness
coldness
I tried using the DX debugger, but the output flew right over my head! I don't understand a single line!

I think the problem lies in the D3DXLoadSurfaceFromFile function... Or quite possibly the whole D3DX library! I tried the D3DXGetImageInfoFromFile function, but it always fails! I don't know what's wrong here :(

If uploading my whole project would help, I'd do it. (I won't do that until asked to because of my speed limitaion).



PS: Here's the DX output...



Direct3D9: (WARN) :driver set D3DDEVCAPS_TEXTURENONLOCALVIDMEM w/o DDCAPS2_NONLOCALVIDMEM:turning off D3DDEVCAPS_TEXTURENONLOCALVIDMEM
D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO
Direct3D9: (INFO) :======================= Hal SWVP device selected

Direct3D9: (INFO) :HalDevice Driver style 8

Direct3D9: (WARN) :driver set D3DDEVCAPS_TEXTURENONLOCALVIDMEM w/o DDCAPS2_NONLOCALVIDMEM:turning off D3DDEVCAPS_TEXTURENONLOCALVIDMEM
'Beginning 3D.exe': Loaded 'C:\Windows\System32\IconCodecService.dll', No symbols loaded.
'Beginning 3D.exe': Loaded 'C:\Windows\System32\WindowsCodecs.dll', No symbols loaded.
Direct3D9: (INFO) :Using P4 PSGP

Direct3D9: (INFO) :Using FF to VS converter in software vertex processing

The thread 'Win32 Thread' (0xe14) has exited with code 0 (0x0).
Direct3D9: (ERROR) :Memory still allocated! Alloc count = 107
Direct3D9: (ERROR) :Current Process (pid) = 00000ec8
Direct3D9: (ERROR) :Memory Address: 013e07f4 lAllocID=1 dwSize=00004bc4, ReturnAddr=72e199aa (pid=00000ec8)
Direct3D9: (ERROR) :Memory Address: 013e573c lAllocID=3 dwSize=00000c28, ReturnAddr=72e229d1 (pid=00000ec8)
Direct3D9: (ERROR) :Memory Address: 013e639c lAllocID=5 dwSize=000011b8, ReturnAddr=72e1b244 (pid=00000ec8)
Direct3D9: (ERROR) :Memory Address: 013e758c lAllocID=8 dwSize=00000dec, ReturnAddr=72e0fd1b (pid=00000ec8)
Direct3D9: (ERROR) :Memory Address: 013e83ac lAllocID=9 dwSize=00003ea8, ReturnAddr=72e199aa (pid=00000ec8)
Direct3D9: (ERROR) :Memory Address: 013ec28c lAllocID=10 dwSize=00000198, ReturnAddr=72e199aa (pid=00000ec8)
Direct3D9: (ERROR) :Memory Address: 013e53ec lAllocID=11 dwSize=00000030, ReturnAddr=72e199aa (pid=00000ec8)
Direct3D9: (ERROR) :Memory Address: 013ec45c lAllocID=12 dwSize=00001020,
Direct3D9: (ERROR) :Total Memory Unfreed From Current Process = 1250075 bytes
The program '[3784] Beginning 3D.exe: Native' has exited with code 0 (0x0).


I deleted most of the output cuz it would have cluttered the screen otherwise!

Please help me!
coldness
coldness
Now I tried to use D3DXLoadTextureFromFile instead, but it doesn't work either! I'm really down, please help me or I will be forced to leave gaming programming due to these errors and the lack of your support!
Evil Steve
Evil Steve
Quote:
Original post by coldness
I tried using the DX debugger, but the output flew right over my head! I don't understand a single line!

I think the problem lies in the D3DXLoadSurfaceFromFile function... Or quite possibly the whole D3DX library! I tried the D3DXGetImageInfoFromFile function, but it always fails! I don't know what's wrong here :(

If uploading my whole project would help, I'd do it. (I won't do that until asked to because of my speed limitaion).
There's either no function failing, or you stripped it out of the output. Can we see the whole output, in [ /source ] tags?

If any D3D or D3DX function fails, the debug output will tell you as such.

EDIT: I'd also be quite concerned by those driver warnings - that says that the driver is buggy. I'd strongly recommend getting the latest drivers for your graphics card.
ArthY303
ArthY303
Do you get the "YES! Loaded image!" MessageBox() ?
coldness
coldness
I'm sorry it took me this long to reply, but my CPU's fan was busted! I had to buy a new one hence the delay.

As for my problem, I think I've fixed it! My Graphics card driver has no support for Vista (yes, I'm using Vista :( ).

I guess the problem was a combination of faulty code (from the book) and\or Vista...

I had to start from scartch and implement my own version of the code the book was addressing. I guess I ended up solving the problem in the process! The D3DXLoadSurfaceFromFile function now works!

Thanks very much for your support and I hope this little "adventure" will be our first together ;)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.