DX Graphics Display Basic process (drawing----managed code based on mesh static model)

Source: Internet
Author: User
static | graphics | hosting | display
Mesh of the general use of Mesh.fromfile method. Of course it has a lot of overloads.

Common static Mesh FromFile (String, MeshFlags, Device, out extendedmaterial) is generally used; Method. Note that the mesh must be read after the initial D3D device. In the initial method of mesh need D3D equipment for parameters, later mesh drawing also use this device.

Set general Display properties for D3D device initialization, such as depth testing, multiple sampling, lighting rendering switches, and so on.
PresentParameters presentparams = new PresentParameters ();

Presentparams.windowed=true;

Presentparams.swapeffect = Swapeffect.discard;

Presentparams.enableautodepthstencil=true;

Presentparams.autodepthstencilformat=depthformat.d16;

presentparams.multisample=multisampletype.nonmaskable;

MyDev = new Device (0, Devicetype.hardware, this,createflags.hardwarevertexprocessing, presentparams);

Mydev.renderstate.multisampleantialias=true;

Mydev.renderstate.lighting=true;

Mydev.renderstate.cullmode=cull.none;

Mydev.renderstate.zbufferenable=true;

mydev.renderstate.zbufferfunction=compare.lessequal;

Mydev.renderstate.zbufferwriteenable=true;

Mydev.renderstate.ambient=matercolor;


PresentParameters presentparams = new PresentParameters ();

Presentparams.windowed=true;

Presentparams.swapeffect = Swapeffect.discard;

Presentparams.enableautodepthstencil=true;

Presentparams.autodepthstencilformat=depthformat.d16;

presentparams.multisample=multisampletype.nonmaskable;

MyDev = new Device (0, Devicetype.hardware, this,createflags.hardwarevertexprocessing, presentparams);

Mydev.renderstate.multisampleantialias=true;

Mydev.renderstate.lighting=true;

Mydev.renderstate.cullmode=cull.none;

Mydev.renderstate.zbufferenable=true;

mydev.renderstate.zbufferfunction=compare.lessequal;

Mydev.renderstate.zbufferwriteenable=true;

Mydev.renderstate.ambient=matercolor;



For lighting settings, you can either adjust them as needed in each of the rendering functions, or you can place the fixed lights before drawing.



In general, when drawing a mesh, each model block adopts the same world matrix. Set the Worldmatrix before you draw the mesh. Sometimes a scene inside the mesh too much, and some mesh together to form an object, for each mesh adjustment Worldmatrix can be very troublesome. So it is best to adjust the coordinates of the mesh according to relative coordinates, then use the same worldmatrix for this group of mesh. Before modifying the mesh vertex data, first use Mesh.clone to copy a mesh that controls the vertex data format.

Public Mesh Clone (MeshFlags, VertexFormats, Device);

Depending on the vertexformats format you need, you can easily traverse the modification of vertex data. Of course, don't forget to lock the data stream you want to modify before you modify it.



For the mesh contained in the material and texture, you need to manually adjust. In the mesh of the FromFile, has out a texture containing a group of extendedmaterial.

We want to declare a material group, a texture group.

texture[] Meshtextures = new texture[materials. Length];

material[] meshmaterials = new direct3d.material[materials. Length];

Then separate the material and texture.

for (int i=0; i<materials. Length; i++)

{

Meshmaterials[i] = materials[i]. Material3d;

Set the ambient color for the material. Direct3D

Does does this by default.

Meshmaterials[i]. Ambient = Meshmaterials[i]. Diffuse;

Create the texture.

Meshtextures[i] = Textureloader.fromfile (dev,materials[i). Texturefilename);

}





Now we can draw mesh.

for (int i=0; i<meshmaterials.length; i++)

{

Set the material and texture for this subset.

Device. Material = Meshmaterials[i];

Device. SetTexture (0, meshtextures[i]);



Draw the mesh subset.

Mesh. Drawsubset (i);

}

Don't forget to device in the end. EndScene ();d evice. Present ();







At the top of the D3D device at the beginning, we started the time test, so, before drawing each, call the clear function, to clean up the depth buffer, otherwise the drawing will be a step confused.





Above is the basic mesh static model drawing. For other advanced effects of drawing, write later.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.