DirectX 8. Начинаем работу с DirectX Graphics (Ваткин, Dempski) - страница 19

Ниже приведён код, который больше относится к windows-программированию. Создаётся главное окно приложения и ведётся обработка сообщений:

>// функция обрабатывающая сообщения главного окна приложения

>LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {

> switch (msg) {

> case WM_DESTROY:

>  PostQuitMessage(0);

>  return 0;

> }

> return DefWindowProc(hWnd, msg, wParam, lParam);

>}


>INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT) {

> WNDCLASSEX wc = {

>  sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,

>  GetModuleHandle(0), 0, 0, 0, 0, "FirstDX_cl", 0

> };

> RegisterClassEx(&wc);

> // Создание главного окна приложения

> HWND hWnd = CreateWindow("FirstDX_cl", "FirstDX",

>  WS_OVERLAPPEDWINDOW, 100, 100, 160, 160,

>  GetDesktopWindow(), NULL, wc.hInstance, NULL);

> if (Init(hWnd)) {

>  ShowWindow (hWnd, SW_SHOWDEFAULT);

>  UpdateWindow(hWnd);

>  MSG msg;

>  ZeroMemory(&msg, sizeof(msg));

>  while (msg.message != WM_QUIT) {

>   if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {

>    TranslateMessage(&msg);

>    DispatchMessage(&msg);

>   } else Render();

>  }

> }

> ReleaseAll();

> UnregisterClass("FirstDX_cl", wc.hInstance);

> return 0;

>}

Функция Render() вызывается всегда, когда не приходят какие-либо сообщения, то есть перерисовка кадра происходит практически постоянно. Функции Init() и ReleaseAll() описаны в предыдущей части урока.

Теперь есть всё, чтобы вы смогли скомпилировать и запустить наш пример. Не забудьте добавить библиотеку d3d8.lib в ваш проект, чтобы линковщик смог найти реализации функций Direct3D.

Поведал: Ваткин.

GameDev.net 

2D Rendering in DirectX 8

by Kelly Dempski
Background

I have been reading alot of questions lately related to DirectX 8 and the exclusion of DirectDraw from the new API. Many people have fallen back to DX7. I can understand people using DX7 if they have alot of experience with that API, but many of the questions seem to be coming from people who are just learning DX, and they are stuck learning an old API. People have argued that many people don't have 3D hardware, and therefore D3D would be a bad alternative for DirectDraw. I don't believe this is true - 2D rendering in D3D requires very little vertex manipulation, and everything else boils down to fillrate. In short, 2D rendering in D3D on 2D hardware should have pretty much the same performance as DirectDraw, assuming decent fillrate. The advantage is that the programmer can learn the newest API, and performance on newer hardware should be very good. This article will present a framework for 2D rendering in DX8 to ease the transition from DirectDraw to Direct3D. In each section, you may see things that you don't like ("I'm a 2D programmer, I don't care about vertices!"). Rest assured, if you implement this simple framework once, you'll never think about these things again.