Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Terrr

DirectDraw Bitmap loading

This topic is 6043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

***********************
          

Share this post


Link to post
Share on other sites
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

// 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]

Share this post


Link to post
Share on other sites
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:

  DDSCAPS2 ddscaps;  

Then instead of this:

  
// 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);
}
Do this:

  
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

***********************
          

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!