Let's start with something super basic : we'll draw a single triangle.
First of all we define a surface where we are going to draw.
In the javascript code, we'll get a reference to this surface, and instead of calling webgl2 stuff directly, we will call whatever we need through lg.
Now we write down a list of point coordinates, here in 2d.
Now we send the data to the GPU. It looks silly with small amount of data, but this is required.
Now we write a GPU program that will decide where to put each point we previously listed on the screen.
vs stands for "Vertex Shader". it will be executed for each 2d point of
Now we write a GPU program that will decide what color to draw on screen.
fs stands for "Fragment Shader". it will be executed for each pixel coverd by whatever we are drawing.
If we are drawing a Triangle, it will be called for every pixels that triangle covers on screen, if it is a Point, then it will fill a square box, etc...
In game engines, this is the place you would expect sophisticated lighing stuff to be rendered. But for this basic example we will simply make it red.
Now we compile the GPU program using our
And at last, we can render our triangle ! We will tell our program to interpret our list of points as a strip of triangles (
We ask to render
We tell it that we want to have all points of our list, which is
If you want to animate, you can make a loop like this.
But DON'T USE
The