Здравствуйте. Взял пример кода программы из одной книги, а он не работает правильно. В окошке должен появится квадрат и вращатся, но вместо этого у левом верхнем углу есть один пиксель, зарисованный. Как исправить? Код: Код (Text): #include <Windows.h> #include <d3d9.h> #include <d3dx9.h> //#include <mmsystem.h> #pragma comment(lib, "d3d9.lib") #pragma comment(lib, "d3dx9.lib") #pragma comment(lib, "Winmm.lib") LPDIRECT3D9 pDirect3D=NULL; LPDIRECT3DDEVICE9 pDirect3DDevice=NULL; LPDIRECT3DVERTEXBUFFER9 pBufferVershin=NULL; struct CUSTOMVERTEX { float X, Y, Z; DWORD color; }; #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE) void Matrix() { D3DXMATRIX MatrixWorld; D3DXMATRIX MatrixView; D3DXMATRIX MatrixProjection; UINT Time=timeGetTime() % 5000; FLOAT Angle=Time*(2.0f * D3DX_PI)/5000.0f; D3DXMatrixRotationY(&MatrixWorld,Angle); pDirect3DDevice->SetTransform(D3DTS_WORLD, &MatrixWorld); D3DXMatrixLookAtLH(&MatrixView, &D3DXVECTOR3(0.0f,0.0f,-8.0f), &D3DXVECTOR3(0.0f,0.0f,0.0f), &D3DXVECTOR3(0.0f,1.0f,0.0f)); pDirect3DDevice->SetTransform(D3DTS_VIEW, &MatrixView); D3DXMatrixPerspectiveFovLH(&MatrixProjection, D3DX_PI/4, 1.0f, 1.0f, 100.0f); pDirect3DDevice->SetTransform(D3DTS_PROJECTION, &MatrixProjection); } HRESULT InitialBufferVershin() { CUSTOMVERTEX Vershin[]= { {1.0f, -1.0f, 0.0f, 0x000000fff }, //A {-1.0f, -1.0f, 0.0f, 0x000000fff }, //B {-1.0f, 1.0f, 0.0f, 0x000000fff }, //C {-1.0f, 1.0f, 0.0f, 0x000000fff }, //C {1.0f, 1.0f, 0.0f, 0x000000fff }, //D {1.0f, -1.0f, 0.0f, 0x000000fff } //A }; if(FAILED(pDirect3DDevice->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&pBufferVershin,NULL))) return E_FAIL; VOID* pBV; if(FAILED(pBufferVershin->Lock(0,sizeof(Vershin),(void**)&pBV,0))) return E_FAIL; memcpy(pBV,Vershin,sizeof(Vershin)); pBufferVershin->Unlock(); return S_OK; } void RenderingDirect3D() { if(pDirect3DDevice==NULL) return; pDirect3DDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,255,0),1.0f,0); pDirect3DDevice->BeginScene(); Matrix(); pDirect3DDevice->SetStreamSource(0,pBufferVershin,0,sizeof(CUSTOMVERTEX)); pDirect3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX); pDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2); pDirect3DDevice->EndScene(); pDirect3DDevice->Present(NULL,NULL,NULL,NULL); } void DeleteDirect3D() { if(pBufferVershin!=NULL) { pBufferVershin->Release(); } if(pDirect3DDevice!=NULL) { pDirect3DDevice->Release(); } if(pDirect3D!=NULL) { pDirect3D->Release(); } } HRESULT InitialDirect3D(HWND hwnd) { if(NULL==(pDirect3D=Direct3DCreate9(D3D_SDK_VERSION))) return E_FAIL; D3DDISPLAYMODE display; if(FAILED(pDirect3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&display))) return E_FAIL; D3DPRESENT_PARAMETERS Direct3DParametr; ZeroMemory(&Direct3DParametr, sizeof(Direct3DParametr)); Direct3DParametr.Windowed=true; Direct3DParametr.SwapEffect=D3DSWAPEFFECT_DISCARD; Direct3DParametr.BackBufferFormat=display.Format; if(FAILED(pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd , /*D3DCREATE_HARDWARE_VERTEXPROCESSING*/ D3DCREATE_SOFTWARE_VERTEXPROCESSING, &Direct3DParametr, &pDirect3DDevice))) return E_FAIL; pDirect3DDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE); pDirect3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); return S_OK; } LRESULT CALLBACK MainWinProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch(msg) { case WM_PAINT: RenderingDirect3D(); //ValidateRect(hwnd,NULL); break; case WM_DESTROY: { PostQuitMessage(0); DeleteDirect3D(); return 0; break; } } return (DefWindowProc(hwnd,msg,wparam,lparam)); } int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX windowsclass; HWND hwnd; MSG msg; ZeroMemory(&msg,sizeof(MSG)); windowsclass.cbSize=sizeof(WNDCLASSEX); windowsclass.style=CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW; windowsclass.lpfnWndProc=MainWinProc; windowsclass.cbClsExtra=0; windowsclass.cbWndExtra=0; windowsclass.hInstance=hinstance; windowsclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); windowsclass.hCursor=LoadCursor(NULL, IDC_ARROW); windowsclass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH); windowsclass.lpszMenuName=NULL; windowsclass.lpszClassName="WINDOWSCLASS"; windowsclass.hIconSm=LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&windowsclass)) return 0; if(!(hwnd=CreateWindowEx(NULL, "WINDOWSCLASS", "Лабораторна робота №3", WS_OVERLAPPEDWINDOW|WS_VISIBLE,0,0,400,600, NULL, NULL, hinstance, NULL))) return 0; //SetTimer(hwnd,Timer1,1000,(TIMERPROC)NULL); InitialDirect3D(hwnd); InitialBufferVershin(); ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); while(msg.message != WM_QUIT) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { RenderingDirect3D(); } } return msg.wParam; }