Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

WebGL example for beginners in computer graphics

WebGL example for beginners in computer graphics

8Observer8
8Observer8
My Instructions for beginners · · 1 min read
3,676 0

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);


Discussion

Loading comments...