Skip to main content
GameDev.net gamedev.net
🔒 Locked

Offscreen surface to back blit help.

Started by Viri- Oct 13, 2000 at 10:48 AM 2 replies 350+ views
Original Post
Viri-
Viri-
Basicly I''m having a lot of trouble getting the thing to blt from the off screen surface to the back surface. I can copy and load and blt full screen backgrounds but thats all. Here is my code: Any help is greatly appreciated. -------------------------------------------------------------- The Code: // \/---In a loop that occurs every frame LPDIRECTDRAWSURFACE lpddsTest; CreateBitmapSurface(lpddsTest, "aship.bmp", 128, 128); RECT aRect; SetRect(&aRect, 0, 0, 128, 128); lpddsback->Blt(&aRect, lpddsTest, &aRect, DDBLT_WAIT, NULL); lpddsTest->Release(); /////////////////////////////////////////////////////////// void CreateSurface(LPDIRECTDRAWSURFACE *lpSource, int xs, int ys) { DDSURFACEDESC ddsd; ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = xs; ddsd.dwHeight = ys; lpdd->CreateSurface(&ddsd, lpSource, NULL); } //////////////////////////////////////////////////////////////// void DrawHBitmap(IDirectDrawSurface *lpSurface, HBITMAP hBitmap, int x, int y, int width, int height) { HDC hdcImage; HDC hdc; BITMAP bm; if (lpSurface == NULL || hBitmap == NULL) return; lpSurface->Restore(); hdcImage = CreateCompatibleDC(NULL); SelectObject(hdcImage, hBitmap); GetObject(hBitmap, sizeof(bm), &bm); width = width == 0 ? bm.bmWidth : width; height = height == 0 ? bm.bmHeight : height; lpSurface->GetDC(&hdc); BitBlt(hdc, x, y, width, height, hdcImage, 0, 0, SRCCOPY); lpSurface->ReleaseDC(hdc); DeleteDC(hdcImage); } //////////////////////////////////////////////////////////////// void CreateBitmapSurface(LPDIRECTDRAWSURFACE lpSurface, char *fname, int xs, int ys) { HBITMAP hBitmap; CreateSurface(&lpSurface, xs, ys); hBitmap = LoadImage(NULL, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); DrawHBitmap(lpSurface, hBitmap, 0, 0, xs, ys); DeleteObject(hBitmap); }
------------thanks,Phoenix
Ridcully
Ridcully
well, i skipped over your code and can''t find anything significantly wrong. perhaps it will help if you describe the type of problem you incur?

oh, but one thing: do not create and release your surface every frame. create it once, and release it when you don''t need it anymore. otherwise you will have a very huge performance impact, mainly due to GDI i suppose...

rid
DJ_House
DJ_House
You may want to try using the MS provided DDraw functions for loading bitmaps. The files are ddutil.cpp and ddutil.h. They can be found with the DirectX SDK sample files. So assuming that the back buffer is attached to the primary surface and you have these variables
LPDIRECTDRAW7 lpdd;
LPDIRECTDRAWSURFACE7 lpddPrimarySurface;
LPDIRECTDRAWSURFACE7 lpddBackBuffer;
LPDIRECTDRAWSURFACE7 lpddOffscreen1;

We can use:


RECT rect;
SetRect(▭, 0, 0, 64, 64);
lpddOffscreen1 = DDLoadBitmap(lpdd, "bitmap.bmp", 0, 0);
lpddBackBuffer->BltFast(0, 0, lpddSOne, ▭, BLTFAST_NOCOLORKEY);
lpddPrimarySurface->Flip(NULL, 0);


That should blt the image to the backbuffer grabbing on the area you specified from it in rect.


Viri-
Viri-
It is not required to lock the screen for the blt is it? When I the screen goes to full screen mode Its just shutting strait down. I''m going to put in a Error write system into the library and goign to change to DX7''s util functions. Thanks,
Viri-
------------thanks,Phoenix

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.