DirectDraw Bitmap loading
Hi all,
I''m busy with some DirectDraw coding. I understand the theory, but I just can''t load a bitmap properly without having BltFst crashing on me.
Would anybody be so kind to post a simple function that can load a bitmap into a surface?
No problem By the way, BltFst doesn''t work with some things (like a directX clipper). Try blitting with regular Blt when you run into blitting problems before trying anything else. It could save you a lot of trouble.
***********************
***********************
I guess I found the problem
I threw in some error checking, and it seems that the backbuffer doesn't want to be created
I know my DirectX works perfectly.
Here is my init code
[edited by - Terrr on June 2, 2002 6:46:21 PM]
[edited by - Terrr on June 2, 2002 6:48:41 PM]
I threw in some error checking, and it seems that the backbuffer doesn't want to be created
I know my DirectX works perfectly.
Here is my init code
// Create the DirectDraw object. This is used for everything DD does if (FAILED(DirectDrawCreateEx(NULL, (LPVOID*)&lpDD, IID_IDirectDraw7, NULL))) { MessageBox(hwnd, ERROR_DIRECTDRAWOBJECT, ERROR_TITLE, MB_OK); return(false); } /* * The cooperative level determines how much control we have over the screen * This must at leasst be either DDSCL_EXLUSIVE or DDSCL_NORMAL * * DDSCL_EXCLUSIVE allows us to change video modes, and requires the DDSCL_FULLSCREEN flag, * which will cause the window to switch to Fullscreen. This is the preferred DD mode because * it allows us to have control of the whole screen without regard for GDI. * * DDSCL_NORMAL is used to allow the DD app to run windowed. */ if (FAILED(lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | // Exclusive mode DDSCL_FULLSCREEN | // Go Fullscreen DDSCL_ALLOWREBOOT))) // Allow Ctrl-alt-del { MessageBox(hwnd, ERROR_SETCOOPERATIVELEVEL, ERROR_TITLE, MB_OK); return (false); } // Set the display mode (resolution) if (FAILED(lpDD->SetDisplayMode(TERR_RESOLUTION_WIDTH, // Width of screen TERR_RESOLUTION_HEIGHT, // Height of screen TERR_RESOLUTION_COLORDEPTH, // Color depth 0, // ? 0))) // ? { MessageBox(hwnd, ERROR_SETDISPLAYMODE, ERROR_TITLE, MB_OK); return(false); } // Create the primary surface with 1 back buffer. Make it the height and width of the screen. // First, zero the memory used by the ddsd structure. // If you don't do this, it may have some random data that might mess up CreateSurface(). ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); // Second. DDSD_CAPS makes CreateSurface() check the ddsd.ddsCaps.dwCaps value. // DDSD_BACKBUFFERCOUNT makes it check the ddsd.dwBackBufferCount value. ddsd.dwFlags = DDSD_CAPS | // Capabilites DDSD_BACKBUFFERCOUNT; // Number of Back Buffers // Primary surface ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | // This is the primary surface DDSCAPS_FLIP | // Flippable DDSCAPS_COMPLEX; // Has a Back Buffer // One Back Buffer ddsd.dwBackBufferCount = 1; // Create it using the description in ddsd. if (FAILED(lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL))) { MessageBox(hwnd, ERROR_CREATESURFACE, ERROR_TITLE, MB_OK); return(false); } // Create the Back Buffer ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; if (FAILED(lpDDSPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpDDSBack))) { MessageBox(hwnd, ERROR_CREATEBACKBUFFER, ERROR_TITLE, MB_OK); return(false); } return(true); // Everything went A-Ok, return true}
[edited by - Terrr on June 2, 2002 6:46:21 PM]
[edited by - Terrr on June 2, 2002 6:48:41 PM]
Oh I''m sorry man. I had 2 gigs this weekend so I''ve been busy. Try declaring surface capabilities data type just for the back buffer creation like so:
Then instead of this:
Do this:
And that should do it. Sorry I didn''t post sooner. Hope that does the trick
***********************
DDSCAPS2 ddscaps;
Then instead of this:
// Create the Back Bufferddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;if (FAILED(lpDDSPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpDDSBack))){ MessageBox(hwnd, ERROR_CREATEBACKBUFFER, ERROR_TITLE, MB_OK); return(false);}
memset(&ddscaps, 0, sizeof(ddscaps));ddscaps.dwCaps = DDSCAPS_BACKBUFFER;if (FAILED(lpDDSPrimary->GetAttachedSurface(&ddsCaps, &lpDDSBack))){ MessageBox(hwnd, ERROR_CREATEBACKBUFFER, ERROR_TITLE, MB_OK); return(false);}
And that should do it. Sorry I didn''t post sooner. Hope that does the trick
***********************
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement