AstaTus
-- 夏天不热。。
posts - 22,comments - 12,trackbacks - 0
      开始看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(00,(void**)&vertices, 0);

    vertices[
0= Vertex(-1.0f0.0f2.0f);
    vertices[
1= Vertex(0.0f1.0f2.0f);
    vertices[
2= Vertex(1.0f0.0f2.0f);

    Triangle
->Unlock();

    D3DXMATRIX proj;
    D3DXMatrixPerspectiveFovLH(
&proj, D3DX_PI * 0.5f, (float)800 / (float)6001.0f1000.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(00, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff1.0f0);

        device
->BeginScene();

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

        device
->EndScene();

        
// Swap the back and front buffers.
        device->Present(0000);
posted on 2008-09-18 20:30 AstaTus 阅读(242) 评论(0)  编辑 收藏 引用 所属分类: DIRECTX9

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理