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

Parsing UV coordinates from the JSON file

Now, we will walk you through the code to show the changes that we need to perform to load the JSON file with a texture. But, first let's understand the biggest challenge we are going to face to load the JSON file in order to have the minimum memory footprint.

The challenge and the algorithm

First, let's review the basic principles of WebGL texture mapping:

  • Each texture coordinate is mapped to a vertex and vice versa. So, if we have eight vertices defined in the vertex buffer, we need eight texture coordinates. If we have 16 vertices defined in the vertex buffer, we need 16 texture coordinates. Take a look at the previous code snippets of this chapter and you will notice we had four UV values for four vertices ...

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