#include #include #include int xres,yres; int mx=0,my=0,mb_real,mb_stuck=1,mb=0,primpitch,shadpitch,backpitch; char keyhit=0,gotch[500]="",timeup=0,minimise_window=0; void werror(char *message) { MessageBox(NULL,message,"Oh sod it",MB_ICONERROR|MB_SETFOREGROUND|MB_OK); PostQuitMessage(0); exit(0); } LRESULT CALLBACK windowproc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) { keyhit=0; PAINTSTRUCT ps; switch (msg) { case WM_PAINT: BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps); return 0; case WM_DESTROY: PostQuitMessage(0); exit(0); return 0; case WM_CHAR: keyhit=1; if (strlen(gotch)<499) { gotch[strlen(gotch)+1]=0; gotch[strlen(gotch)]=(char)wp; } break; case WM_LBUTTONDOWN: //mb_left_clicks++; goto skip; case WM_RBUTTONDOWN: //mb_right_clicks++; skip:; case WM_MOUSEMOVE: case WM_LBUTTONUP: case WM_LBUTTONDBLCLK: case WM_RBUTTONUP: case WM_RBUTTONDBLCLK: mx=(int)LOWORD(lp); my=(int)HIWORD(lp); mb_real=(int)wp&3; if (!mb_real) mb_stuck=0; if (!mb_stuck) mb=mb_real; break; default:; } return DefWindowProc(hwnd,msg,wp,lp); } HWND winhandle=NULL; void makethewindow(HINSTANCE hinst,int xs,int ys,const char *task_name) { WNDCLASS winclass; xres=xs; yres=ys; winclass.style=CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW; winclass.lpfnWndProc=windowproc; winclass.cbClsExtra=0; winclass.cbWndExtra=0; winclass.hInstance=hinst; winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); winclass.hCursor=LoadCursor(NULL,IDC_ARROW); winclass.hbrBackground=GetStockObject(BLACK_BRUSH); winclass.lpszMenuName=NULL; winclass.lpszClassName="mallards"; if (!RegisterClass(&winclass)) werror("Couldn't register window class"); xs=xres+2*GetSystemMetrics(SM_CXFRAME); ys=yres+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYFRAME); winhandle=CreateWindow("mallards",task_name,WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN)-xs)/2,(GetSystemMetrics(SM_CYSCREEN)-ys)/2,xs,ys, NULL,NULL,hinst,NULL); if (!winhandle) werror("Couldn't create a window"); } #define LOGFILE "d3derr.log" IDirect3DDevice8 *d3dev; void d3derr(const int loc,const int result) { if (result!=D3D_OK) {FILE *out=fopen(LOGFILE,"at"); fprintf(out,"result{%d}=%d %08X low16=%d",loc,result,result,result&0xFFFF); fclose(out); exit(0);} } void setprojection(const double fov,const double epsz) { int i,j; D3DMATRIX proj; for (i=0;i<4;i++) for (j=0;j<4;j++) proj.m[i][j]=0; proj._11=1.0/tan(0.5*fov); proj._22=1.0/(tan(0.5*fov)*yres/xres); proj._33=1.0; proj._34=1.0; // (divisor) proj._43=-epsz; d3dev->SetTransform(D3DTS_PROJECTION,&proj); } #define degrees *M_PI/180 #define pigeons 0 int WINAPI WinMain(HINSTANCE hinst,HINSTANCE previous,LPSTR cmdline,int showcmd) { makethewindow(hinst,800,600,"Window"); // System dependant IDirect3D8 *d3d=Direct3DCreate8(D3D_SDK_VERSION); if (!d3d) werror("Could not create Direct3D 8 interface"); D3DPRESENT_PARAMETERS d3dpp; d3dpp.BackBufferWidth=xres; d3dpp.BackBufferHeight=yres; d3dpp.BackBufferFormat=D3DFMT_UNKNOWN; d3dpp.BackBufferCount=1; d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE; d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow=winhandle; d3dpp.Windowed=TRUE; d3dpp.EnableAutoDepthStencil=TRUE; d3dpp.AutoDepthStencilFormat=D3DFMT_D24S8; d3dpp.Flags=D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; d3dpp.FullScreen_RefreshRateInHz=0; d3dpp.FullScreen_PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE; /* // One from a tutorial memset(&d3dpp,0x00,sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow=winhandle; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount=1; d3dpp.FullScreen_PresentationInterval=D3DPRESENT_INTERVAL_DEFAULT; */ d3derr(101, d3d->CreateDevice( D3DADAPTER_DEFAULT, // Adapter D3DDEVTYPE_HAL, // DeviceType winhandle, // hFocusWindow D3DCREATE_FPU_PRESERVE|D3DCREATE_MIXED_VERTEXPROCESSING, // BehaviorFlags &d3dpp, // pPresentationParameters &d3dev) ); setprojection(90 degrees,0.1); return pigeons; }