EN
이 콘텐츠는 한국어로 제공되지 않아 영어 버전으로 표시됩니다.

useProgram method

Set the program object to use for rendering.

IE11

Syntax

WebGLRenderingContext.useProgram(program);

Parameters

program [in]

Type: WebGLProgram

The program object.

Return value

This method does not return a value.

Remarks

Program objects can be used for multiple rendering contexts.

WebGL errorDescription
gl.INVALID_OPERATION
  • If program hasn't been linked.
  • If program isn't a WebGLProgram object, but is a WebGL generated object.
gl.INVALID_VALUEIf program isn't a WebGL generated object.

 

Examples

The following example specifies one of two programs with useProgram. For more info on this example, see Get started with WebGL.


//  Clear color buffer and set it to light gray
    gl.clearColor(1.0, 1.0, 1.0, 0.5);
    gl.clear(this.gl.COLOR_BUFFER_BIT);
            
// This draws either the grid or the photo for stretching
    if (document.getElementById("renderLines").checked)
    {
      gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer2);

      gl.useProgram(this.lineprogram);

      gl.uniform2fv(gl.getUniformLocation(this.lineprogram, "p1"), p1);
      gl.uniform2fv(gl.getUniformLocation(this.lineprogram, "p2"), p2);

      gl.vertexAttribPointer(this.texCoordLocation2, 2, gl.FLOAT, false, 0, 0);

      gl.enableVertexAttribArray(this.texCoordLocation2);

      gl.drawArrays(gl.LINES, 0, resolution * resolution * 10);
    }
    else
    { 
      gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer);
      
      gl.useProgram(this.pictureprogram);


      gl.uniform2fv(gl.getUniformLocation(this.pictureprogram, "p1"), p1);
      gl.uniform2fv(gl.getUniformLocation(this.pictureprogram, "p2"), p2);

      gl.vertexAttribPointer(this.texCoordLocation, 2, gl.FLOAT, false, 0, 0);

      gl.enableVertexAttribArray(this.texCoordLocation);


      gl.drawArrays(gl.TRIANGLES, 0, resolution * resolution * 2 * 3);
    }


See also

WebGLRenderingContext

 

 

표시:
© 2014 Microsoft