O'Reilly logo

WebGL Game Development by Sumeet Arora

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading textures

Let's first understand a few important WebGL API functions before diving into the code.

The gl.pixelStorei function sets pixel storage modes for readPixels and unpacks textures with texImage2D and texSubImage2D. The gl.pixelStorei function is declared as follows:

void gl.pixelStorei(GLenum pname, GLint param)

Let's see what each parameter of this function does:

  • pname: This parameter specifies the pixel storage type; it must be either gl.PACK_ALIGNMENT, gl.UNPACK_ALIGNMENT, or gl.UNPACK_FLIP_Y_WEBGL
  • param: This parameter specifies the Boolean value for the pack or unpack alignment

The gl.pixelStorei function is not used for a particular texture but is a global setting for all textures used in our current graphics context. We will use ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required