I'm struggling to apply a texture to a mesh and keep getting this error message:
[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1
It's frustrating not understanding what the issue is... I hope someone can help me by looking at my code.
I am curious to see how the texture reacts when placed on a deformed shape.
Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - cameras</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #808080;
font-family:Monospace;
font-size:13px;
text-align:center;
background-color: #000;
margin: 0px;
overflow: hidden;
}
#info {
position: absolute;
top: 0px; width: 100%;
padding: 5px;
z-index: 100;
}
a {
color: #0080ff;
}
b { color: lightgreen }
#stats { position: absolute; top:0; left: 0 }
#stats #fps { background: transparent !important }
#stats #fps #fpsText { color: #777 !important }
#stats #fps #fpsGraph { display: none }
</style>
</head>
<body>
<div id="container"></div>
<div id="info"><a href="http://threejs.org" target="_blank">three.js</a> - cameras<br/>
<b>O</b> orthographic <b>P</b> perspective
</div>
<script src="../build/three.min.js"></script>
<script src="js/libs/stats.min.js"></script>
<script>
var scene;
var camera;
var Zinc = 0;
var texture, material, plane;
var materials = [];
texture = THREE.ImageUtils.loadTexture( "adidas.gif",{}, function(){
// assuming you want the texture to repeat in both directions:
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 1, 1 );
material = new THREE.MeshBasicMaterial({ map : texture });
init();
animate();
});
function drawSquare(x1, y1, x2, y2) {
var square = new THREE.Geometry();
// Set four points
square.vertices.push( new THREE.Vector3( x1,y2,0) );
square.vertices.push( new THREE.Vector3( x1,y1,0) );
square.vertices.push( new THREE.Vector3( x2,y1,0) );
square.vertices.push( new THREE.Vector3( x2,y2,0) );
//Push one triangle
square.faces.push( new THREE.Face3( 0,1,2) );
// Push another triangle
square.faces.push( new THREE.Face3( 0,3,2) );
// Return the square object with BOTH faces
return square;
}
/* other functions and initialization remains the same as original code */
</script>
</body>
</html>