Archived

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

Leviathan569

Problem getting backbuffer

Recommended Posts

Leviathan569    122
Hi everybody, I''m new to DirectX and I''ve got a problem that''s driving me mad. I''m developing a C++ class for DirectDraw applications. When I want to get the backbuffer, the result always is DDERR_NOTFOUND. The code looks like this: HResult = PrimarySurface->GetAttachedSurface(&Caps,&BackBuffer); BackBuffer and PrimarySurface are both data members of my DD class. Initializing DirectDraw, getting the primary surface and setting the display mode works fine. Now here''s the weird part : I used exactly the same code in an application without classes and it worked fine. When I try to encapsulate my code into a C++ class, the thing stops working. What am I doing wrong? Please reply by e-mail. ------------------------ leviathan569@hotmail.com ------------------------

Share this post


Link to post
Share on other sites
Pyabo    124
Well, impossible to say what you''re doing wrong without seeing more of your code, BUT... why are you doing this? What are you trying to accomplish? Wouldn''t this sort of violate the point of having DDraw handle the backbuffering for you? I thought you always draw to the same surface...?

And here''s a quote from MSDN that might explain things:

"This method fails if more than one surface is attached that matches the capabilities requested. "

?

Share this post


Link to post
Share on other sites
Leviathan569    122
I''m just following my DirectX handbook. You create a primary surface and a backbuffer. You draw the screen image on the backbuffer and then you flip the backbuffer and the primary surface.

------------------------
leviathan569@hotmail.com
------------------------

Share this post


Link to post
Share on other sites
Leviathan569    122
Here''s more of my source code:

//-----------------------------------
//-- Create DirectDraw interface --
//-----------------------------------

HResult = DirectDrawCreateEx(NULL,
(LPVOID*),&DirectDraw,IID_IDirectDraw7,NULL);
if (HResult != DD_OK)
{
ErrStr = ERR_DD_CREATE;
return false;
}

//-----------------------------
//-- Set cooperative level --
//-----------------------------

HResult = DirectDraw->SetCooperativeLevel(HWindow,
DDSCL_FULLSCREEN|DDSCL_EXCLUSIVE|DDSCL_ALLOWREBOOT);
if (HResult != DD_OK)
{
ErrStr = ERR_COOP;
return false;
}

//------------------------
//-- Set display mode --
//------------------------

HResult = DirectDraw->SetDisplayMode(800,600,16,0,0);
if (HResult != DD_OK)
{
ErrStr = ERR_SETMODE;
return false;
}

//------------------------------
//-- Create primary surface --
//------------------------------

ZeroMemory(&SurfaceDesc,sizeof(SurfaceDesc)); SurfaceDesc.dwSize = sizeof(SurfaceDesc); SurfaceDesc.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT; SurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX;
SurfaceDesc.dwBackBufferCount = 1;
HResult = DirectDraw->CreateSurface(&SurfaceDesc,&PrimarySurface,NULL);
if (HResult != DD_OK)
{
ErrStr = ERR_CREATESURF;
return false;
}

//----------------------
//-- Get backbuffer --
//----------------------

Caps.dwCaps = DDSCAPS_BACKBUFFER;
HResult = PrimarySurface->GetAttachedSurface(&Caps,&BackBuffer);
if (HResult != DD_OK)
{
ErrStr = ERR_BACKBUFFER;
return false;
}

This works fine. But when I want to embed it in a class, the thing doesn''t work anymore. It works until the backbuffer part and there it fails.


------------------------
leviathan569@hotmail.com
------------------------

Share this post


Link to post
Share on other sites