Etiketler

,



#include <Windows.h>
#include <WindowsX.h>
#include <d3d9.h>
#include <d3dx9.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;

void D3DBaslat(HWND hWnd);
void KareGoruntule(void);
void D3DTemzile(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=TRUE;
 direct3d.SwapEffect=D3DSWAPEFFECT_DISCARD;
 direct3d.hDeviceWindow=hWnd;
 direct3d.BackBufferFormat=D3DFMT_X8R8G8B8;
 direct3d.MultiSampleType=D3DMULTISAMPLE_NONE;
 direct3d.MultiSampleQuality=0;
 direct3d.EnableAutoDepthStencil=TRUE;
 direct3d.AutoDepthStencilFormat=D3DFMT_D16;

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

 GrafikBaslat();

 directx->SetRenderState(D3DRS_LIGHTING,FALSE);
 directx->SetRenderState(D3DRS_ZENABLE,TRUE);

 return;
}

void KareGoruntule(void)
{
 directx->Clear(0,NULL,
 D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
 directx->Clear(0,NULL,
 D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0);

 directx->BeginScene();
 directx->SetFVF(FVF_A);

 D3DXMATRIX mView; 

 D3DMatrixLookAtLH(&mView,
 &D3DXVECTOR3(0.0f,0.0f,15.0f),
 &D3DXVECTOR3(0.0f,0.0f,0.0f),
 &D3DXVECTOR3(0.0f,1.0f,0.0f));

 directx->SetTransform(D3DTS_VIEW,&mView);

 D3DXMATRIX mProjection;
 D3DXMatrixPerspectiveFovLH(&mProjection,
 D3DXToRadian(45),
 (FLOAT)EKRAN_GENISLIK/(FLOAT)EKRAN_YUKSEKLIK,1.0f,100.0f);

 directx->SetTransform(D3DTS_PROJECTION,&mProjection);

 D3DXMATRIX mDonusumX;
 D3DXMATRIX mDonusumY;
 D3DXMATRIX mDondur01;
 D3DXMATRIX mDondur02;
 static float index=0.0f;
 index+=0.05f;

 D3DXMatrixTranslation(&mDonusumX,0.0f,0.0f,2.0f);
 D3DXMatrixTranslation(&mDonusumY,0.0f,0.0f,-2.0f);
 D3DXMatrixRotationY(&mDondur01,index);
 D3DXMatrixRotationY(&mDondur02, index+3.14159f);

 directx->SetTransform(D3DTS_WORLD,&(mDonusumX*mDondur01));
 directx->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);

 directx->SetTransform(D3DTS_WORLD,&(mDonusumX*mDondur02));
 directx->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);

 directx->SetTransform(D3DTS_WORLD,&(mDonusumY*mDondur01));
 directx->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);

 directx->SetTransform(D3DTS_WORLD,&(mDonusumY*mDondur02));
 directx->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);

 directx->SetStreamSource(0,buffer0,0,sizeof(CUSTOMVERTEX));

 directx->EndScene();

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

 return;
}

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

 return;
}

void GrafikBaslat(void)
{
 CUSTOMVERTEX noktalar[]=
 {
 {3.0f,-3.0f,0.0f,D3DCOLOR_XRGB(0,0,255),},
 {0.0f,3.0f,0.0f,D3DCOLOR_XRGB(0,255,0),},
 {-3.0f,-3.0f,0.0f,D3DCOLOR_XRGB(255,0,0),},
 };

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

 VOID* pVoid;

 buffer0->Lock(0,0,(void**)&pVoid,0);
 memcpy(pVoid,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);
 }

 KareGoruntule();

 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