Hello Cube: Textures
This example shows how texture map a cube using an image fetched from a URL.
Image URL:
// World View Projection matrix that will transform the input vertices // to screen space. uniform mat4 worldViewProjection; // input parameters for our vertex shader attribute vec4 position; attribute vec2 texCoord0; varying vec2 uvs; /** * The vertex shader simply transforms the input vertices to screen space. */ void main() { // Multiply the vertex positions by the worldViewProjection matrix to // transform them to screen space. gl_Position = worldViewProjection * position; uvs = texCoord0; }
// Color to draw with. uniform sampler2D texSampler0; varying vec2 uvs; /** * This pixel shader just returns the color red. */ void main() { gl_FragColor = texture2D(texSampler0, uvs); }