一个三角型。。

一个三角型。。
      开始看directx了,发现学ogre,还是现弄懂directx会比较好点。

      这个程序主要体现了directx的一个基本的框架。
  1. 在初始化D3D设备后,开始设置顶点缓存,将要显示的点输入,
  2.用函数D3DXMatrixPerspectiveFovLH 求投影矩阵,该函数根据视域体的属性求出投影矩阵
  3.设置顶点渲染的方法,
device -> CreateVertexBuffer( 3   *   sizeof (Vertex), D3DUSAGE_WRITEONLY, D3DFVF_XYZ, D3DPOOL_MANAGED,  & Triangle,  0 );

    Vertex
*  vertices;
    Triangle
-> Lock( 0 0 ,( void ** ) & vertices,  0 );

    vertices[
0 =  Vertex( - 1.0f 0.0f 2.0f );
    vertices[
1 =  Vertex( 0.0f 1.0f 2.0f );
    vertices[
2 =  Vertex( 1.0f 0.0f 2.0f );

    Triangle
-> Unlock();

    D3DXMATRIX proj;
    D3DXMatrixPerspectiveFovLH(
& proj, D3DX_PI  *   0.5f , ( float ) 800   /  ( float ) 600 1.0f 1000.0f );
    
    device
-> SetTransform(D3DTS_PROJECTION,  & proj);

    device
-> SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);


  4.在消息循环函数中
while (msg.message  !=  WM_QUIT)
    
{
        
if(::PeekMessage(&msg, 000, PM_REMOVE)) /**///////////////这里有个疑惑,什么时候if语句不成立呢
        {
            ::TranslateMessage(
&msg);
            ::DispatchMessage(
&msg);
             }

          
else
        
{    
               
float currTime  = (float)timeGetTime();
               
float timeDelta = (currTime - lastTime)*0.001f;

                ptr_display(timeDelta);

               lastTime 
= currTime;
           }

    }
这里是场景的渲染
device -> Clear( 0 0 , D3DCLEAR_TARGET  |  D3DCLEAR_ZBUFFER,  0xffffffff 1.0f 0 );

        device
-> BeginScene();

        device
-> SetStreamSource( 0 , Triangle,  0 sizeof (Vertex));   //将Vertexbuffer中的顶点倒入到流当中
        device
-> SetFVF(Vertex::FVF); //设置顶点的格式  FVF已被我赋值为 FVF_XYZ
 
        device
-> DrawPrimitive(D3DPT_TRIANGLELIST,  0 1 ); //图元类型 三角形 个数为一个

        device
-> EndScene();

        
//  Swap the back and front buffers.
        device -> Present( 0 0 0 0 );

你可能感兴趣的:(一个三角型。。)