September 15, 2010

Drawing Simple Shapes – Triangle, Square in WebGL

Our first assignment asked us to draw simple shapes using WebGL. For this particular project I drew a simple square and triangle. Here is a screen shot of my work.

If you have a WebGl capable browser, then follow the link and you can test it yourself. Make sure you view source on the page. I heavily commented the code.

Here are the three files you need to run this lesson.
lesson1.html
sylvester.js
glUtils.js

  1. How can i write this code in a stand alone java script file

    #ifdef GL_ES
    precision highp float;
    #endif

    void main(void) {
    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
    }

    attribute vec3 aVertexPosition;

    uniform mat4 uMVMatrix;
    uniform mat4 uPMatrix;

    void main(void) {
    gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
    }

    and then call it again

    Comment by maram — May 16, 2012 @ 6:41 am

Leave a comment