WebGL 기초( 5 - 도형 이동 ) 이번에는 삼각형에 움직임을 추가해보려고 합니다.
이를 위해서 애니메이션 루프를 설정해야하는데
앞의 두 메서드가 아닌 requestAnimationFrame 사용하려는 이유는
애니메이션을 만들게 될때 씬의 뷰를 움직이는 방법이있는데,
requestAnimationFrame 지원이 브라우저마다 다르기때문에https://www.paulirish.com/2011/requestanimationframe-for-smart-animating/ 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <script >                        initShader();   setupBuffers();   (function  animLoop (     setupWebGL();     setupDynamicBuffers();     drawScene();     requestAnimationFrame(animLoop, canvas);   })(); </script > 
requestAnimationFrame의 첫번째 파라미터는 콜백 함수이고,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 <script >   var  angle = 0.0 ;   function  setupDynamicBuffers (          var  x_translation = Math .sin(angle)/2.0 ;                      var  positionsColor = [         -0.5  + x_translation,  0.5  + x_translation,          -0.5  + x_translation, -0.5  + x_translation,          0.5  + x_translation, -0.5  + x_translation,        ];            positionsColorBuffer = gl.createBuffer();       gl.bindBuffer(gl.ARRAY_BUFFER, positionsColorBuffer);       gl.bufferData(gl.ARRAY_BUFFER, new  Float32Array (positionsColor), gl.DYNAMIC_DRAW);            var  triangleVertices = [         -0.5  + x_translation,  0.5  + x_translation,          -0.5  + x_translation, -0.5  + x_translation,          0.5  + x_translation, -0.5  + x_translation,        ];       angle += 0.01;            trianglesVerticeBuffer = gl.createBuffer();       gl.bindBuffer(gl.ARRAY_BUFFER, trianglesVerticeBuffer);       gl.bufferData(gl.ARRAY_BUFFER, new  Float32Array (triangleVertices), gl.DYNAMIC_DRAW);   } </script > 
가장 중요한 것은 정점이나 데이터가 변경될때는 정점의 타입을
            
            
            
            
                
    
Comments: