Jump to content
  • Advertisement

Archived

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

help with ddraw - posting my code this time

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

okay I think I would get a better answer if people can look at my code. I''ve got everything written except for the bitmap being written to the screen. Any help would be greatly appreciated. Please tell me what I need to add to this code to draw the bitmap to the screen. Please give me the complete code I need to add. This is in Visual C++ .net. Thanks. // DDTEST.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "DDTEST.h" #define MAX_LOADSTRING 100 #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name HWND hWnd = NULL; HINSTANCE game_instance = NULL; LPDIRECTDRAW game_draw_main = NULL; LPDIRECTDRAWSURFACE game_draw_surface = NULL; LPDIRECTDRAWSURFACE game_draw_back = NULL; DDSURFACEDESC game_draw_desc; DDSCAPS game_draw_caps; LPDIRECTDRAWCLIPPER game_draw_clip; DDBLTFX back_fill; HBITMAP hbmp; DDCOLORKEY ddck; RECT bmp_rect = {0, 0, 48, 48}; RECT temp_rect; int ddrval; int DDInit() { ddrval = DirectDrawCreate(NULL, &game_draw_main, NULL); if (ddrval != DD_OK) { return 1; } ddrval = IDirectDraw_SetCooperativeLevel(game_draw_main, hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); if (ddrval != DD_OK) { return 2; } ddrval = IDirectDraw_SetDisplayMode(game_draw_main, 640, 480, 16); if (ddrval != DD_OK) { return 3; } return 4; } void GameInit() { int RESULT; RESULT = DDInit(); if (RESULT != 4) { exit(RESULT); } ZeroMemory(&game_draw_desc, sizeof(game_draw_desc)); game_draw_desc.dwSize = sizeof(game_draw_desc); game_draw_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; game_draw_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; game_draw_desc.dwBackBufferCount = 1; game_draw_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0; game_draw_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0; ddrval = IDirectDraw_CreateSurface(game_draw_main, &game_draw_desc, &game_draw_surface, NULL); if (ddrval != DD_OK) { exit(5); } game_draw_caps.dwCaps = DDSCAPS_BACKBUFFER; ddrval = IDirectDrawSurface_GetAttachedSurface(game_draw_surface, &game_draw_caps, &game_draw_back); if (ddrval != DD_OK) { exit(6); } hbmp = (HBITMAP)LoadImage(NULL,MAKEINTRESOURCE(BMP1),IMAGE_BITMAP,32,32,LR_LOADFROMFILE); IDirectDraw_CreateClipper(game_draw_main, 0, &game_draw_clip, NULL); IDirectDrawClipper_SetHWnd(game_draw_clip, 0, hWnd); IDirectDrawSurface_SetClipper(game_draw_back, game_draw_clip); ZeroMemory(&back_fill, sizeof(back_fill)); back_fill.dwSize = sizeof(back_fill); back_fill.dwFillColor=RGB(0,0,0); } void GameMain() { // // // // // // // // here is where I want to draw the bitmap to // back surface, loading from a resource // // // // // IDirectDrawSurface_Flip(game_draw_surface, NULL, DDFLIP_WAIT); } void GameQuit() { if (game_draw_back) IDirectDrawSurface_Release(game_draw_back); if (game_draw_surface) IDirectDrawSurface_Release(game_draw_surface); if (game_draw_main) { IDirectDraw_Release(game_draw_main); game_draw_main = NULL; } } // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_DDTEST, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_DDTEST); GameInit(); while(TRUE) { DWORD start_tick = GetTickCount(); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (msg.message == WM_QUIT) break; if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } GameMain(); if (KEYDOWN(VK_ESCAPE)) SendMessage(hWnd, WM_CLOSE, 0,0); while ((GetTickCount() - start_tick) < 30); } GameQuit(); return (int) msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage are only necessary if you want //this code // to be compatible with Win32 systems prior to the //''RegisterClassEx'' // function that was added to Windows 95. It is important to //call this function // so that the application will get ''well formed'' small icons //associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DDTEST); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCTSTR)IDC_DDTEST; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // // FUNCTION: InitInstance(HANDLE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Message handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; }

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!