Archived

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

Direct Draw annoying me...

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

Hello im new here, but i''ve been trying to learn this thing called ''game development'' and recently ive been frustrated with this piece of code, which is a mish-mash of a few tutorials found on gamedev.net. When i compile and run it, there are 0 errors or warnings, but it does not make a window! can anyone help? heres the code: (ps im really sorry for the formatting but thats what it does when i copy-paste it into the message box...) // Includes #include #include #include // Constants #define WIN32_LEAN_AND_MEAN // Macros #define INIT_DXSTRUCT(dxstruct) { ZeroMemory(&dxstruct, sizeof(dxstruct)); dxstruct.dwSize = sizeof(dxstruct); } /////////////////// G L O B A L S //////////////////// //Windows HINSTANCE hMainInstance; HWND hMainWindow; //Direct Draw LPDIRECTDRAW7 lpdd7 = NULL; LPDIRECTDRAWSURFACE7 lpddsPrimary = NULL; LPDIRECTDRAWSURFACE7 lpddsBack = NULL; LPDIRECTDRAWSURFACE7 lpddsImage = NULL; LPDIRECTDRAWCLIPPER lpddClipper = NULL; DDSURFACEDESC2 ddsd; // Prototypes LRESULT CALLBACK MsgHandler(HWND, UINT, WPARAM, LPARAM); int initialize(void); void Shutdown(void); ///////////////////////////////// WinMain //////////////////////////////// int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX Game; HWND hwnd; MSG msg; Game.cbSize = sizeof(WNDCLASSEX); Game.style =CS_DBLCLKS | CS_OWNDC | CS_HREDRAW |CS_VREDRAW; Game.lpfnWndProc = MsgHandler; Game.hInstance = hinstance; Game.cbClsExtra = 0; Game.cbWndExtra = 0; Game.hIcon = LoadIcon(NULL, IDI_WINLOGO); Game.hCursor = LoadCursor(NULL, IDC_ARROW); Game.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH); Game.lpszMenuName = NULL; Game.lpszClassName ="TME Class"; Game.hIconSm = LoadIcon(NULL, IDI_WINLOGO); if (initialize()) { if (!RegisterClassEx(&Game)) return (0); if (!(hwnd = CreateWindowEx (NULL, "TME Class", "Clipping and Scaling Demo", WS_POPUP | WS_VISIBLE, 0, 0, 640, 480, NULL, NULL, hinstance, NULL))) return(0); if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Shutdown(); return 0; } LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if (msg == WM_PAINT) { PAINTSTRUCT ps; HDC hdc; // display device context for graphics calls hdc = BeginPaint(hMainWindow, &ps); // validate the window // your painting goes here! EndPaint(hMainWindow, &ps); // release the DC // tell Windows we took care of it return(0); } return(DefWindowProc(hwnd, msg, wparam, lparam)); } /////////////////////////////////////////////////////////////// // INITIALIZE // Creates all the DirectX objects we''ll need for this demo, // sets the screen resolution to 640x480x16. /////////////////////////////////////////////////////////////// int initialize(void) { // initialize COM if (FAILED(CoInitialize(NULL))) return(FALSE); // create DirectDraw object if (FAILED(CoCreateInstance(CLSID_DirectDraw, NULL, CLSCTX_ALL, IID_IDirectDraw7, (void**)&lpdd7))) return(FALSE); // initialize DirectDraw object if (FAILED(lpdd7->Initialize(NULL))) return(FALSE); // set cooperative level to fullscreen if (FAILED(lpdd7->SetCooperativeLevel(hMainWindow, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))) return(FALSE); // hide the mouse ShowCursor(FALSE); // set 640x480x16 resolution if (FAILED(lpdd7->SetDisplayMode(640, 480, 16, 0, 0))) return(FALSE); // create our primary surface INIT_DXSTRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if (FAILED(lpdd7->CreateSurface(&ddsd, &lpddsPrimary, NULL))) return(FALSE); // create the back buffer INIT_DXSTRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = 640; ddsd.dwHeight = 480; if (FAILED(lpdd7->CreateSurface(&ddsd, &lpddsBack, NULL))) return(FALSE); // create the clipper if (FAILED(lpdd7->CreateClipper(0, &lpddClipper, NULL))) return(FALSE); // create and set the clip list LPRGNDATA lpClipList = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER) + sizeof(RECT)); RECT rcBoundary = {0, 0, 640, 480}; memcpy(lpClipList->Buffer, &rcBoundary, sizeof(RECT)); // set list lpClipList->rdh.dwSize = sizeof(RGNDATAHEADER); // structure size lpClipList->rdh.iType = RDH_RECTANGLES; // bound type lpClipList->rdh.nCount = 1; // num of bounds lpClipList->rdh.nRgnSize = sizeof(RECT); // size of Buffer lpClipList->rdh.rcBound = rcBoundary; // bounding RECT if (FAILED(lpddClipper->SetClipList(lpClipList, 0))) { // always free the mallocs! free(lpClipList); return(FALSE); } // attach clipper to back buffer if (FAILED(lpddsBack->SetClipper(lpddClipper))) { free(lpClipList); return(FALSE); } // free the memory free(lpClipList); // create the image surface (image is 200x200) INIT_DXSTRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = 200; ddsd.dwHeight = 200; if (FAILED(lpdd7->CreateSurface(&ddsd, &lpddsImage, NULL))) return(FALSE); // load the image onto the surface // all set! return(TRUE); } /////////////////////////////////////////////////////////////// // SHUTDOWN // Release the objects we created. /////////////////////////////////////////////////////////////// void Shutdown(void) { if (lpddsImage) { // murder the image surface! lpddsImage->Release(); lpddsImage = NULL; } if (lpddClipper) { // obliterate the clipper! lpddClipper->Release(); lpddClipper = NULL; } if (lpddsBack) { // annihilate the back buffer! lpddsBack->Release(); lpddsBack = NULL; } if (lpddsPrimary) { // kill the primary surface! lpddsPrimary->Release(); lpddsPrimary = NULL; } if (lpdd7) { // blow away DirectDraw! lpdd7->Release(); lpdd7 = NULL; } // destroy the window! CloseWindow(hMainWindow); // assassinate COM! CoUninitialize(); } bah.

Share this post


Link to post
Share on other sites
Here''s a tip: stick to one thing at once. You say you''re trying to get a window to appear? Well, why in the world did you include all of the code for your clipping, call back functions, initialization and shutdown? It seems to me you don''t have a good grasp on what the code is doing. My suggestion is you get a program that does JUST what you want to do, and that is make a window appear. Once you get that to work, start adding in one thing at once. Don''t try to throw together a million things and then wonder why it''s not working.

--Vic--

PS: Oh, and one thing. When you put up a big post like this, you''ll almost never get any responses. Another reason you should try to locate your problem by working with one thing at once.

Share this post


Link to post
Share on other sites
You''re one lucky man, I''m just messing with my window creation code too.And I think I konw your problem ^^.

I think that it is a good idea to call the ShowWindow API after caling create window. (That''s one of the thing I forgot to do yesterday)

Share this post


Link to post
Share on other sites
Thanks for the help, i took your advice pee wee and finaly got the window working. Ill put a link to the code next time (and im sure there will be a next time

Share this post


Link to post
Share on other sites