• 原生WebGL绘制3个点


    <html>
    <body>
    <canvas width = "300" height = "300" id = "my_Canvas"></canvas>
    <script>
    var canvas = document.getElementById('my_Canvas');
    var gl = canvas.getContext('webgl');

    var vertCode = 'attribute vec2 coordinates;' +
    'void main(void) {' +
    'gl_PointSize = 20.0;' +
    'gl_Position = vec4(coordinates, 0.0, 1.0);' +
    '}';
    var vertShader = gl.createShader(gl.VERTEX_SHADER);
    gl.shaderSource(vertShader, vertCode);
    gl.compileShader(vertShader);

    var fragCode = 'void main(void) {' +
    'gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);' +
    '}';
    var fragShader = gl.createShader(gl.FRAGMENT_SHADER);
    gl.shaderSource(fragShader, fragCode);
    gl.compileShader(fragShader);

    var shaderProgram = gl.createProgram();
    gl.attachShader(shaderProgram, vertShader);
    gl.attachShader(shaderProgram, fragShader);
    gl.linkProgram(shaderProgram);
    gl.useProgram(shaderProgram);

    var vertexBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
    var vertexArray = [0.0, -0.5, 0.0, 0.5, 0.5, 0.0];
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertexArray), gl.STATIC_DRAW);
    var coord = gl.getAttribLocation(shaderProgram, "coordinates");
    gl.vertexAttribPointer(coord, 2, gl.FLOAT, false, 0, 0);
    gl.enableVertexAttribArray(coord);
    gl.clearColor(0.0, 0.0, 0.0, 1.0);
    gl.enable(gl.DEPTH_TEST);
    gl.clear(gl.COLOR_BUFFER_BIT);
    gl.viewport(0, 0, canvas.width, canvas.height);
    gl.drawArrays(gl.POINTS, 0, 3);
    </script>
    </body>
    </html>

  • 相关阅读:
    什么是 Visual VM?
    myeclipse svn 修改用户名和密码
    unix/linux共享内存应用与陷阱
    linux内存查看方式
    Linux下crontab命令的用法
    linux ftp命令参数全集
    XmlDataSource控件绑定GridView
    VC++发布Activex控件
    SqlServer数据库自定义Split()函数
    C和C++中的主要数据类型和字节大小
  • 原文地址:https://www.cnblogs.com/shenwenkai/p/7160738.html
Copyright © 2020-2023  润新知