Using textures
Until now, we've only used plain colors for our 3D objects. But, you can also use images to fill your 3D shape. These images are called textures and can be used to add more character to your 3D scene.
Getting ready
Create two images of 640 x 640 pixels each, and add them to the data folder of your sketch. If you have forgotten how to do this, you can take a look at the recipe Working with images, in Chapter 2, Drawing Text, Curves, and Shapes in 2D.
How to do it...
The first thing you need to do is to import the OpenGL library and declare two PImage
objects for your images.
import processing.opengl.*; PImage texture1; PImage texture2;
In the setup()
function, you'll set the size of your window and load the images from the hard drive.
void setup() { size( 640, 480, OPENGL ); noStroke(); texture1 = loadImage("stones.jpg"); texture2 = loadImage("lines.jpg"); }
Inside the draw()
function, we'll draw two squares. We'll add textures to them, using the texture()
function. For...