Wednesday, December 19, 2018

Lets create a square webgl

wEBGL programming : Most of time i think "simple idea & simple design ", because developers just like me good in programming , poor in design and colors. We are weird guys who talk to their computer day  & night. I admit we treat computer problems just like a boy treat his female friend. Polite,care etc etc. One day i and my friend discuss about graphics and programming. Her view is that we're awesome in programming , but no one like our  creation because of poor interface , bad color scheme. So i try webgl for my own game which i'm only working at holidays.

I try to create a square using programming called webgl. Webgl graphics for web browsers, mobile browsers. 
This code you already familiar about .
you can use canvas tag for draw on web page. 
document.getElementById used in js which a one param, in my case it is game. This tells where you take start.
initWebgl user defined function which is used to get canvas reference.
 try catch is used because some browsers doesn't support webgl. If you web browser support then you initialize webgl like this var gl= canvas.getContext("webgl"); Now we have reference and our browser support webgl too.
this function need two parameters one is webgl reference and other is location where image will draw. For this task call gl.viewport function called
1. create a buffer
2. bindbuffer with array and newly create buffer called vertexBuffer.
3.set verts for your square {-1.0,1.0}
4.extract buffer data [gl.ARRAY_BUFFER {destination}, new Float32Array(param){source} and draw( i think this for animation )]
5. what to draw, how many vertex,total vertex, type 

 modelViewMatrix means 3d shape of object.
projectionMatrix means project 3d shape into 2d . [object project on camera]
vertexShaderSource and fragementShaderSource write onces in program , they are just like high level code
   vertexShaderSource take care projection on camera , 3d shape object
   fragementShaderSource take care pixel color

clearColor or clear clear the screen before rendering
useProgram need shader 
vertexAttribPointer take care vertex attribute on render
uniformMatrix4fv need projection and 3d model