Begian DirectX(bj)

本文介绍了DirectX游戏开发的基础知识,包括Surface与Sprite的概念及应用、3D绘图原理、光照与材质设置、纹理处理以及Mesh操作等内容。适用于初学者了解DirectX的基本使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
一 : Suface , Sprites, salmon
1: Suface : 储存图片纹理等数据的内存区域
(1) Display buffer:font buffer,back buffer可以通过present()把back buffer内容调入font buffer从而显示出来
         (2) Offsceen surface(离屏表面相对于primary surface):是缓存和主屏面值间的缓冲区.
                  A: 建立offscree suface : CreateOffscreenPlainSureface()
                  B: 加载资源到 offscree suface: D3DXLoadSurfaceFromFile() 
                  C: 把offscree suface的东东转到back buffer中:  StretchRect()
void Render(void)
{
// This will hold the back buffer
IDirect3DSurface9* backbuffer = NULL;
// Check to make sure you have a valid Direct3D device
if( NULL == pd3dDevice )
return;
// Clear the back buffer to a blue color
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
// Get the back buffer
pd3dDevice->GetBackBuffer( 0,
0,
D3DBACKBUFFER_TYPE_MONO,
&backbuffer );
// Copy the offscreen surface to the back buffer
// Note the use of NULL values for the source and destination RECTs
// This ensures a copy of the entire surface to the back buffer
pd3dDevice->StretchRect( srcSurface,
NULL,
backbuffer,
NULL,
D3DTEXF_NONE );
// Present the back buffer contents to the display
pd3dDevice->Present ( NULL, NULL, NULL, NULL );
}
3D
1 Primary Type DrawPrimitive(), DrawIndexedPrimitive()
Point List,   Line List,   Line Strip(许多不相连的线组成) Line Strip(许多相连的组成) Triangle List(不相连的三角形组成的) Triangle Strip, Triangle Fan
2: DirectX 中的Matrix
   移动: D3DXMatrixTranslation()
   旋转(弧度): D3DXMatrixRotationX(),D3DXMatrixRotationY(),D3DXMatrixRotationZ()
   把角度转化为弧度: D3DXToRadian(angle)
   压缩或放大物体: D3DXMatrixScaling()
   矩阵相乘: D3DXMatrixMultiply()
 
   把矩阵作用于物体的变换: SetTransform()
注意: 各种矩阵作用物体的顺序,可以通过各种矩阵在D3DXMatrixMultiply()中参数的位置来确定
 
3: 顶点颜色
     D3DCOLOR_ARGB, D3DCOLOR_RGBA, 
D3DCOLOR_XRGB, (默认alpha值为255)
D3DCOLOR_COLORVALUE.(值时0.0---1.0之间)
4: shade(着色):
   Flat shading:通过一个点的颜色来render多边形的颜色
   Gourand shading: 通过多个点
   可以通过SetRenderStata(D3DRS_SHADEMODE,,)来设置shade
5 :Fill Mode: 多边形的渲染方式
   Point, WireFram, Solid
   SetRendeStata(D3DRS_FILLMODE,,,)
6 Light
(1)type:
 Ambient Lights(环境光源)(默认光源): 来世界的各个方向,均匀的照在物体上,所以同时间只能有一个Ambient Light处于活动状态  
Direction Lights(方向光):有方向,颜色,但没有位置,世界中可有多个Direction Lights
Point Lights():有颜色,位置,可有多个Point Lights
SpoteLights(聚焦光源): 有,位置 ,颜色,方向
 (2 )Function
     HRESULT SetLight()
     HRESULT LightEnable()
     Bool GetLightEnalble(): check the stata of Light
     SetRederStata(D3DRS_LIGHT,,,)
(4): Create the Light
 注意:
Create Ambient Light: SetRenderStata(D3DRS_AMBIENT,D3DCOLOR_XRGB())
 
7:Materils : 物体发出和反射光的属性
D3DCOLORVALUE difuss reflection
D3DCOLORVALUE ambient reflection
D3DCOLORVALUE specular reflection
D3DCOLORVALUE Emissive
Float power
SetMaterial()
注意:specular: SetRederStata(D3DRS_SPECULARENABLE, TRUE)
 
 
8: Texture
 SetTextureStageStata(): 设置纹理方式,可以是多个纹理同时加在一个物体上
 D3DXCreateTextureFromFile():
 D3DXCreateTextureFromResuorce(): 可以是多个texture混合成的resuorse
 SetTexure()
 
9: Mesh: 
   Interface : ID3DXMesh
(1) Creater Mesh
D3DXCreateMesh();
D3DXCreateMeshFVF();
注意: D3DXDeclaratorFromFvF(): 申明所需要的定点格式
 (2): Fill the Mesh
 (4): Display Mesh
      DrawSubset()
 (5): Optimizing Mesh
      Optimize()   有新的输出mesh
      OptimizeImaplace() 没有新的输出mesh
 (6): Get Detail of Mesh
      GetNumVertices()
      GetNumFace()
 
     
 
 
 
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值