Created
February 11, 2019 15:00
-
-
Save jt0dd/36d131a02ac7daae866d02e167257a91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // the way I see this done in one example is like: | |
| vbuffer = _gl.createBuffer(); | |
| _gl.bindBuffer(ARRAY_BUFFER, vbuffer); | |
| _gl.bufferData(ARRAY_BUFFER, vertices, STATIC_DRAW); | |
| numItems = vertices.length ~/ 2; | |
| tbuffer = _gl.createBuffer(); | |
| _gl.bindBuffer(ARRAY_BUFFER, tbuffer); | |
| _gl.bufferData(ARRAY_BUFFER, textureCoords, STATIC_DRAW); | |
| aVertexPosition = _gl.getAttribLocation(program, "aVertexPosition"); // but things like this | |
| _gl.enableVertexAttribArray(aVertexPosition); // which this part relies on | |
| aTextureCoord = _gl.getAttribLocation(program, "aTextureCoord"); // and this | |
| _gl.enableVertexAttribArray(aTextureCoord); // and this | |
| uSampler = _gl.getUniformLocation(program, "uSampler"); // are values that were set in the shader code directly, | |
| // and I'm not sure how to set them otherwise | |
| // and some rendering code: | |
| _gl.bindBuffer(ARRAY_BUFFER, vbuffer); | |
| _gl.vertexAttribPointer(aVertexPosition, 2, FLOAT, false, 0, 0); | |
| _gl.bindBuffer(ARRAY_BUFFER, tbuffer); | |
| _gl.vertexAttribPointer(aTextureCoord, 2, FLOAT, false, 0, 0); | |
| _gl.bindTexture(TEXTURE_2D, playerTexture); // plus, binding the texture is done in a way I donnt see an example for in | |
| // our kernel code and he defines the texture manually, which it might be trivial to take the texture being worked with | |
| // already somewhere in the code instead, but I'm not sure how I would do it from looking at the existing code. | |
| _gl.uniform1i(uSampler, 0); | |
| _gl.drawArrays(TRIANGLES, 0, numItems); | |
| // and the way that texture is defined in the example Im citing is like: | |
| playerTexture = _gl.createTexture(); | |
| _gl.bindTexture(TEXTURE_2D, playerTexture); | |
| _gl.texImage2DUntyped(TEXTURE_2D, 0, RGBA, RGBA, UNSIGNED_BYTE, document.querySelector('#img-player')); | |
| _gl.texParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, NEAREST); | |
| _gl.texParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, LINEAR_MIPMAP_NEAREST); | |
| _gl.generateMipmap(TEXTURE_2D); | |
| _gl.bindTexture(TEXTURE_2D, null); | |
| and his shaders are like: | |
| <script id="vertex" type="x-shader"> | |
| attribute vec2 aVertexPosition; | |
| void main() { | |
| gl_Position = vec4(aVertexPosition, 0.0, 1.0); | |
| } | |
| </script> | |
| <script id="fragment" type="x-shader"> | |
| #ifdef GL_ES | |
| precision highp float; | |
| #endif | |
| uniform vec4 uColor; | |
| void main() { | |
| gl_FragColor = uColor; | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment