MULTIMEDIA

DirectX 10 Game Programming : Direct3D - Textures and Details (part 3) - Drawing the Textured Object

1/7/2014 2:58:28 AM

3. Drawing the Textured Object

It might seem like a lot of work just to map a single texture to a 3D object, but once you have the changes made to the shader, that code can be reused, simplifying your job in the future.

At this point the vertex format has been changed to support texture coordinates, the texture is loaded, and the shader knows how to map that texture to the object; finally, you can see what it looks like.

The Render function that makes use of the changes you’ve already made is shown next, with the additional SetResource call made to update the texture with the shader.

/*******************************************************************
* Render
* All drawing happens in the Render function
* Inputs - void
* Outputs - void
*******************************************************************/
void Render()
{
if (pD3DDevice != NULL)
{
// clear the target buffer
pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(0.0f,
1.0f, 1.0f, 0.0f));

// Set the input layout
pD3DDevice->IASetInputLayout(gModelObject.pVertexLayout);

// Set vertex buffer
UINT stride = sizeof(VertexPosUVStruct);
UINT offset = 0;
pD3DDevice->IASetVertexBuffers(0, 1, &gModelObject.pVertexBuffer,
&stride, &offset);

// Set primitive topology
pD3DDevice-
>IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

// Set the texture resource view
pBaseTextureVariable->SetResource(pTextureRV);

// Render a model object
D3D10_TECHNIQUE_DESC techniqueDescription;
gModelObject.pTechnique->GetDesc(&techniqueDescription);

// Loop through the technique passes
for(UINT p=0; p < techniqueDescription.Passes; ++p)
{
gModelObject.pTechnique->GetPassByIndex(p)->Apply(0);
pD3DDevice->Draw(gModelObject.numVertices, 0);
}

// display the next item in the swap chain
pSwapChain->Present(0, 0);
}
}


Figure 3 shows what the texture-mapped quad should look like.

Figure 3. The texture-mapped quad.

Other  
  •  DirectX 10 Game Programming : Shaders and Effects - Geometry Shaders
  •  Adobe Photoshop CS5 : Managing Color from Monitor to Print - Working with Rendering Intents
  •  Adobe Photoshop CS5 : Managing Color from Monitor to Print - Changing from Additive (RGB) to Subtractive (CMYK) Color
  •  Adobe Photoshop CS5 : Managing Color from Monitor to Print - Setting Up Soft-Proof Colors
  •  Adobe Photoshop CS5 : Managing Color from Monitor to Print - Producing Consistent Color
  •  Adobe Flash Professional CS5 : Creating Frame-by-Frame Animation - Editing Keyframes
  •  Adobe Flash Professional CS5 : Creating Frame-by-Frame Animation - Clearing Keyframes Versus Removing Frames
  •  Adobe Flash Professional CS5 : Creating Frame-by-Frame Animation - Converting Frames to Keyframes, Using Frame-Based Versus Span-Based Selection
  •  Adobe Flash Professional CS5 : Creating Frame-by-Frame Animation - Creating Keyframes
  •  Adobe Flash Professional CS5 : Creating Frame-by-Frame Animation - Understanding Frame-by-Frame Animation
  •  
    Top 10
    Review : Sigma 24mm f/1.4 DG HSM Art
    Review : Canon EF11-24mm f/4L USM
    Review : Creative Sound Blaster Roar 2
    Review : Philips Fidelio M2L
    Review : Alienware 17 - Dell's Alienware laptops
    Review Smartwatch : Wellograph
    Review : Xiaomi Redmi 2
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8