Home > front end >  Webgl plot points run out as a result, help me to look at where there are problems
Webgl plot points run out as a result, help me to look at where there are problems

Time:09-27

File



<meta charset="utf-8"/& gt;
The draw point

Both please ues the browser supporting "canvas".


<script SRC="https://bbs.csdn.net/lib/cuon-matrix.js" & gt; </script>
<script SRC="https://bbs.csdn.net/topics/.. Lib/webgl - debug. Js & gt; "" </script>
<script SRC="https://bbs.csdn.net/topics/.. Lib/cuon - utils. Js & gt; "" </script>
<script SRC="https://bbs.csdn.net/topics/js/drawpoint1.js" & gt; </script>


JS file
Var VSHADER_SOURCE='void main () {\ n' + 'gl_Position=vec4 (0.0, 0.0, 0.0, 1.0); \ n '+//set the coordinate gl_PointSize=10.0; \ n} '+/size/set' \ n ';
Var FSHADER_SOURCE='void main () {\ n' + 'gl_FragColor=vec4 (1.0, 0.0, 0.0, 1.0); \ n} '+//set colors' \ n';
The function main () {//access & lt; canvas> Element var canvas=document. GetElementById (" webgl ");
//get webgl graphics context var gl=getWebGLContext (canvas);
if(! Gl) {
The console. The log (" failed to get webgl ");
return; }
//initialize shader
If (initShader (gl, VSHADER_SOURCE FSHADER_SOURCE)) {
The console. The log (" failed to initialize shaders "); }
//specify clear & lt; canvas> Color gl. ClearColor (0.0, 0.0, 0.0, 1.0);
//to empty & lt; canvas>
Gl. The clear (gl. COLOR_BUFFER_BIT);
//draw a point
Gl. DrawArrays (gl) POINTS, 0, 1)}

CodePudding user response:

1, you also need to introduce webgl - utils. Js
2, should be initShaders
  • Related