Etiketler

, , ,

 
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>

int screen_width=1152;
int screen_height =864;

DWORD dx_style=WS_EX_TOPMOST|WS_POPUP|WS_VISIBLE;
DWORD fvf_style= D3DFVF_XYZ|D3DFVF_DIFFUSE;

LPDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pDevice;
LPDIRECT3DVERTEXBUFFER9 pVertexBuffer;
LPDIRECT3DINDEXBUFFER9 i_buffer;

int angle=0;

struct CUSTOMVERTEX
{
 FLOAT x,y,z;
 DWORD Color;
};

bool dx_kur(HWND hWnd);
void dx_temizle();
void dx_serbest_birak();
bool dx_VertexKur();

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

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

 ZeroMemory(&wndCEx,sizeof(WNDCLASSEX));
 wndCEx.style=CS_HREDRAW|CS_VREDRAW;
 wndCEx.lpfnWndProc=WndProc;
 wndCEx.cbClsExtra=0;
 wndCEx.cbWndExtra=0;
 wndCEx.hInstance=hInstance;
 wndCEx.hIcon=LoadIcon(0,IDI_APPLICATION);
 wndCEx.hCursor=LoadCursor(0,IDC_ARROW);
 wndCEx.hbrBackground=(HBRUSH)COLOR_WINDOW;
 wndCEx.lpszClassName=L"UCBOYUT";
 wndCEx.cbSize=sizeof(WNDCLASSEX);

 RegisterClassEx(&wndCEx);

 hWnd=CreateWindowEx(NULL,L"UCBOYUT",L"HULUCPLUSPLUS",
 dx_style,0,0,screen_width,screen_height,
 NULL,NULL,hInstance,NULL);

 ShowWindow(hWnd,nCmdShow);

 MSG message;

 dx_kur(hWnd);
 dx_VertexKur();

 while(TRUE)
 {
 if(PeekMessage(&message,NULL,NULL,NULL,PM_REMOVE))
 {
 if(message.message==WM_QUIT)
 break;
 TranslateMessage(&message);
 DispatchMessage(&message);
 }
 dx_temizle();
 }

 dx_serbest_birak();

 return (int)message.wParam;
}

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

 case WM_KEYDOWN:
 {
 switch(wParam)
 {
 case VK_ESCAPE:
 PostQuitMessage(0);
 return 0;
 }
 }
 }
 return DefWindowProc(hWnd,message,wParam,lParam);
}

bool dx_kur(HWND hWnd)
{
 pD3D=Direct3DCreate9(D3D_SDK_VERSION);
 D3DPRESENT_PARAMETERS present;

 ZeroMemory(&present,sizeof(D3DPRESENT_PARAMETERS));
 present.SwapEffect=D3DSWAPEFFECT_DISCARD;
 present.hDeviceWindow=hWnd;
 present.Windowed=FALSE;
 present.BackBufferFormat=D3DFMT_X8R8G8B8;
 present.BackBufferCount=1;
 present.BackBufferWidth=screen_width;
 present.BackBufferHeight=screen_height;
 present.EnableAutoDepthStencil=TRUE;
 present.AutoDepthStencilFormat=D3DFMT_D16;

 if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,
 hWnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&present,&pDevice)))
 return FALSE;
 pDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
 pDevice->SetRenderState(D3DRS_ZENABLE,TRUE);

 return TRUE;
}

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

 pDevice->BeginScene();
 pDevice->SetFVF(fvf_style);

 D3DXMATRIX matView; 
 D3DXMatrixLookAtLH(&matView,
 &D3DXVECTOR3 (0.0f, 8.0f, 25.0f), 
 &D3DXVECTOR3 (0.0f, 0.0f, 0.0f), 
 &D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); 
 pDevice->SetTransform(D3DTS_VIEW, &matView); 

 D3DXMATRIX matProjection; 
 D3DXMatrixPerspectiveFovLH(&matProjection,
 D3DXToRadian(45), 
 (FLOAT)screen_width / (FLOAT)screen_height, 
 1.0f, 100.0f);

 pDevice->SetTransform(D3DTS_PROJECTION, &matProjection); 

 static float index = 0.0f; index+=0.03f; 

 D3DXMATRIX matRotateY; 
 D3DXMatrixRotationY(&matRotateY, index); 
 pDevice->SetTransform(D3DTS_WORLD, &(matRotateY));
 pDevice->SetStreamSource(0, pVertexBuffer, 0, 
 sizeof(CUSTOMVERTEX));

 pDevice->SetIndices(i_buffer);

 pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,8,0,12);

 pDevice->EndScene(); 

 pDevice->Present(NULL, NULL, NULL, NULL);
 }

void dx_serbest_birak()
{
 if(pDevice!= NULL)
 pDevice->Release();

 if(pD3D!=NULL)
 pD3D->Release();

 if(pVertexBuffer!=NULL)
 pVertexBuffer->Release();

 if(i_buffer!=NULL)
 i_buffer->Release();
}

bool dx_VertexKur()
{
 HRESULT hr;

 CUSTOMVERTEX pVertex[] ={
 { -3.0f, 3.0f, -3.0f, D3DCOLOR_XRGB(0, 0, 255), },
 { 3.0f, 3.0f, -3.0f, D3DCOLOR_XRGB(0, 255, 0), },
 { -3.0f, -3.0f, -3.0f, D3DCOLOR_XRGB(255, 0, 0), },
 { 3.0f, -3.0f, -3.0f, D3DCOLOR_XRGB(0, 255, 255), },
 { -3.0f, 3.0f, 3.0f, D3DCOLOR_XRGB(0, 0, 255), },
 { 3.0f, 3.0f, 3.0f, D3DCOLOR_XRGB(255, 0, 0), },
 { -3.0f, -3.0f, 3.0f, D3DCOLOR_XRGB(0, 255, 0), },
 { 3.0f, -3.0f, 3.0f, D3DCOLOR_XRGB(0, 255, 255), },
 };

 hr=pDevice->CreateVertexBuffer(8*sizeof(CUSTOMVERTEX),0,
 fvf_style,D3DPOOL_MANAGED,&pVertexBuffer,NULL);

 if(FAILED(hr))
 return 0;

 VOID* pVertices;

 hr=pVertexBuffer->Lock(0,sizeof(pVertex),(void**)&pVertices,0);

 if(FAILED(hr))
 return 0;

 memcpy(pVertices,pVertex,sizeof(pVertex));

 pVertexBuffer->Unlock();

 short indices[]=
 {
 0,1,2,
 2,1,3,
 4,0,6,
 6,0,2,
 7,5,6,
 6,5,4,
 3,1,7,
 7,1,5,
 4,5,0,
 0,5,1,
 3,7,2,
 2,7,6,
 };

 pDevice->CreateIndexBuffer(36*sizeof(short),0,
 D3DFMT_INDEX16,D3DPOOL_MANAGED,&i_buffer,NULL);

 i_buffer->Lock(0,0,(void**)&pVertices,0);
 memcpy(pVertices,indices,sizeof(indices));
 i_buffer->Unlock();

 return 1;
}
Reklamlar