Introduction to 3D game programming (11) fvf format and elements of d3d Basics

Source: Internet
Author: User
Introduction to 3D game programming (11) fvf format and elements of d3d Basics

(13:49:05)

ReprintedBytes
   
  Continue with d3d today. If time is enough, you can draw a simple triangle surface.
 
  Basic d3d concepts
 
  (1) Flexible vertex format fvf
              In fact, this is a structure that we declare and define. In this structure, we store metadata vertices, and we use it in programs to record the attributes of all vertices,DX itself has certain limitations on it, that is, to limit the order of parameters of various types when designing its properties. In this fvf, we can set the vertex's:
              1: Position X, Y, zcoordinate 2: rhw (converted vertex, W reciprocal) 3: Hybrid weighted value 4: normal of vertex 5: diffuse color (diffuse attribute) 6. ReflectionColor (mirror reflection attribute) 7. texture coordinate sets (UV coordinates)
              We can select some attributes for setting based on different needs, which is more convenient than setting all hard. When drawing a graph, the computer will refer to our settings.The necessary components save a lot of memory and rendering time. However, some attributes are not set, but the order cannot be reversed.
              We can find the msdn or dxdev help document to search for fvf. The fvf format can be a combination of the following types:
D3dfvf_xyz contains unconverted vertex coordinates
D3dfvf_xyzrhw contains the converted vertex coordinates
D3dfvf_xyzw contains the transformed and cropped vertex coordinates.
D3dfvf_xyzb1 ......... D3dfvf_xyzb5 contains the vertex used for skeleton animation and the weight information of the vertex on the skeleton.
D3dfvf_normal contains the normal information.
D3dfvf_psize vertex information indicates the drawing point size
D3dfvf_diffuse contains the diffuse reflection information.
D3dfvf_specular contains the information of the mirror reflection.
D3dfvf_tex0 ......... D3dfvf_tex8 contains 0-8 texture coordinates
          When we need more than two parameters at the same time, we can add a bit or character to the definition.      (2) vertex buffer)
        It is a memory buffer used in d3d to save vertex data. It is worth noting that the vertex buffer settings should be set in the video memory, because our CPU memory andThere is no way to compare the speed of reading data from the video memory, but because the video memory can store less data, we need to do everything possible to deliver the data to the video memory that will be rendered, even if the data is large, we need to separate and deliver the data based on the video memory speed to avoid direct rendering in the system memory as much as possible. This will be explained in more detail in subsequent settings.
        (3) coordinate system.
          Well, there is nothing to say. It is worth noting that we use the left-hand Coordinate System in d3d, that is, the positive direction of the Z axis is inside the screen, the modeling software such as 3dmax isThe right-hand coordinate system, that is, the positive direction of the Z axis is outside the screen.
        (4) elements.
          In the field of 3D graphics, we often use multiple groups of polygon to enclose an object surface to simulate an object. If there are 3D contacts such as 3 DMAX and MayaModeling software is easier to understand. Our objects are hollow and only spliced by some patches, which are usually made up of smaller elements. In d3d, we use trianglemesh for splicing.
        (5) primitive types
          I have just said that we use a triangle mesh for graphical representation, but in fact, there are six d3d primitive types, and there are also three ways to create triangle elements. Learn about themThe principle is of great benefit to optimizing the program algorithm.
Point column set     D3dpt_pointlist   A set of points
Line column set     D3dpt_linelist         A set of Line Segments
Cable band set     D3dpt_linestrip     Set of line segments connected at the beginning and end
Triangle Column     D3dpt_trianglelist         A set of triangles
Triangle band     D3dpt_trianglestrip A triangle connected at the beginning and end, with two vertices overlapping
Triangle fan     D3dpt_trianglefan         A group of triangles that make up slice.
1: It is quite easy to draw points. We can give the spatial coordinates of the points, and then draw them separately.
Example: g_pd3ddevice-> drawprimitive (d3dpt_pointlist, 0, 6 ); // Six points are drawn.
Well, g_pd3ddevice is the pointer of the d3d device. The first parameter of the function is the flexible vertex format structure we set, 0 is the offset, and 0 represents the first vertex from the fvf structure.Start to draw. 6 is to draw 6 elements from the offset.
2: line Column
G_pd3ddevice-> drawprimitive (d3dpt_linelist, 0, 3 );   // Three line segments may not be connected
The parameter is similar to the vertex. By default, the system connects the 1st points and 2nd points in the fvf structure into a line segment, and the 3rd points and 4th points are connected into a line segment.What we get is a series of lines that may not be connected.
3: cable band
G_pd3ddevice-> drawprimitive (d3dpt_linestrip, 0, 5 ); // Draw 5 lines that must be connected
The parameter is not mentioned. It is worth noting that the difference between the cable band and the line column is that the system will connect, and by default, and so on, weThe result is a series of connected line segments. Of course, under the same point, the obtained line segments are more than the line columns,
4: triangle fan
G_pd3ddevice-> drawprimitive (d3dpt_trianglefan, 0, 4 ); // Four closely connected triangular rows are drawn.
This method is to draw a triangle at, 2, and draw a triangle at, 3, followed by, 4... Er, it's better to draw a picture later.
5: triangle row and column
G_pd3ddevice-> drawprimitive (d3dpt_trianglelist, 0, 2 ); // Two unconnected triangles will be drawn
This draw method is to draw a triangle at and, and draw a triangle at and.
6: triangle band
G_pd3ddevice-> drawprimitive (d3dpt_trianglestrip, 0, 4 ); // Draw four connected triangles
This draw method is to draw a triangle, 1, 2, 3, draw a triangle line, 2, 3, 4 draw a triangle line.
Er, I made a picture, and the mouse broke down. The touch screen was messy. It was not beautiful. It would be nice to see it clearly.I will summarize the methods for drawing elements:
Hresultdrawprimitive (                
          D3dprimitivetype     Primitivetype, // Basic primitive type
          Uintstartvertex,       // Start Vertex
          Uintprimitivecount                 // Number of elements to be drawn
); 

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.