WebGL experiment part 2

2013-09-29 Last modified on 2021-05-24

Part 2 ! OMG !

Intro

This is a very small update, and we are going to draw this:

Polygons with colour (image from NeHe website)

The demo page is here and the code is here.

We are using the code from experiment01.

Function: drawTriangle

We are just adding the colors in our drawTriangle function:

var colors = [
  1, 0, 0,
  0, 1, 0,
  0, 0, 1
];

Then, we load them into the mesh:

triangle.setVerticesData(colors, BABYLON.VertexBuffer.ColorKind);

That's it !

Function: drawSquare

Same thing here. Adding:

var colors = [
  0.5, 0.5, 1,
  0.5, 0.5, 1,
  0.5, 0.5, 1,
  0.5, 0.5, 1
];

And loading:

square.setVerticesData(colors, BABYLON.VertexBuffer.ColorKind);

The end

I don't know yet how to not repeat the color for the square... Do you have an idea ?

See you on part 3 !