Mixing 2D and 3D objects
On some occasions, you'll want to draw 2D objects on top of your 3D environment. In this recipe, we'll take a look at how you can do this. This will be handy if you want to draw an interface or some text on top of everything.
How to do it...
The first thing to do is to set up an OpenGL window of 640 x 480 pixels. You should know this by now, since you've done it before in the previous recipes. You should also declare a float variable named n
. We'll be using this variable to calculate 3D perlin noise for animating the size of the cubes in our 3D world. The first part of your sketch looks like the following:
import processing.opengl.*; float n; void setup() { size( 640, 480, OPENGL ); n = 0.0f; }
The next thing we'll do is drawing a grid of cubes. We'll change the value of the n
variable by adding 0.01 to each frame, so we get a different noise value for each cube. Type the following code inside the draw()
function and run it to see what happens.
hint( ENABLE_DEPTH_TEST...