WebGL example for beginners in computer graphics

Published October 07, 2019
Advertisement

It is my example how to draw a triangle using WebGL and TypeScript: https://plnkr.co/edit/PkqSZGwhv9zKSnUNSiXo?p=preview

Just fork my example, change it, save and send a new link to your friends.

I use glMatrix library for math. You can find in the ShaderProgram.ts file hwo I set scale, rotation, and translation:

       


        let modelMatrix = mat4.create();
        mat4.translate(modelMatrix, modelMatrix, vec3.fromValues(0, 0.5, 0));
        mat4.rotateZ(modelMatrix, modelMatrix, 20.0 * Math.PI / 180.0);
        mat4.scale(modelMatrix, modelMatrix, vec3.fromValues(0.5, 0.5, 1));
        
        let u_ModelMatrix = gl.getUniformLocation(this.program, "u_ModelMatrix");
        gl.uniformMatrix4fv(u_ModelMatrix, false, modelMatrix);


 

Triangle.png

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement