need ddraw help please look at my code
Okay I''ve got almost everything done for my direct draw test.
I still don''t have the part where the bitmap is blitted to
the screen. If someone can give me ALL the code I need to add
to this in order to get it done I would really appreciate it.
I am using Visual C++ .net
// 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;
}
A while ago I created my own DirectDraw Class which will do everything for you including creating the window. If you have used D3DApp.h/.cpp in the direct3d samples, you will know what I mean. This could greatly help you out because it includes all the information to blitting to the screen (including FPS). Would you want something like this?
~Guyaton
~Guyaton
I''d be interested in a class to do this if you have one you
could post. But I''d still be interested in how to do it
the "hard" way, just so I understand direct draw well.
could post. But I''d still be interested in how to do it
the "hard" way, just so I understand direct draw well.
Send me an email at guyaton@hotmail.com and i will send it as a .zip If i recal i have some pretty good comments in it.
~Guyaton
~Guyaton
I don''t have the time to filter through your code and figure out what''s wrong, but here are my DirectX 8.1 libraries:
http://www.time-spacegames.com/profugus/download/utilities.zip
Feel free to use and abuse the code above in any way that you deam worthy. All I ask is that, if you use it as-is, then give me credit.
you can also get the source to one of my free games, using those libraries, at this location:
http://www.time-spacegames.com/jackoff/index.html
WARNING: the link above is meant for adults over the age of 18.
Feel free to use the code mentioned above as you wish, with a few stipulations: I still hold the CopyRight to the game. You may not distribute this game except in it''s unaltered form (the zip file).
http://www.time-spacegames.com/profugus/download/utilities.zip
Feel free to use and abuse the code above in any way that you deam worthy. All I ask is that, if you use it as-is, then give me credit.
you can also get the source to one of my free games, using those libraries, at this location:
http://www.time-spacegames.com/jackoff/index.html
WARNING: the link above is meant for adults over the age of 18.
Feel free to use the code mentioned above as you wish, with a few stipulations: I still hold the CopyRight to the game. You may not distribute this game except in it''s unaltered form (the zip file).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement