Appendix F. Load Shader Programs from Files
All the sample programs in this book embed the shader programs in the JavaScript program, which increases the readability of the sample programs but makes it hard to construct and maintain the shader programs.
As an alternative, you can load the shader programs from files by using the same methods described in the section “Load and Display 3D Models” in Chapter 10, “Advanced Techniques.” To see how that’s done, let’s modify ColoredTriangle
from Chapter 5, “Using Colors and Texture Images,” to add support for loading shaders from a file. The new program is called LoadShaderFromFiles
, which is shown in Listing F.1.
Get WebGL Programming Guide: Interactive 3D Graphics Programming with WebGL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.