Etiketler

, ,

#include <Windows.h>
#include <WindowsX.h>
#include <d3d9.h>
#include <time.h>

#define EKRAN_GENISLIK 1152
#define EKRAN_YUKSEKLIK 864
#define TUS(vk_code)((GetAsyncKeyState(vk_code)&0x8000)?1:0)

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 directx;
LPDIRECT3DVERTEXBUFFER9 buffer0=NULL;

int r=100,g=200,b=200;
void D3Dbaslat(HWND hWnd);
void kare_goruntule(void);
void D3Dtemizle(void);
void GrafikBaslat(void);

struct CUSTOMVERTEX
{
 FLOAT X,Y,Z,RHW;
 DWORD COLOR;
};

#define FVF_A (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

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

 D3DPRESENT_PARAMETERS direct3d;

 ZeroMemory(&direct3d,sizeof(direct3d));
 direct3d.Windowed=FALSE;
 direct3d.SwapEffect=D3DSWAPEFFECT_DISCARD;
 direct3d.hDeviceWindow=hWnd;
 direct3d.BackBufferFormat=D3DFMT_X8R8G8B8;
 direct3d.BackBufferWidth=EKRAN_GENISLIK;
 direct3d.BackBufferHeight=EKRAN_YUKSEKLIK;

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

 GrafikBaslat();

 return;
}

void kare_goruntule(void)
{
 srand ( time(NULL) );

 /*r=rand()%255+1;
 b=rand()%255+1;
 g=rand()%255+1;*/
	
 directx->Clear(0,NULL,D3DCLEAR_TARGET,
 D3DCOLOR_XRGB(r,b,g),1.0f,0);

 directx->BeginScene();

 directx->SetFVF(FVF_A);
 directx->SetStreamSource(0,
 buffer0,0,
 sizeof(CUSTOMVERTEX));
 directx->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);

 directx->EndScene();

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

 return;
}


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

 return;
}

void GrafikBaslat(void)
{
 CUSTOMVERTEX noktalar[]=
 {
 {320.0f,50.0f,0.5f,1.0f,D3DCOLOR_XRGB(100,40,23),},
 {520.0f,400.0f,0.5f,1.0f,D3DCOLOR_XRGB(20,0,10),},
 {120.0f,400.0f,0.5f,1.0f,D3DCOLOR_XRGB(150,200,200),},
 };

 directx->CreateVertexBuffer(
 3*sizeof(CUSTOMVERTEX),
 0,
 FVF_A,
 D3DPOOL_MANAGED,
 &buffer0,
 NULL);

 VOID* Voidpointer;

 buffer0->Lock(0,0,(void**)&Voidpointer,0);
 memcpy(Voidpointer,noktalar,sizeof(noktalar));
 buffer0->Unlock();

 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_EX_TOPMOST|WS_POPUP,
 0,0,
 EKRAN_GENISLIK,
 EKRAN_YUKSEKLIK,
 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();

 if(TUS(VK_ESCAPE))
 PostMessage(hWnd,WM_DESTROY,0,0);

 if(TUS(VK_DOWN))
 {
 /*kare_goruntule();*/


 directx->Clear(0,NULL,D3DCLEAR_TARGET,
 D3DCOLOR_XRGB(0,0,0),1.0f,0);

 directx->BeginScene();

 directx->EndScene();

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

 }

 if(TUS(VK_UP))
 {
 /*kare_goruntule();*/


 directx->Clear(0,NULL,D3DCLEAR_TARGET,
 D3DCOLOR_XRGB(100,50,200),1.0f,0);

 directx->BeginScene();

 directx->EndScene();

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

 }
			


 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