| 查看: 767 | 回复: 0 | ||
断点~+++金虫 (小有名气)
|
[求助]
DX 画个矩形问题 求大神
|
|
////////////////////////////////////////////////////////////////////////////////////////////////// // // File: triangle.cpp // // Author: Frank Luna (C) All Rights Reserved // // System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0 // // Desc: Renders a triangle in wireframe mode. Demonstrates vertex buffers, // render states, and drawing commands. // ////////////////////////////////////////////////////////////////////////////////////////////////// #include "d3dUtility.h" // // Globals // IDirect3DDevice9* Device = 0; const int Width = 640; const int Height = 480; IDirect3DVertexBuffer9* Triangle = 0; // vertex buffer to store // our triangle data. // // Classes and Structures // struct Vertex { Vertex(){} Vertex(float x, float y, float z) { _x = x; _y = y; _z = z; } float _x, _y, _z; static const DWORD FVF; }; const DWORD Vertex::FVF = D3DFVF_XYZ; // // Framework Functions // bool Setup() { // // Create the vertex buffer. // Device->CreateVertexBuffer( 3 * sizeof(Vertex), // size in bytes D3DUSAGE_WRITEONLY, // flags Vertex::FVF, // vertex format D3DPOOL_MANAGED, // managed memory pool &Triangle, // return create vertex buffer 0); // not used - set to 0 // // Fill the buffers with the triangle data. // Vertex* vertices; Triangle->Lock(0, 0, (void**)&vertices, 0); vertices[0] = Vertex(0.0f, 0.5f, 2.0f); //left vertices[1] = Vertex(-1.0f, 1.0f, 2.0f); // vertices[2] = Vertex( 1.0f, 1.0f, 2.0f); //right vertices[3] = Vertex( 1.0f, 0.0f, 2.0f); vertices[4] = Vertex( -1.0f, 0.0f, 2.0f); vertices[5] = Vertex( -1.0f, 1.0f, 2.0f); Triangle->Unlock(); // // Set the projection matrix. // D3DXMATRIX proj; D3DXMatrixPerspectiveFovLH( &proj, // result D3DX_PI * 0.5f, // 90 - degrees (float)Width / (float)Height, // aspect ratio 1.0f, // near plane 1000.0f); // far plane Device->SetTransform(D3DTS_PROJECTION, &proj); // // Set wireframe mode render state. // Device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); return true; } void Cleanup() { d3d::Release<IDirect3DVertexBuffer9*>(Triangle); } bool Display(float timeDelta) { if( Device ) { Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0); Device->BeginScene(); Device->SetStreamSource(0, Triangle, 0, sizeof(Vertex)); Device->SetFVF(Vertex::FVF); // Draw one triangle. Device->DrawPrimitive(D3DPT_TRIANGLEFAN,0,4); Device->EndScene(); Device->Present(0, 0, 0, 0); } return true; } // // WndProc // LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch( msg ) { case WM_DESTROY: : ostQuitMessage(0);break; case WM_KEYDOWN: if( wParam == VK_ESCAPE ) : estroyWindow(hwnd);break; } return : efWindowProc(hwnd, msg, wParam, lParam);} // // WinMain // int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd) { if(!d3d::InitD3D(hinstance, Width, Height, true, D3DDEVTYPE_HAL, &Device)) { ::MessageBox(0, "InitD3D() - FAILED", 0, 0); return 0; } if(!Setup()) { ::MessageBox(0, "Setup() - FAILED", 0, 0); return 0; } d3d::EnterMsgLoop( Display ); Cleanup(); Device->Release(); return 0; } Device->DrawPrimitive(D3DPT_TRIANGLEFAN,0,4); 使用D3DPT_TRIANGLEFAN 系统使用顶点v2、v3和v1画第一个三角形;v3,v4,v1画第二个三角形;v4,v5,v1画第三个三角形;等等。启用平面着色时,系统色调颜色从第一个顶点的三角形 但是运行的时候只有第一个三角形画出来了 应该是四个三角形组成一个矩形啊 |
» 猜你喜欢
售SCI一区文章,我:8 O5 51O 54,科目齐全,可+急
已经有3人回复
售SCI一区文章,我:8 O5 51O 54,科目齐全,可+急
已经有5人回复
为什么中国大学教授们水了那么多所谓的顶会顶刊,但还是做不出宇树机器人?
已经有3人回复
售SCI一区文章,我:8 O5 51O 54,科目齐全,可+急
已经有4人回复
售SCI一区文章,我:8 O5 51O 54,科目齐全,可+急
已经有3人回复
售SCI一区文章,我:8 O5 51O 54,科目齐全,可+急
已经有4人回复
“人文社科而论,许多学术研究还没有达到民国时期的水平”
已经有5人回复
过年走亲戚时感受到了所开私家车的鄙视链
已经有11人回复
什么是人一生最重要的?
已经有4人回复
版面费该交吗
已经有3人回复













ostQuitMessage(0);
estroyWindow(hwnd);
回复此楼