Drawing Something - The TheoryOkay, so you’ve learnt how to initialize a Direct3D application in Visual Basic - wow. Hardly cutting edge visuals, and completely useless as well. So I’m pretty sure that you want to learn how to draw something. Drawing In Direct3D is extremely simple when you get your head around it, but it requires a fair amount of work and memory before you can get to this point. The first part is understanding what the different words mean - right now we’ll stick to the simple definitions and elaborate on them as we get more advanced later on. 1. Vertices (plural of vertex)
2. Polygon
3. Face
4. Textures
5. Mesh
Now that you have those words floating around we can start doing some interesting things. Don’t swear by the above definitions though - they are very lose and are only there to offer a basic introduction to the terms, more complex and meaningful definitions will be offered as and when they are necessary. The first thing I want to cover is the 3 types of vertex that you can use. While the structure of Direct3D allows for 100’s of different combinations there are three types that will serve most situations - and all other situations will be adaptations or modification of these three. 1. Untransformed and Unlit vertex
2. Untransformed and Lit vertex
3. Transformed and Lit vertex
Yet more things to remember… But before we go through a simple demonstration of how to use these vertices there is one more thing you need to know. Flexible Vertex Formats. As I mentioned earlier, Direct3D allows for 100’s of possible vertex types - it is through this system of Flexible Vertex Formats (FVF) that we achieve this. A flexible vertex format description is a variable of type Long that is a combination of flags that Direct3D can use to work out what format the data you pass it is in. If you pass invalid, or incorrect for the data you use one of two things will happen: Nothing will be rendered, or something very strange will be rendered. The vertex formats for the 3 main types look like this: Const FVF_TLVERTEX = (D3DFVF_XYZRHW Or D3DFVF_TEX1 Or D3DFVF_DIFFUSE Or D3DFVF_SPECULAR) Const FVF_LVERTEX = (D3DFVF_XYZ Or D3DFVF_DIFFUSE Or D3DFVF_SPECULAR Or D3DFVF_TEX1) Const FVF_VERTEX = (D3DFVF_XYZ Or D3DFVF_NORMAL Or D3DFVF_TEX1) And their UDT structures will look like this: Private Type TLVERTEX X As Single Y As Single Z As Single rhw As Single color As Long Specular As Long tu As Single tv As Single End Type Private Type LITVERTEX X As Single Y As Single Z As Single color As Long Specular As Long tu As Single tv As Single End Type Private Type VERTEX X As Single Y As Single Z As Single nx As Single ny As Single nz As Single tu As Single tv As Single End Type Right this second you don’t really need to know all of these - I put them in mainly for reference purposes; those of you familiar with DirectX7 in Visual Basic, or DirectX in another language may well want to jump ahead slightly. In the next section we’ll extend our sample program to render some basic 2D and 3D geometry in fullscreen mode. It may sound like a small task, but you’ve got the mountain to climb yet my friend.
|