WebGL Fundamentals

12:31 PM

So, the long Diwali vacations are over and we are back to business. I left the journey at the verge of starting to learn WebGL. And god it was tiring. Today, I managed to create a simple figure, and apply some basic operations like translate, scale and rotate on the figure.

So, to create a WebGL program, you need to do quite a lot of setup. 
  • First you need to create a HTML Canvas element, since all of the magic that WebGL does happens inside this.
  • Then you need to get the webgl context of this element.
  • WebGL is basically a rasterization engine, that runs on 2 shaders, Vertex and Fragment. The vertex shader tells the GPU the position of each vertex on the screen, and the fragment shader is used to determine the colour of each pixel.
  • You need to create these 2 shader programs, which are written in GLSL, a shader language, which is written in a C/C++ type syntax. 
  • Then you need to compile these shaders, and create a program and link those shaders with it.
  • Then you need to bind the global variables your shaders use, and populate the buffer ( what to draw on screen) with positions of your vertexes.
  • Finally you need to draw the pixel position, using GL primitive triangles.
This may sound like you need to code much, but actually there are all built in methods to do these tasks. You just need to execute them.

This is today's final program, You can translate using arrow keys, rotate using a & d, and scale using i,j,k and l.


Comments

Popular posts from this blog

WebGL - Perspective

WebGL - Orthographic 3D

Cursor and Serial Ports