Archived

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

DirectDraw

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

//Load bitmap into an offscreen surface and displays it void TDXDraw::LoadTexture(const char* Filename,LPDIRECTDRAWSURFACE7 Surface){ Graphics::TBitmap* TempBitmap = new Graphics::TBitmap(); TempBitmap->LoadFromFile(Filename); ZeroMemory(&SurfaceDescriptor, sizeof(DDSURFACEDESC2)); SurfaceDescriptor.dwSize = sizeof(DDSURFACEDESC2); SurfaceDescriptor.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; SurfaceDescriptor.dwWidth = TempBitmap->Width; SurfaceDescriptor.dwHeight = TempBitmap->Height; SurfaceDescriptor.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN ; CheckDXError(DirectDraw->CreateSurface(&SurfaceDescriptor, &Surface, NULL),"TDXDraw.LoadTexture /Buffer creëren"); TCanvas* TempCanvas = new TCanvas(); TempCanvas->Brush->Color = clBlack; HDC Hdc; try{ CheckDXError(Surface->GetDC(&Hdc),"TDXDraw.LoadTexture /Surface handle verkrijgen"); TempCanvas->Handle = Hdc; TempCanvas->Draw(0,0,TempBitmap); }__finally{ TempCanvas->Handle = NULL; CheckDXError(Surface->ReleaseDC(Hdc),"TDXDraw.LoadTexture /Surface handle vrijgeven"); } delete TempBitmap; delete TempCanvas; CheckDXError(PrimarySurface->BltFast(10, 10, Surface, NULL, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT),"TDXDraw.LoadTexture /Schrijf naar scherm"); } //Displays an offscreen surface void TDXDraw::Draw(int x,int y, LPDIRECTDRAWSURFACE7 Surface){ HDC Hdc; ErrorCode = PrimarySurface->BltFast(x, y, Surface, NULL, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); if (ErrorCode == DDERR_SURFACELOST) CheckDXError(DirectDraw->RestoreAllSurfaces()); else CheckDXError(ErrorCode,"TDXDraw.Draw /Blitten van een surface"); } /* When calling: --> LPDIRECTDRAWSURFACE7 TempSurface; DXDraw->LoadTexture("try.bmp",TempSurface); DXDraw->Draw(10,10,TempSurface); <-- I always get an error "DirectDraw received a pointer that was an invalid DirectDraw object". I do not understand why. I''d appreciate it if anyone could help me. Thnx in advance. (btw, I am positive there is no problem with the CheckDXError() function!) */

Share this post


Link to post
Share on other sites
I don''t think you have to use the -> operator. i don''t think you even have to pass the directdraw object, at least i don''t. maybe i''ve confused you more, or else i didn''t understand what you were trying to do..

¬_¬

Share this post


Link to post
Share on other sites
I think your problem is in your LoadTexture function. Change it to this:

void TDXDraw::LoadTexture(const char* Filename, LPDIRECTDRAWSURFACE7 &Surface);

The address of TempSurface is passed to LoadTexture, but it''s passed by value. Thus, a copy is made of the address. The pointer in LoadTexture (Surface) is changed, but TempSurface is not. Thus, TempSurface still points to garbage when you try to use it. Using the address-of operator passes the address of the pointer, so it can be manipulated. So whenever you mean to change the surface (creation/destruction, etc.), use the & operator. I hope that made sense.

You shouldn''t have to make any other changes, but please slap me with a surgical 2x4 if I''m wrong.

Share this post


Link to post
Share on other sites
Thanx, that was exactly it. How come I didn''t see that?
I''ll pay more attention to passing variables by reference from now on.

Share this post


Link to post
Share on other sites