Archived

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

furbyhater

[DDraw] Help with surface creation (Beginner)

Recommended Posts

Hi, this is my first post on the forum, my name''s Florian and I''m from Switzerland (where they make the cheese Right now I''m beginning DDraw with c++ (where I''m still quite a beginner too), and I have started writing a DDraw class, a wrapper of a sort, to facilitate casual operations. One of the member functions is a function wich takes a LPDIRECTDRAWSURFACE7 as a parameter and should create a offscreen surface & point to it with the given LPDIRECTDRAWSURFACE7. But somehow it doesn''t work, because when I check the pointer after having used the function, he''s invalid. Here''s the code: // bool bKey checks for color-keying, iMemFlags controls memory // allocation (system/video memory) ENUM_RESULT CDDraw::CreateOffscreen(int iWidth, int iHeight, bool bKey, LPDIRECTDRAWSURFACE7 lpSurface, int iMemFlags) { // clear ddsd and set size memset(&itsDdsd,0,sizeof(itsDdsd) ); itsDdsd.dwSize = sizeof(itsDdsd); // color-keyed surface or not if(!bKey) itsDdsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; else { itsDdsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT; // set the defined color key itsDdsd.ddckCKSrcBlt.dwColorSpaceLowValue = itsTransColor; itsDdsd.ddckCKSrcBlt.dwColorSpaceHighValue = itsTransColor; } itsDdsd.dwWidth = iWidth; itsDdsd.dwHeight = iHeight; itsDdsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | iMemFlags; // destroy previous surface, if valid if(lpSurface) { lpSurface->Release(); lpSurface = NULL; } if(FAILED(itsLpDD->CreateSurface(&itsDdsd, &lpSurface, NULL) ) ) { // error return(VID_ERR_CREATEOFFSCREEN); } return(OK); } Where itsLpDD points to a valid dd object. All the "its*" variables are class variables (of CDDraw), and I try to create the offscreen surface in another class, CMain, wich contains an instance of CDDraw ("itsVideo"), and a LP to a DD surface, "itsLpSprite". What I try to do looks like this: // Set the color key itsVideo.SetColorKey(255,0,255); // Create the sprite surface if ( (itsResult = itsVideo.CreateOffscreen( 64,64,true,itsLpSprite) ) != OK) { // error itsError.ShowMessage(itsWin.GetHwnd(), itsResult); } // check if valid surface has been created if(!itsLpSprite) { // error itsError.ShowMessage(itsWin.GetHwnd(), itsResult); } And each time, I get an invalid surface... Any advice/criticism (I''m sure there''s alot to critic is welcome...

Share this post


Link to post
Share on other sites