Skip to content

createShader() ​

ts
function createShader(
  gl: WebGL2RenderingContext,
  source: string,
  type: number,
): WebGLShader | null;

Creates, compiles, and returns a WebGL shader.

It automatically handles conversion of the source code to GLSL 3.00 ES (e.g., adding #version 300 es, handling texture2D vs texture, etc.).

Parameters ​

gl ​

WebGL2RenderingContext

The WebGL2 context.

source ​

string

Shader source string.

type ​

number

Shader type (gl.VERTEX_SHADER or gl.FRAGMENT_SHADER).

Returns ​

WebGLShader | null

The compiled WebGLShader, or null if creation or compilation failed.

Released under the MIT License.