Etiketler

,

Merhaba arkadaslar bu yazimda DirectX ile pencere yapmanin 
kodlarini paylasicam sizlerle. Ama oncelikle yapmamiz gereken
bir kac islem var. 
Oncelikle Microsoft' un istesinden DirectX SDK'yi indirecegiz.
Daha sonra yeni actigimiz Win32 projesinde project->properties
kismina geliyoruz. Buradan Configuration Properties seceneginin
icinden Linker'a onun icinden de Input a tikliyoruz ve karsimiza
cikan pencerede Additional Dependencies kismina edit diyip
asagidaki kodlari ekliyoruz.
d3d9.lib
ve artik kodlama zamani...
 
#include <Windows.h>
#include <WindowsX.h>
#include <d3d9.h>

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 directx;

void D3Dbaslat(HWND hWnd);
void kare_goruntule(void);
void D3Dtemizle(void);

void D3Dbaslat(HWND hWnd)
{
 d3d=Direct3DCreate9(D3D_SDK_VERSION);

 D3DPRESENT_PARAMETERS direct3d;

 ZeroMemory(&direct3d,sizeof(direct3d));
 direct3d.Windowed=TRUE;
 direct3d.SwapEffect=D3DSWAPEFFECT_DISCARD;
 direct3d.hDeviceWindow=hWnd;

 d3d->CreateDevice(D3DADAPTER_DEFAULT,
 D3DDEVTYPE_HAL,
 hWnd,
 D3DCREATE_SOFTWARE_VERTEXPROCESSING,
 &direct3d,
 &directx);

 return;
}

void kare_goruntule(void)
{
 directx->Clear(0,NULL,D3DCLEAR_TARGET,
 D3DCOLOR_XRGB(200,230,190),1.0f,0);

 directx->BeginScene();

 directx->EndScene();

 directx->Present(NULL,NULL,NULL,NULL);

 return;
}

void D3Dtemizle(void)
{
 directx->Release();
 d3d->Release();

 return;
}

LRESULT CALLBACK WindowProc(HWND hWnd,
 UINT message,
 WPARAM wParam,
 LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,
 HINSTANCE hPrevInstance,
 LPSTR lpCmdLine,
 int nCmdShow)
{
 HWND hWnd;
 WNDCLASSEX ps;

 ZeroMemory(&ps,sizeof(WNDCLASSEX));
 ps.cbSize=sizeof(WNDCLASSEX);
 ps.style=CS_HREDRAW|CS_VREDRAW;
 ps.lpfnWndProc=(WNDPROC)WindowProc;
 ps.hInstance=hInstance;
 ps.hCursor=LoadCursor(NULL,IDC_ARROW);
 ps.hbrBackground=(HBRUSH)COLOR_WINDOW;
 ps.lpszClassName=L"PencereSinifi01";

 RegisterClassEx(&ps);

 hWnd=CreateWindowEx(NULL,
 L"PencereSinifi01",
 L"Ilk Direct3D programimiz by HuluCPlusPlus",
 WS_OVERLAPPEDWINDOW,400,400,
 720,540,
 NULL,NULL,
 hInstance,NULL);

 ShowWindow(hWnd, nCmdShow);

 D3Dbaslat(hWnd);

 MSG mesaj;

 while(TRUE)
 {
 DWORD baslangic_noktasi=GetTickCount();

 if(PeekMessage(&mesaj,NULL,0,0,PM_REMOVE))
 {
 if(mesaj.message==WM_QUIT)
 {
 break;
 }

 TranslateMessage(&mesaj);
 DispatchMessage(&mesaj);
 }

 kare_goruntule();

 while((GetTickCount()-baslangic_noktasi)<25);
 }

 D3Dtemizle();

 return mesaj.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd,
 UINT message,
 WPARAM wParam,
 LPARAM lParam)
{
 switch(message)
 {
 case WM_DESTROY:
 {
 PostQuitMessage(0);
 return 0;
 }break;
 }

 return DefWindowProc(hWnd,
 message,
 wParam,
 lParam);
}
Reklamlar