Skip to Content
Real-Time 3D Graphics with WebGL 2 - Second Edition
book

Real-Time 3D Graphics with WebGL 2 - Second Edition

by Farhad Ghayour, Diego Cantor
October 2018
Intermediate to advanced
500 pages
12h 40m
English
Packt Publishing
Content preview from Real-Time 3D Graphics with WebGL 2 - Second Edition

Time for Action: Rendering a Square Using a VAO

Let's refactor a previous example using VAOs:

  1. Open up ch02_01_square.html in your editor.
  2. First, we update our global variables:
// Global variables that are set and used// across the applicationlet gl,  program,  squareVAO,  squareIndexBuffer,  indices;
  1. We've replaced squareVertexBuffer with squareVAO, as we no longer need to reference the vertex buffer directly.
  1. Next, we update the initBuffers functions as follows:
// Set up the buffers for the squarefunction initBuffers() {  /*    V0                    V3    (-0.5, 0.5, 0)        (0.5, 0.5, 0)    X---------------------X    |                     |    |                     |    |       (0, 0)        |    |                     |    |                     |    X---------------------X    V1                    V2    (-0.5, -0.5, 0)       (0.5, -0.5, 0)  */  const vertices = [    -0.5, 0.5, 0,    -0.5, -0.5, 0,    0.5, -0.5, 0,
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

WebGL Programming Guide: Interactive 3D Graphics Programming with WebGL

WebGL Programming Guide: Interactive 3D Graphics Programming with WebGL

Kouichi Matsuda, Rodger Lea
3D Graphics Rendering Cookbook

3D Graphics Rendering Cookbook

Sergey Kosarevsky, Viktor Latypov

Publisher Resources

ISBN: 9781788629690Supplemental Content