Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

357
Views
¿Cómo puedo hacer un círculo usando TRIANGLE_FAN en webgl usando la ecuación paramétrica para el círculo general (x + g)2 + (y + f)2 = r2

Soy nuevo en WEBGL y me enfrento a un problema al renderizar un círculo usando TRIANGLE_FAN He escrito el código completo pero no sé qué va mal al renderizar un semicírculo Está haciendo un triángulo innecesario cada vez en cualquier posición Aquí está el código dado, ¿Cómo se puede esto se soluciono este problema?

 const canvas_1 = document.getElementById("my_canvas_1"); var gl = canvas_1.getContext('webgl'); // shader Program function ourShader(){ var vertCode ='attribute vec2 coordinates;' + 'void main(void) {' + ' gl_Position = vec4(coordinates,0.0, 1.0);' + 'gl_PointSize = 1.0;'+'}'; var vertShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vertShader, vertCode); gl.compileShader(vertShader); var fragCode = 'void main(void) {' + 'gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);' + '}'; var fragShader = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(fragShader, fragCode); gl.compileShader(fragShader); var shaderProgram = gl.createProgram(); gl.attachShader(shaderProgram, vertShader); gl.attachShader(shaderProgram, fragShader); gl.linkProgram(shaderProgram); gl.useProgram(shaderProgram); return shaderProgram; } // Clear background gl.clearColor(0.0, 0.0, 0.0, 1.0); gl.enable(gl.DEPTH_TEST); gl.clear(gl.COLOR_BUFFER_BIT); var vertices = new Array(); console.log("vertices: "+vertices); let r = 0.2; let prec = 0.0001; pos = [0.0,-0.5]; let i=0; vertices.push(pos[0],pos[1]); let x = r+pos[0]; let x_ = -r+pos[0]; function drawSmallDrop(shadersProg) { if(x >= x_) { y = Math.sqrt( (r*r) - ((x-pos[0])*(x-pos[0])) ) + pos[1]; vertices.push(x,y); console.log(x,y,i); i++; x = x-prec; } if(vertices.length>=3){ var vertex_buffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); gl.bindBuffer(gl.ARRAY_BUFFER, null); gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer); var coord = gl.getAttribLocation(shadersProg, "coordinates"); gl.vertexAttribPointer(coord, 2, gl.FLOAT, false, 0, 0); gl.enableVertexAttribArray(coord); gl.drawArrays(gl.TRIANGLE_FAN, 0, vertices.length); } console.log(gl.getError());// for error check } shadProg = ourShader(); setInterval(drawSmallDrop, 1, shadProg) ; gl.viewport(0,0,canvas_1.height,canvas_1.height);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!