Texturing a cloth simulation
In this recipe, we will learn how to apply a texture to the cloth simulation we created in the Creating a cloth simulation recipe of the current chapter.
Getting ready
We will be using the cloth simulation developed in the recipe Creating a cloth Simulation as the base for this recipe.
You will also need an image to use as texture; place it inside your assets
folder. In this recipe we will name our image texture.jpg
.
How to do it…
We will calculate the correspondent texture coordinate to each particle in the cloth simulation and apply a texture.
Include the necessary files to work with the texture and read images.
#include "cinder/gl/Texture.h" #include "cinder/ImageIo.h"
Declare a
ci::gl::Texture
object in your application's class declaration.gl::Texture mTexture;
In the
setup
method load the image.mTexture = loadImage( loadAsset( "image.jpg" ) );
We will remake the
draw
method. So we'll erase everything in it which was changed in the Creating a cloth simulation recipe...