Jump to content
  • Advertisement

Archived

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

rahulprasad

DirectDraw surfaces

This topic is 5224 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

Hey guys, Ok, I know this topic probably has not been addressed in years, but I''m trying to set up a double buffer system in DirectDraw7 but I cant seem to write to the primary surface (no blits, no direct access, nothing). The secondary (back) surface works fine, but for some reasom the primary one does not work at all. Any suggestions ? -Rahul

Share this post


Link to post
Share on other sites
Advertisement
Thanks cpprulz.

I already tried that though, and it does not work.

The primary surface is always white. The code I use to initialize DirectDraw is given below if it helps.

int BackBuffer::initialize(int width, int height)
{
// Initialize variables
lpDirectDraw = NULL;
lpPrimarySurface = NULL;
lpBackSurface = NULL;
primarySurface = NULL;
backSurface = NULL;
primarySurfacePitch = 0;
back_lpitch = 0;

// create IDirectDraw object and test for error
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpDirectDraw, IID_IDirectDraw7, NULL)))
return(0);

// set cooperation level to fullscreen mode
if (FAILED(lpDirectDraw->SetCooperativeLevel(hwnd,
DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_MULTITHREADED )))
return(0);

// set the display mode
if (FAILED(lpDirectDraw->SetDisplayMode(width, height ,WINDOW_COLOR_DEPTH ,0 ,0)))
return(0);

// Create the primary surface
memset(&surfaceDescription,0,sizeof(surfaceDescription));

surfaceDescription.dwSize = sizeof(surfaceDescription);
surfaceDescription.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
surfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
surfaceDescription.dwBackBufferCount = 1;

if (FAILED(lpDirectDraw->CreateSurface(&surfaceDescription,&lpPrimarySurface,NULL)))
{
writeError("CreateSurface FAILED");
return (0);
}
// get the pixel format of the primary surface
DDPIXELFORMAT ddpf; // used to get pixel format

// initialize structure
DDRAW_INIT_STRUCT(ddpf);

// query the format from primary surface
lpPrimarySurface->GetPixelFormat(&ddpf);

pixelFormat = ddpf.dwRGBBitCount;

// set up conversion macros, so you don''t have to test which one to use
if (pixelFormat == DD_PIXEL_FORMAT555)
{
RGB16Bit = RGB16Bit555;
}
else
{
RGB16Bit = RGB16Bit565;
}

// Get the backbuffer
memset(&surfaceCaps, 0, sizeof(surfaceCaps));
surfaceCaps.dwCaps = DDSCAPS_BACKBUFFER;
if (FAILED(lpPrimarySurface->GetAttachedSurface(&surfaceCaps,&lpBackSurface)))
return(0);

// Clear the buffers
clearBack(0);
clearPrimary(0);

// set software clipping region
minClipX = 0;
maxClipX = screenWidth - 1;
minClipY = 0;
maxClipY = screenHeight - 1;
writeError("Initialize completed");
return (1);
}

Share this post


Link to post
Share on other sites
Can you show me the code in clearBack(0) and clearPrimary(0)?
And the code used to do the blitting?

Share this post


Link to post
Share on other sites
Here is the code for clearPrimary

void BackBuffer::clearPrimary(int color)
{
writeError("Enter clearPrimary");

DDBLTFX ddbltfx;

// clear out the structure and set the size field
DDRAW_INIT_STRUCT(ddbltfx);

// set the dwfillcolor field to the desired color
ddbltfx.dwFillColor = color;

if (FAILED(lpPrimarySurface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
writeError("clearPrimary failed");
}

and for clearBack

void BackBuffer::clearBack(int color)
{
writeError("Enter clearBack");

DDBLTFX ddbltfx;

// clear out the structure and set the size field
DDRAW_INIT_STRUCT(ddbltfx);

// set the dwfillcolor field to the desired color
ddbltfx.dwFillColor = color;

if (FAILED(lpBackSurface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
writeError("clearBack failed");
}

Even at this point, the stuff fails because the primary surface is white, not black, and stays white no matter what I do on it, so I figured I would start with this. There are no other functions to do any blitting--I was writing directly to the surface.

-Rahul

Share this post


Link to post
Share on other sites
I tried the same code and it works for me.
But I used DirectDrawCreate(NULL,&DDraw,NULL);

Sorry I couldn''t help, but keep at it, try different colors.

Or just ditch DirectDraw7 and go Direct3D8 http://www.gamedev.net/reference/articles/article1020.asp

Good Luck!

Share this post


Link to post
Share on other sites
Thanks for trying!

Unfortunately, DirectDrawCreate(NULL,&DDraw,NULL); did not work for me either.

The primary surface still remains white, no matter what I do with colors etc.

I''m wondering whether its something to do with the video card of the machine I am using. However in that case, the back buffer should not work either (yet it does).

-Rahul

Share this post


Link to post
Share on other sites
From a very cursory look at your code I don't see any obvious problems... make sure you have the latest video drivers etc. etc. Do you have any DDraw apps on your computer that work fine? Do the samples in the SDK work (you might need to find the DX7 SDK for DDraw examples)?

[edited by - AndyTX on June 2, 2004 11:11:54 AM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!