Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function createTexture(img) {
- let texture = _gl.createTexture();
- _gl.bindTexture(_gl.TEXTURE_2D, texture);
- _gl.texParameteri(_gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE);
- _gl.texParameteri(_gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE);
- _gl.texParameteri(_gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.NEAREST);
- _gl.texParameteri(_gl.TEXTURE_2D, _gl.TEXTURE_MAG_FILTER, _gl.NEAREST);
- let mipLevel = 0;
- let internalFormat = _gl.RGBA;
- let srcFormat = _gl.RGBA;
- let srcType = _gl.UNSIGNED_BYTE;
- _gl.texImage2D(_gl.TEXTURE_2D, mipLevel, internalFormat, srcFormat, srcType, img);
- return {
- texture: texture,
- width: img.width,
- height: img.height,
- };
- }
- export function render(r, g, b, a) {
- let programData = _programs[0];
- _gl.viewport(0, 0, _gl.canvas.width, _gl.canvas.height);
- clear(r, g, b, a);
- _gl.useProgram(programData.program);
- for (var actor of _actors.keys()) {
- _gl.bindVertexArray(actor.vertexArray);
- _gl.activeTexture(_gl.TEXTURE0 + 0);
- _gl.bindTexture(_gl.TEXTURE_2D, actor.texture);
- _gl.uniform1i(programData.uniforms.image, 0);
- _gl.uniform2f(programData.uniforms.resolution, _gl.canvas.width, _gl.canvas.height);
- _gl.uniform2f(programData.uniforms.uvModifier, 1.0, 1.0);
- _gl.uniform2f(programData.uniforms.uvTranslator, 0.0, 0.0);
- _gl.drawArrays(_gl.TRIANGLES, 0, 6);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement