本文整理汇总了C#中WebGLRenderingContext.uniformMatrix4fv方法的典型用法代码示例。如果您正苦于以下问题:C# WebGLRenderingContext.uniformMatrix4fv方法的具体用法?C# WebGLRenderingContext.uniformMatrix4fv怎么用?C# WebGLRenderingContext.uniformMatrix4fv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebGLRenderingContext
的用法示例。
在下文中一共展示了WebGLRenderingContext.uniformMatrix4fv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Application
//.........这里部分代码省略.........
// set to identity
var mvMatrix = __mat4.create();
var mvMatrixStack = new Stack<float[]>();
// set to perspective
var pMatrix = __mat4.create();
#region new in lesson 03
// how would this translate to non GC, NDK?
Action mvPushMatrix = delegate
{
var copy = __mat4.create();
mvMatrix.CopyTo(copy, 0);
//glMatrix.mat4.set(mvMatrix, copy);
mvMatrixStack.Push(copy);
};
Action mvPopMatrix = delegate
{
mvMatrix = mvMatrixStack.Pop();
};
#endregion
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
gl.uniformMatrix4fv(shaderProgram_pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram_mvMatrixUniform, false, mvMatrix);
};
#endregion
#region init buffers
#region cube
var cubeVertexPositionBuffer = new WebGLBuffer(gl);
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
var cubesize = 1.0f * 0.05f;
var vertices = new[]{
// Front face
-cubesize, -cubesize, cubesize,
cubesize, -cubesize, cubesize,
cubesize, cubesize, cubesize,
-cubesize, cubesize, cubesize,
// Back face
-cubesize, -cubesize, -cubesize,
-cubesize, cubesize, -cubesize,
cubesize, cubesize, -cubesize,
cubesize, -cubesize, -cubesize,
// Top face
-cubesize, cubesize, -cubesize,
-cubesize, cubesize, cubesize,
cubesize, cubesize, cubesize,
示例2: Application
//.........这里部分代码省略.........
// set to identity
var mvMatrix = __mat4.create();
var mvMatrixStack = new Stack<float[]>();
// set to perspective
var pMatrix = __mat4.create();
#region new in lesson 03
// how would this translate to non GC, NDK?
Action mvPushMatrix = delegate
{
var copy = __mat4.create();
mvMatrix.CopyTo(copy, 0);
//glMatrix.mat4.set(mvMatrix, copy);
mvMatrixStack.Push(copy);
};
Action mvPopMatrix = delegate
{
mvMatrix = mvMatrixStack.Pop();
};
#endregion
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
gl.uniformMatrix4fv(shaderProgram_pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram_mvMatrixUniform, false, mvMatrix);
};
#endregion
#region init buffers
#region cube
var cubeVertexPositionBuffer = new WebGLBuffer(gl);
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
//var cubesize = 1.0f * 0.05f;
//var cubesize = 1.0f * 0.1f;
var cubesize = 16 / 128f;
//var cubesize = 1.0f;
var vertices = new[]{
// Front face
-cubesize, -cubesize, cubesize,
cubesize, -cubesize, cubesize,
cubesize, cubesize, cubesize,
-cubesize, cubesize, cubesize,
// Back face
-cubesize, -cubesize, -cubesize,
-cubesize, cubesize, -cubesize,
cubesize, cubesize, -cubesize,
cubesize, -cubesize, -cubesize,
示例3: Application
//.........这里部分代码省略.........
{
var Theta = j * dTheta;
var cosTheta = Math.Cos(Theta);
var sinTheta = Math.Sin(Theta);
for (var i = 0; i <= nPhi; i++)
{
var Phi = i * dPhi;
var cosPhi = Math.Cos(Phi);
var sinPhi = Math.Sin(Phi);
vertices.push((f)(cosPhi * sinTheta));
vertices.push((f)(-sinPhi * sinTheta));
vertices.push((f)(cosTheta));
}
}
for (var j = 0; j < nTheta; j++)
for (var i = 0; i <= nPhi; i++)
{
ind.push((ushort)(j * (nPhi + 1) + i));
ind.push((ushort)((j + 1) * (nPhi + 1) + i));
}
var posLocation = gl.getAttribLocation(prog, "aPos");
gl.enableVertexAttribArray((uint)posLocation);
var posBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, posBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
gl.vertexAttribPointer((uint)posLocation, 3, gl.FLOAT, false, 0, 0);
var indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(ind.ToArray()),
gl.STATIC_DRAW);
//prMatrix.perspective(45, 1, .1, 100);
gl.uniformMatrix4fv(gl.getUniformLocation(prog, "prMatrix"),
false, new Float32Array(prMatrix.getAsArray()));
var mvMatrix = new CanvasMatrix4();
var mvMatLoc = gl.getUniformLocation(prog, "mvMatrix");
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.clearDepth(1.0f);
gl.clearColor(0, 0, .8f, 1f);
var xOffs = 0;
var yOffs = 0;
var drag = 0;
var xRot = 0f;
var yRot = 1f;
var transl = -15.5f;
#region drawScene
Action drawScene = delegate
{
var rotMat = new CanvasMatrix4();
rotMat.makeIdentity();
#region draw
Action<f, f, f, f, f, f, f> drawBall = (x, y, z, r, g, b, _scale) =>
{
var scale = _scale * 1.4f;
示例4: Application
//.........这里部分代码省略.........
var Theta = j * dTheta;
var cosTheta = Math.Cos(Theta);
var sinTheta = Math.Sin(Theta);
for (var i = 0; i <= nPhi; i++)
{
var Phi = i * dPhi;
var cosPhi = Math.Cos(Phi);
var sinPhi = Math.Sin(Phi);
vertices.push((f)(cosPhi * sinTheta));
vertices.push((f)(-sinPhi * sinTheta));
vertices.push((f)(cosTheta));
}
}
for (var j = 0; j < nTheta; j++)
for (var i = 0; i <= nPhi; i++)
{
ind.push((ushort)(j * (nPhi + 1) + i));
ind.push((ushort)((j + 1) * (nPhi + 1) + i));
}
var posLocation = gl.getAttribLocation(prog, "aPos");
gl.enableVertexAttribArray((uint)posLocation);
var posBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, posBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
gl.vertexAttribPointer((uint)posLocation, 3, gl.FLOAT, false, 0, 0);
var indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(ind.ToArray()),
gl.STATIC_DRAW);
var prMatrix = new CanvasMatrix4();
//prMatrix.perspective(45, 1, .1, 100);
gl.uniformMatrix4fv(gl.getUniformLocation(prog, "prMatrix"),
false, new Float32Array(prMatrix.getAsArray()));
var mvMatrix = new CanvasMatrix4();
var rotMat = new CanvasMatrix4();
rotMat.makeIdentity();
var mvMatLoc = gl.getUniformLocation(prog, "mvMatrix");
var colorLoc = gl.getUniformLocation(prog, "color");
var scaleLoc = gl.getUniformLocation(prog, "scale");
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.clearDepth(1.0f);
gl.clearColor(0, 0, .8f, 1f);
var xOffs = 0;
var yOffs = 0;
var drag = 0;
var xRot = 0f;
var yRot = 0f;
var transl = -10.5f;
#region drawBall
Action<f, f, f, f, f, f, f> drawBall = (x, y, z, r, g, b, _scale) =>
{
var scale = _scale * 1f;
mvMatrix.makeIdentity();
mvMatrix.translate(x, y, z);
mvMatrix.multRight(rotMat);
mvMatrix.translate(0, 0, transl);
gl.uniformMatrix4fv(mvMatLoc, false, new Float32Array(mvMatrix.getAsArray()));
gl.uniform1f(scaleLoc, scale);
gl.uniform3f(colorLoc, r, g, b);
示例5: drawObject
void drawObject(WebGLRenderingContext gl, foo shader, bar @object)
{
gl.useProgram(shader.program);
gl.bindBuffer(gl.ARRAY_BUFFER, @object.vertex_buffer);
gl.vertexAttribPointer((uint)shader.aVertexPosition, 3, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, @object.texturecoord_buffer);
gl.vertexAttribPointer((uint)shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture1"]);
gl.uniform1i(shader.u["uSamplerDiffuse1"], 0);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture2"]);
gl.uniform1i(shader.u["uSamplerDiffuse2"], 1);
gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture3"]);
gl.uniform1i(shader.u["uSamplerDiffuse3"], 2);
gl.activeTexture(gl.TEXTURE3);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture4"]);
gl.uniform1i(shader.u["uSamplerDiffuse4"], 3);
gl.activeTexture(gl.TEXTURE4);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture5"]);
gl.uniform1i(shader.u["uSamplerDiffuse5"], 4);
gl.activeTexture(gl.TEXTURE5);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture6"]);
gl.uniform1i(shader.u["uSamplerDiffuse6"], 5);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, @object.index_buffer);
gl.uniformMatrix4fv(shader.u["uProjectionMatrix"], false, shader.PROJECTION_MATRIX);
gl.uniformMatrix4fv(shader.u["uModelViewMatrix"], false, shader.MV_MATRIX);
gl.drawElements(gl.TRIANGLES, @object.n_elements, gl.UNSIGNED_SHORT, 0);
}
示例6: Application
//.........这里部分代码省略.........
pt.push(-h / 2);
pt.push((float)(cosPhi * r1));
pt.push((float)(sinPhi * r1)); // points
nt.push(Nx);
nt.push((float)(Ny * cosPhi));
nt.push((float)(Ny * sinPhi)); // normals
pt.push(h / 2);
pt.push((float)(cosPhi2 * r2));
pt.push((float)(sinPhi2 * r2)); // points
nt.push(Nx);
nt.push((float)(Ny * cosPhi2));
nt.push((float)(Ny * sinPhi2)); // normals
Phi += dPhi;
}
var posLoc = gl.getAttribLocation(prog, "aPos");
gl.enableVertexAttribArray((uint)posLoc);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pt.ToArray()), gl.STATIC_DRAW);
gl.vertexAttribPointer((uint)posLoc, 3, gl.FLOAT, false, 0, 0);
var normLoc = gl.getAttribLocation(prog, "aNorm");
gl.enableVertexAttribArray((uint)normLoc);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(nt), gl.STATIC_DRAW);
gl.vertexAttribPointer((uint)normLoc, 3, gl.FLOAT, false, 0, 0);
var prMatrix = new CanvasMatrix4();
gl.uniformMatrix4fv(gl.getUniformLocation(prog, "prMatrix"),
false, new Float32Array(prMatrix.getAsArray()));
var mvMatrix = new CanvasMatrix4();
var rotMat = new CanvasMatrix4();
rotMat.makeIdentity();
rotMat.rotate(-40, 0, 1, 0);
var mvMatLoc = gl.getUniformLocation(prog, "mvMatrix");
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.clearDepth(1.0f);
gl.clearColor(0, 0, .5f, 1);
var xOffs = 0;
var yOffs = 0;
var drag = 0;
var xRot = 0;
var yRot = 0;
var transl = -1.5f;
Action drawScene = delegate
{
gl.uniformMatrix4fv(gl.getUniformLocation(prog, "prMatrix"),
false, new Float32Array(prMatrix.getAsArray()));
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
rotMat.rotate(xRot / 5, 1, 0, 0);
示例7: Application
//.........这里部分代码省略.........
};
#endregion
new HTML.Images.FromAssets.crate().InvokeOnComplete(
crate =>
new HTML.Images.FromAssets.moon().InvokeOnComplete(
moon =>
{
var shaderProgram_vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
gl.enableVertexAttribArray((uint)shaderProgram_vertexPositionAttribute);
var shaderProgram_textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord");
gl.enableVertexAttribArray((uint)shaderProgram_textureCoordAttribute);
var shaderProgram_vertexNormalAttribute = gl.getAttribLocation(shaderProgram, "aVertexNormal");
gl.enableVertexAttribArray((uint)shaderProgram_vertexNormalAttribute);
var shaderProgram_pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
var shaderProgram_mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
var shaderProgram_nMatrixUniform = gl.getUniformLocation(shaderProgram, "uNMatrix");
var shaderProgram_samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler");
var shaderProgram_useLightingUniform = gl.getUniformLocation(shaderProgram, "uUseLighting");
var shaderProgram_ambientColorUniform = gl.getUniformLocation(shaderProgram, "uAmbientColor");
var shaderProgram_pointLightingLocationUniform = gl.getUniformLocation(shaderProgram, "uPointLightingLocation");
var shaderProgram_pointLightingColorUniform = gl.getUniformLocation(shaderProgram, "uPointLightingColor");
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
gl.uniformMatrix4fv(shaderProgram_pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram_mvMatrixUniform, false, mvMatrix);
var normalMatrix = glMatrix.mat3.create();
glMatrix.mat4.toInverseMat3(mvMatrix, normalMatrix);
glMatrix.mat3.transpose(normalMatrix);
gl.uniformMatrix3fv(shaderProgram_nMatrixUniform, false, normalMatrix);
};
#endregion
#region cubeVertexPositionBuffer
var cubeVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
var vertices = new f[]
{
// Front face
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
// Back face
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
// Top face
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
示例8: Application
//.........这里部分代码省略.........
// new in lesson 02
var shaderProgram_vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
gl.enableVertexAttribArray((uint)shaderProgram_vertexColorAttribute);
var shaderProgram_pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
var shaderProgram_mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
var mvMatrix = glMatrix.mat4.create();
var mvMatrixStack = new Stack<Float32Array>();
var pMatrix = glMatrix.mat4.create();
#region new in lesson 03
Action mvPushMatrix = delegate
{
var copy = glMatrix.mat4.create();
glMatrix.mat4.set(mvMatrix, copy);
mvMatrixStack.Push(copy);
};
Action mvPopMatrix = delegate
{
mvMatrix = mvMatrixStack.Pop();
};
#endregion
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
gl.uniformMatrix4fv(shaderProgram_pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram_mvMatrixUniform, false, mvMatrix);
};
#endregion
#region init buffers
var triangleVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexPositionBuffer);
var vertices = new[]{
0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f
};
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
var triangleVertexPositionBuffer_itemSize = 3;
var triangleVertexPositionBuffer_numItems = 3;
#region new in lesson 02
var triangleVertexColorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexColorBuffer);
var colors = new[]{
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f
};
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW);
var triangleVertexColorBuffer_itemSize = 4;
var triangleVertexColorBuffer_numItems = 3;
示例9: Application
//.........这里部分代码省略.........
mvMatrixStack.Push(copy);
};
#endregion
#region mvPopMatrix
Action mvPopMatrix = delegate
{
mvMatrix = mvMatrixStack.Pop();
};
#endregion
#region degToRad
Func<float, float> degToRad = (degrees) =>
{
return degrees * (f)Math.PI / 180f;
};
#endregion
// await earth
new HTML.Images.FromAssets.earth().InvokeOnComplete(
earth =>
// await metail
new HTML.Images.FromAssets.arroway_de_metal_structure_06_d100_flat().InvokeOnComplete(
metal =>
{
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
#region [uniform] mat4 uPMatrix <- pMatrix
gl.uniformMatrix4fv(currentProgram.pMatrixUniform, false, pMatrix);
#endregion
#region [uniform] mat4 uMVMatrix <- mvMatrix
gl.uniformMatrix4fv(currentProgram.mvMatrixUniform, false, mvMatrix);
#endregion
var normalMatrix = glMatrix.mat3.create();
glMatrix.mat4.toInverseMat3(mvMatrix, normalMatrix);
glMatrix.mat3.transpose(normalMatrix);
#region [uniform] mat3 uNMatrix <- normalMatrix
gl.uniformMatrix3fv(currentProgram.nMatrixUniform, false, normalMatrix);
#endregion
};
#endregion
#region handleLoadedTexture
Action<WebGLTexture, IHTMLImage> handleLoadedTexture = (texture, texture_image) =>
{
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
示例10: ApplicationContent
//.........这里部分代码省略.........
var shaderProgram_vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
gl.enableVertexAttribArray((uint)shaderProgram_vertexColorAttribute);
var shaderProgram_pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
var shaderProgram_mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
#endregion
var mvMatrix = glMatrix.mat4.create();
var mvMatrixStack = new Stack<Float32Array>();
var pMatrix = glMatrix.mat4.create();
#region new in lesson 03
Action mvPushMatrix = delegate
{
var copy = glMatrix.mat4.create();
glMatrix.mat4.set(mvMatrix, copy);
mvMatrixStack.Push(copy);
};
Action mvPopMatrix = delegate
{
mvMatrix = mvMatrixStack.Pop();
};
#endregion
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
gl.uniformMatrix4fv(shaderProgram_pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram_mvMatrixUniform, false, mvMatrix);
};
#endregion
var size = 0.03f;
#region cube
var cubeVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
#region vertices
var vertices = new[]{
// Front face RED
-size, -size, size,
size, -size, size,
size, size, size,
-size, size, size,
// Back face YELLOW
-size, -size, -size,
-size, size, -size,
size, size, -size,
size, -size, -size,
// Top face GREEN
-size, size, -size,
-size, size, size,
size, size, size,
size, size, -size,
示例11: Application
//.........这里部分代码省略.........
}
}
var n1 = nPhi + 1;
var off = 24;
for (var i = 0; i < nTheta; i++)
for (var j = 0; j < nPhi; j++)
{
((IArray<int>)(object)ind).push(i * n1 + j + off);
((IArray<int>)(object)ind).push((i + 1) * n1 + j + 1 + off);
((IArray<int>)(object)ind).push(i * n1 + j + 1 + off);
((IArray<int>)(object)ind).push(i * n1 + j + off);
((IArray<int>)(object)ind).push((i + 1) * n1 + j + off);
((IArray<int>)(object)ind).push((i + 1) * n1 + j + 1 + off);
}
#endregion
gl.enableVertexAttribArray(posLoc);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pt0), gl.STATIC_DRAW);
gl.vertexAttribPointer(posLoc, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(normLoc);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(nt), gl.STATIC_DRAW);
gl.vertexAttribPointer(normLoc, 3, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(ind),
gl.STATIC_DRAW);
var prMatrix = new CanvasMatrix4();
prMatrix.perspective(45f, 1f, .1f, 100f);
gl.uniformMatrix4fv(gl.getUniformLocation(prog, "prMatrix"),
false, new Float32Array(prMatrix.getAsArray()));
var mvMatrix = new CanvasMatrix4();
var rotMat = new CanvasMatrix4();
rotMat.makeIdentity();
rotMat.rotate(25, 1, 1, 0);
var mvMatLoc = gl.getUniformLocation(prog, "mvMatrix");
var colorLoc = gl.getUniformLocation(prog, "u_color");
var line_prog = gl.createProgram(
new LineVertexShader(),
new LineFragmentShader()
);
var lineLoc = 2U;
gl.bindAttribLocation(line_prog, lineLoc, "aPos");
gl.linkProgram(line_prog);
gl.useProgram(line_prog);
gl.uniformMatrix4fv(gl.getUniformLocation(line_prog, "prMatrix"),
false, new Float32Array(prMatrix.getAsArray()));
var mvMatLineLoc = gl.getUniformLocation(line_prog, "mvMatrix");
var pt1 = new float[]{2,1,1, -2,1,1, 2,-1,1, -2,-1,1, 2,1,-1, -2,1,-1, 2,-1,-1, -2,-1,-1,
1,2,1, 1,-2,1, 1,2,-1, 1,-2,-1, -1,2,1, -1,-2,1, -1,2,-1, -1,-2,-1,
1,1,2, 1,1,-2, -1,1,2, -1,1,-2, 1,-1,2, 1,-1,-2, -1,-1,2, -1,-1,-2
};
gl.enableVertexAttribArray(lineLoc);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
示例12: Application
//.........这里部分代码省略.........
var shaderProgram_vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
gl.enableVertexAttribArray((uint)shaderProgram_vertexColorAttribute);
var shaderProgram_pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
var shaderProgram_mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
#endregion
var mvMatrix = glMatrix.mat4.create();
var mvMatrixStack = new Stack<Float32Array>();
var pMatrix = glMatrix.mat4.create();
#region new in lesson 03
Action mvPushMatrix = delegate
{
var copy = glMatrix.mat4.create();
glMatrix.mat4.set(mvMatrix, copy);
mvMatrixStack.Push(copy);
};
Action mvPopMatrix = delegate
{
mvMatrix = mvMatrixStack.Pop();
};
#endregion
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
gl.uniformMatrix4fv(shaderProgram_pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram_mvMatrixUniform, false, mvMatrix);
};
#endregion
#region init buffers
#region pyramid
var pyramidVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, pyramidVertexPositionBuffer);
var vertices = new[]{
// Front face
0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
// Right face
0.0f, 1.0f, 0.0f,
1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
// Back face
0.0f, 1.0f, 0.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
// Left face
0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f
示例13: Application
//.........这里部分代码省略.........
mvMatrixStack.Push(copy);
};
#endregion
#region mvPopMatrix
Action mvPopMatrix = delegate
{
mvMatrix = mvMatrixStack.Pop();
};
#endregion
#region degToRad
Func<float, float> degToRad = (degrees) =>
{
return degrees * (f)Math.PI / 180f;
};
#endregion
// await earth
new HTML.Images.FromAssets.earth().InvokeOnComplete(
earth =>
// await earth_specular
new HTML.Images.FromAssets.earth_specular().InvokeOnComplete(
earth_specular =>
{
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
#region [uniform] mat4 uPMatrix <- pMatrix
gl.uniformMatrix4fv(currentProgram.pMatrixUniform, false, pMatrix);
#endregion
#region [uniform] mat4 uMVMatrix <- mvMatrix
gl.uniformMatrix4fv(currentProgram.mvMatrixUniform, false, mvMatrix);
#endregion
var normalMatrix = glMatrix.mat3.create();
glMatrix.mat4.toInverseMat3(mvMatrix, normalMatrix);
glMatrix.mat3.transpose(normalMatrix);
#region [uniform] mat3 uNMatrix <- normalMatrix
gl.uniformMatrix3fv(currentProgram.nMatrixUniform, false, normalMatrix);
#endregion
};
#endregion
#region handleLoadedTexture
Action<WebGLTexture, IHTMLImage> handleLoadedTexture = (texture, texture_image) =>
{
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture_image);
gl.texParameteri((uint)gl.TEXTURE_2D, (uint)gl.TEXTURE_MAG_FILTER, (int)gl.LINEAR);
gl.texParameteri((uint)gl.TEXTURE_2D, (uint)gl.TEXTURE_MIN_FILTER, (int)gl.LINEAR_MIPMAP_NEAREST);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
};
#endregion
var earthColorMapTexture = gl.createTexture();
示例14: Application
//.........这里部分代码省略.........
var shaderProgram_samplerUniform = getUniformLocation("uSampler");
var shaderProgram_colorUniform = getUniformLocation("uColor");
#endregion
var mvMatrix = glMatrix.mat4.create();
var mvMatrixStack = new Stack<Float32Array>();
var pMatrix = glMatrix.mat4.create();
#region mvPushMatrix
Action mvPushMatrix = delegate
{
var copy = glMatrix.mat4.create();
glMatrix.mat4.set(mvMatrix, copy);
mvMatrixStack.Push(copy);
};
#endregion
#region mvPopMatrix
Action mvPopMatrix = delegate
{
mvMatrix = mvMatrixStack.Pop();
};
#endregion
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
gl.uniformMatrix4fv(shaderProgram_pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram_mvMatrixUniform, false, mvMatrix);
};
#endregion
#region degToRad
Func<float, float> degToRad = (degrees) =>
{
return degrees * (f)Math.PI / 180f;
};
#endregion
#region currentlyPressedKeys
var currentlyPressedKeys = new Dictionary<int, bool>
{
{33, false},
{34, false},
{37, false},
{39, false},
{38, false},
{40, false}
};
Native.Document.onkeydown +=
e =>
{
currentlyPressedKeys[e.KeyCode] = true;
};
Native.Document.onkeyup +=
e =>
{
示例15: Application
//.........这里部分代码省略.........
// new in lesson 02
var shaderProgram_vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
gl.enableVertexAttribArray((uint)shaderProgram_vertexColorAttribute);
var shaderProgram_pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
var shaderProgram_mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
var mvMatrix = glMatrix.mat4.create();
var mvMatrixStack = new Stack<Float32Array>();
var pMatrix = glMatrix.mat4.create();
#region new in lesson 03
Action mvPushMatrix = delegate
{
var copy = glMatrix.mat4.create();
glMatrix.mat4.set(mvMatrix, copy);
mvMatrixStack.Push(copy);
};
Action mvPopMatrix = delegate
{
mvMatrix = mvMatrixStack.Pop();
};
#endregion
#region setMatrixUniforms
Action setMatrixUniforms =
delegate
{
gl.uniformMatrix4fv(shaderProgram_pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram_mvMatrixUniform, false, mvMatrix);
};
#endregion
#region cube
var cubeVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
var cubesize = 1.0f * 0.10f;
var vertices = new[]{
// Front face
-cubesize, -cubesize, cubesize,
cubesize, -cubesize, cubesize,
cubesize, cubesize, cubesize,
-cubesize, cubesize, cubesize,
// Back face
-cubesize, -cubesize, -cubesize,
-cubesize, cubesize, -cubesize,
cubesize, cubesize, -cubesize,
cubesize, -cubesize, -cubesize,
// Top face
-cubesize, cubesize, -cubesize,
-cubesize, cubesize, cubesize,
cubesize, cubesize, cubesize,
cubesize, cubesize, -cubesize,
// Bottom face
-cubesize, -cubesize, -cubesize,
cubesize, -cubesize, -cubesize,
cubesize, -cubesize, cubesize,
-cubesize, -cubesize, cubesize,