Tutorial 3 - Adding some colour

This tutorial is based on tutorial 2 and hence it'll only detail updates to that tutorial. We'll be adding some colour to our geometry. This is a very simple tutorial, we're not adding many lines of code but the effect is very nice.

Square.java

 
   QuadArray array = new QuadArray(4,QuadArray.COORDINATES | QuadArray.COLOR_3);
   array.setCoordinate(0,new Point3d(-1,-1,0));
   array.setColor(0,new Color3f(1.0f,0.0f,0.0f));
   array.setCoordinate(1,new Point3d(1,-1,0));
   array.setColor(1,new Color3f(1.0f,1.0f,0.0f));
   array.setCoordinate(2,new Point3d(1,1,0));
   array.setColor(2,new Color3f(0.0f,1.0f,0.0f));
   array.setCoordinate(3,new Point3d(-1,1,0));
   array.setColor(3,new Color3f(0.0f,0.0f,1.0f));
The first thing we've adding is the "QuadArray.COLOR_3". This tells the quad array that we're not just going to store coordinates but also per vertex colors.

Next, for each coordinate we add a call to array.setColor(). The colour specified will be the colour applied at the vertex. As you can see from the screen shots the colours will be merged across the surface.

Compile and run the tutorial code to see the nicely coloured square.

Get the source code
Back to the tutorials page