Original Post
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]