WebGL
How do I make an webgl?
What is a webgl? How do you make a webgl? This script and codes were developed by Joseph1401 on 16 September 2022, Friday.
WebGL - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>WebGL</title>
</head>
<body> <canvas id="glcanvas" width="640" height="480"> Your browser doesn't appear to support the <code><canvas></code> element. </canvas>
<script id="shader-fs" type="x-shader/x-fragment"> void main(void) { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }
</script>
<script id="shader-vs" type="x-shader/x-vertex"> attribute vec3 aVertexPosition; uniform mat4 uMVMatrix; uniform mat4 uPMatrix; void main(void) { gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); }
</script> <script src='https://code.jquery.com/jquery-2.2.4.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
WebGL - Script Codes JS Codes
var gl;
$(function(){ var canvas = document.getElementById('glcanvas'); gl = initWebGL(canvas); if(!gl){ return; } gl.clearColor(0.0,0.0,0.0,1.0); gl.enable(gl.DEPTH_TEST); gl.depthFunc(gl.LEAUAL); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); gl.viewport(0, 0, canvas.width, canvas.height); initShaders(); // Here's where we call the routine that builds all the objects // we'll be drawing. initBuffers(); // Set up to draw the scene periodically. setInterval(drawScene, 15);
})
function getShader(gl, id, type){ var shaderScript, theSource, currentChild, shader; shaderScript = document.getElementById(id); if(!shaderScript){ return null; } theSource = shaderScript.text; if(!type){ if(shaderScript.type == 'x-shader/x-fragment'){ type = gl.FRAGMENT_SHADER; } else if(shaderScript.type == 'x-shader/x-vertex'){ type = gl.VERTEX_SHADER; } else{ return null; } } shader = gl.createShader(type); gl.shaderSource(shader, theSource); gl.complieShader(shader); if(!gl.getShaderParameter(shader, gl.COMPILE_STATUS)){ alert("An error occurred compiling the shaders: " + gl.getShaderInfoLog(shader)); gl.deleteShader(shader); return null; } return shader;
}
function initWebGL(canvas){ gl = null; gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl'); if(!gl){ alert("NO WEBGL SUPPORT ON BROWSER"); } return gl;
}
function initShaders(){ var fragmentShader = getShader(gl, 'shader-fs'); var vertexShader = getShader(gl,'shader-vs'); var shaderProgram = gl.createProgram(); gl.attachShader(shaderProgram , vertexShader); gl.attachShader(shaderProgram , fragmentShader); gl.linkProgram(shaderProgram); if(!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)){ alert(gl.getProgramInfoLog +"SHADER NOT INIT"); } gl.useProgram(shaderProgram); vertexPositionAttribute = gl.getAttribLocation(shaderProgram, 'aVertexPosition'); gl.enableVertexAttribArray(vertexPositionAttribute);
}
var horizAspect = 480.0/640.0;
function initBuffers() { squareVerticesBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesBuffer); var vertices = [ 1.0, 1.0, 0.0, -1.0, 1.0, 0.0, 1.0, -1.0, 0.0, -1.0, -1.0, 0.0 ]; gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
}
function drawScene() { gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); perspectiveMatrix = makePerspective(45, 640.0/480.0, 0.1, 100.0); loadIdentity(); mvTranslate([-0.0, 0.0, -6.0]); gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesBuffer); gl.vertexAttribPointer(vertexPositionAttribute, 3, gl.FLOAT, false, 0, 0); setMatrixUniforms(); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
Developer | Joseph1401 |
Username | jmills4122 |
Uploaded | September 16, 2022 |
Rating | 3 |
Size | 2,710 Kb |
Views | 32,384 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
TicTacToe | 4,955 Kb |
Diagonal menu Test | 2,382 Kb |
Collections Viewer | 2,524 Kb |
Button Stuff | 3,099 Kb |
TODO | 1,381 Kb |
Bianary | 2,442 Kb |
Tree Processor | 16,330 Kb |
Quote Generator | 4,410 Kb |
A Pen by Joseph1401 | 2,721 Kb |
Current Weather | 3,714 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Button fills | Zubfatal | 5,205 Kb |
Process Accordion | Devilskitchen | 31,432 Kb |
Exploding Text | Jjmartucci | 4,749 Kb |
CSS Bot Confusion | Jpod | 3,456 Kb |
Ball Physics | Getsetbro | 3,149 Kb |
Michelle, submit your photography to Unsplash. | Zaneriley | 3,368 Kb |
Tumblr API | Juanv911 | 2,436 Kb |
RollOver Effect 2 | Lmack90 | 2,162 Kb |
Responsive Boxes without Images | Andymcfee | 4,120 Kb |
CSS3 keyframe onload animation. | Samueljseay | 1,706 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!