#define WIN32_LEAN_AND_MEAN
#define INITGUID
#include <windows.h>
#include <ddraw.h>
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define _RGB32BIT(a,r,g,b) ((b) + ((g) << 8) + ((r) << 16) + ((a) << 24))
#define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); }
#define CLASS_NAME "myclass"
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 32
LPDIRECTDRAW7 lpdd = NULL;
LPDIRECTDRAWSURFACE7 lpddsprimary = NULL;
LPDIRECTDRAWSURFACE7 lpddsbackbuffer = NULL;
LPDIRECTDRAWSURFACE7 lpddsbackground = NULL;
DDSURFACEDESC2 ddsd;
DDSCAPS2 ddscaps;
HWND window_handle;
BOOL window_closed = 0;
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
int DDraw_Draw_Surface(LPDIRECTDRAWSURFACE7 source, int x, int y, int width, int height, LPDIRECTDRAWSURFACE7 dest, int transparent);
LPDIRECTDRAWSURFACE7 DDraw_Create_Surface(int width, int height, int mem_flags, int color_key);
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;
HDC hdc;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&winclass);
hwnd = CreateWindowEx(NULL, CLASS_NAME, "MyDD", WS_POPUP | WS_VISIBLE, 0, 0, SCREEN_WIDTH,SCREEN_HEIGHT, NULL, NULL, hinstance, NULL);
window_handle = hwnd;
//Game_Init();
DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL);
lpdd->SetCooperativeLevel(window_handle,DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);
lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0);
DDRAW_INIT_STRUCT(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.dwBackBufferCount = 1;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL);
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsbackbuffer);
lpddsbackground = DDraw_Create_Surface(640,480,0,-1);
/////////////////////////////////////////////////////////////////
HBITMAP hbmbackground;
HDC hdcbackground = CreateCompatibleDC(hdc);
hbmbackground = (HBITMAP)LoadImage(hinstance, "background.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
hdc = CreateCompatibleDC(GetDC(hwnd));
BitBlt(hdc, 0, 0, 640, 480, hdcbackground, 0, 0, SRCCOPY);
////////////////////////////////////////////////////////////////
//lpddsbackground->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
//lpddsbackground->Unlock(NULL);
while(TRUE)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//Game_Main();
if(window_closed == 1)return(0);
if(KEYDOWN(VK_ESCAPE)){PostMessage(window_handle,WM_CLOSE,0,0);window_closed=1;}
//Lock the back buffer
//lpddsbackbuffer->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
//Get pointers to the pitch and the backbuffer
int lpitch32 = (int)(ddsd.lPitch >> 2);
UINT *backbuffer = (UINT *)ddsd.lpSurface;
//Clear the backbuffer
memset(backbuffer, 0, SCREEN_WIDTH*SCREEN_HEIGHT*4);
//Unlock the back buffer
lpddsbackbuffer->Unlock(NULL);
//Flip the back buffer to the display
while(FAILED(lpddsprimary->Flip(NULL,DDFLIP_WAIT)));
}
//Game_Shutdown();
return(msg.wParam);
}
Loading a background bitmap into an offscreen DDraw surface
I am trying to load a 640x480x24 bit background image to its own DirectDraw surface. I can set up DirectDraw and get the primary and backbuffer and I also know how to set up an offscreen surface. I've been using the windows GDI function LoadImage() to get the image but then I don't know how to draw that to the DirectDraw surface that I have reserved for it. I tried BitBlt but I don't know what to use for the destination DC. The stuff I am having problems with I put between /////'s. Thanks
[edit]
Washu: turned 'em into source tags.
[/edit]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement