Microsoft DirectX 8.0 (C++) |
The code examples below show the steps required to use a volume texture.
First, specify a custom vertex type that has three texture coordinates for each vertex, as shown in this code example.
struct VOLUMEVERTEX { FLOAT x, y, z; DWORD color; FLOAT tu, tv, tw; }; #define D3DFVF_VOLUMEVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE| D3DFVF_TEX1|D3DFVF_TEXCOORDSIZE3(0))
Next, fill the vertices with data.
VOLUMEVERTEX g_vVertices[4] = { { 1.0f, 1.0f, 0.0f, 0xffffffff, 1.0f, 1.0f, 0.0f }, {-1.0f, 1.0f, 0.0f, 0xffffffff, 0.0f, 1.0f, 0.0f }, { 1.0f,-1.0f, 0.0f, 0xffffffff, 1.0f, 0.0f, 0.0f }, {-1.0f,-1.0f, 0.0f, 0xffffffff, 0.0f, 0.0f, 0.0f } };
Now, create a vertex buffer and fill it with data from the vertices.
The next step is to use the IDirect3DDevice8::CreateVolumeTexture method to create a volume texture, as shown in this code example.
LPDIRECT3DVOLUMETEXTURE8 volTexture; d3dDevice->CreateVolumeTexture( 8, 4, 4, 1, 0, D3DFMT_R8G8B8, D3DPOOL_MANAGED, &volTexture );
Before rendering the primitive, set the current texture to the volume texture created above. The code example below shows the entire rendering process for a strip of triangles.
if( SUCCEEDED( d3dDevice->BeginScene() ) ) { // Draw the quad, with the volume texture. d3dDevice->SetTexture( 0, pVolumeTexture ); d3dDevice->SetVertexShader( D3DFVF_VOLUMEVERTEX ); d3dDevice->SetStreamSource( 0, pVB, sizeof(VOLUMEVERTEX) ); d3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2); // End the scene. d3dDevice->EndScene(); }