Jump to content
  • Advertisement

Archived

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

while1

LPDIRECTDRAWSURFACE question

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

I have a little problem with the LPDIRECTDRAWSURFACE7 type. Look at this:
  

class MySurf
{
  MySurf(LPDIRECTDRAWSURFACE7 p_tSurf) {m_tSurf = p_tSurf}; 
  LPDIRECTDRAWSURFACE7 m_tSurf;
};

std::vector<MySurf*> g_aArray;

  
Now in the main function should I do like this:
  

void main()
{
  LPDIRECTDRAWSURFACE* l_ptSurf;
  MySurf* l_pNewSurf = new MySurf(l_ptSurf);
  g_aArray.push_back(l_pNewSurf);
}

  
or like this:
  

void main()
{
  LPDIRECTDRAWSURFACE l_tSurf;
  MySurf* l_pNewSurf = new MySurf(&l_tSurf);
  g_aArray.push_back(l_pNewSurf);
}

  

Share this post


Link to post
Share on other sites
Advertisement
The problem is that you need to initialize the LPDIRECTDRAWSURFACE that you pass to the constructor, or create the surface inside the constructor. Use CreateSurface to create the surface; it will return an LPDIRECTDRAWSURFACE that you can use in your class.

So, you could do something like this:

  
void main(
{
LPDIRECTDRAWSURFACE* l_ptSurf;
DDSURFACEDESC ddsd;
HRESULT ddreturn;

// Create the surface as offscreen, system memory

// (not video memory).

// Assumes ''ddobj'' points to direct draw object.

ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd.ddsCaps.dwCaps =
DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
ddsd.dwHeight = Height; // Surface height

ddsd.dwWidth = Width; // Surface width

ddreturn = ddobj->CreateSurface(&ddsd, &l_ptSurf, NULL);
if (ddreturn != DD_OK)
exit(1); // Couldn''t create surface


MySurf* l_pNewSurf = new MySurf(l_ptSurf);
g_aArray.push_back(l_pNewSurf);
}

Share this post


Link to post
Share on other sites
MySurf takes a pointer to DirectDraw surface, not a pointer to pointer, so either way would be wrong.

I haven''t used DirectDraw that much, but I would guess that simple pointer would do. So second option would be correct, except you shouldn''t use & in front of l_tSurf, when creating MySurf.

So you would write:

void main()
{
LPDIRECTDRAWSURFACE l_tSurf;
/* create surface here, or do what you want... */
MySurf* l_pNewSurf = new MySurf(l_tSurf);
g_aArray.push_back(l_pNewSurf);
}

OldGuy:

Is that an error, or does CreateSurface() really take a pointer to pointer to pointer as a second argument? Wow!

Share this post


Link to post
Share on other sites
Sorry, it was a typo on my part; I copied the declaration of the LPDIRECTDRAWSURFACE from the original. It should be declared as ''LPDIRECTDRAWSURFACE'', not ''LPDIRECTDRAWSURFACE *''.

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!