本文整理汇总了C#中WebGLRenderingContext.useProgram方法的典型用法代码示例。如果您正苦于以下问题:C# WebGLRenderingContext.useProgram方法的具体用法?C# WebGLRenderingContext.useProgram怎么用?C# WebGLRenderingContext.useProgram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebGLRenderingContext
的用法示例。
在下文中一共展示了WebGLRenderingContext.useProgram方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Application
/* Source: http://www.ibiblio.org/e-notes/webgl/models/ethanol.html
* http://www.worldofmolecules.com/3D/dopamine_3d.htm
*/
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IDefault page = null)
{
var prMatrix = new CanvasMatrix4();
var gl_viewportWidth = 500;
var gl_viewportHeight = 500;
var gl = new WebGLRenderingContext();
var canvas = gl.canvas.AttachToDocument();
#region AtResize
Action AtResize =
delegate
{
gl_viewportWidth = Native.window.Width;
gl_viewportHeight = Native.window.Height;
prMatrix = new CanvasMatrix4();
prMatrix.perspective(45f,
(f)Native.window.aspect,
1f, 100f);
canvas.style.SetLocation(0, 0, gl_viewportWidth, gl_viewportHeight);
canvas.width = gl_viewportWidth;
canvas.height = gl_viewportHeight;
};
Native.window.onresize +=
e =>
{
AtResize();
};
AtResize();
#endregion
Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;
var h = 1f;
var r1 = .5f;
var r2 = .2f;
#region requestPointerLock
var __pointer_x = 0;
var __pointer_y = 0;
canvas.onmousedown +=
delegate
{
canvas.requestPointerLock();
};
canvas.onmousemove +=
e =>
{
if (Native.Document.pointerLockElement == canvas)
{
__pointer_x += e.movementX;
__pointer_y += e.movementY;
}
};
canvas.onmouseup +=
delegate
{
//Native.Document.exitPointerLock();
};
#endregion
var prog = gl.createProgram(
new GeometryVertexShader(),
new GeometryFragmentShader()
);
gl.linkProgram(prog);
gl.useProgram(prog);
var uniforms = prog.Uniforms(gl);
//.........这里部分代码省略.........
示例2: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IDefault page = null)
{
// view-source:http://mrdoob.com/lab/javascript/webgl/glsl/04/
var time = new Stopwatch();
time.Start();
var parameters_screenWidth = 0;
var parameters_screenHeight = 0;
var gl = new WebGLRenderingContext();
var canvas = gl.canvas.AttachToDocument();
#region IsDisposed
var IsDisposed = false;
Dispose = delegate
{
if (IsDisposed)
return;
IsDisposed = true;
canvas.Orphanize();
};
#endregion
// Create Vertex buffer (2 triangles)
var buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f), gl.STATIC_DRAW);
// Create Program
var program = gl.createProgram(
new DisturbVertexShader(),
new DisturbFragmentShader()
);
gl.linkProgram(program);
gl.useProgram(program);
#region loadTexture
Action<IHTMLImage, WebGLTexture> loadTexture =
async (image, texture_) =>
{
await image;
gl.enable(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, texture_);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, (int)gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (int)gl.LINEAR_MIPMAP_LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, (int)gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, (int)gl.REPEAT);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
};
#endregion
var texture = gl.createTexture();
loadTexture(new HTML.Images.FromAssets.disturb(), texture);
var vertexPositionLocation = default(long);
var textureLocation = default(WebGLUniformLocation);
#region resize
Action resize = delegate
{
canvas.style.SetLocation(0, 0);
canvas.width = Native.window.Width;
canvas.height = Native.window.Height;
parameters_screenWidth = canvas.width;
parameters_screenHeight = canvas.height;
gl.viewport(0, 0, canvas.width, canvas.height);
};
Native.window.onresize +=
delegate
{
if (IsDisposed)
return;
resize();
//.........这里部分代码省略.........
示例3: Application
//.........这里部分代码省略.........
{
do
{
Native.document.body.style.backgroundColor = "cyan";
await Task.Delay(500);
Native.document.body.style.backgroundColor = "yellow";
await Task.Delay(500);
} while (await Native.window.async.onframe);
}
);
// https://developer.mozilla.org/en/docs/Web/API/WebGLRenderingContext
#region Paint_Image
Paint_ImageDelegate Paint_Image =
(mProgram, time, mouseOriX, mouseOriY, mousePosX, mousePosY) =>
{
var viewportxres = gl.canvas.width;
var viewportyres = gl.canvas.height;
#region Paint_Image
//new IHTMLPre { "enter Paint_Image" }.AttachToDocument();
// http://www.html5rocks.com/en/tutorials/webgl/webgl_fundamentals/
//gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
gl.viewport(0, 0, viewportxres, viewportyres);
// alpha to zero will only hide the pixel if blending is enabled.
gl.useProgram(mProgram);
// uniform4fv
var mouse = new[] { mousePosX, mousePosY, mouseOriX, mouseOriY };
var l2 = gl.getUniformLocation(mProgram, "iGlobalTime"); if (l2 != null) gl.uniform1f(l2, time);
var l3 = gl.getUniformLocation(mProgram, "iResolution"); if (l3 != null) gl.uniform3f(l3, viewportxres, viewportyres, 1.0f);
var l4 = gl.getUniformLocation(mProgram, "iMouse"); if (l4 != null) gl.uniform4fv(l4, mouse);
//var l7 = gl.getUniformLocation(this.mProgram, "iDate"); if (l7 != null) gl.uniform4fv(l7, dates);
//var l9 = gl.getUniformLocation(this.mProgram, "iSampleRate"); if (l9 != null) gl.uniform1f(l9, this.mSampleRate);
var ich0 = gl.getUniformLocation(mProgram, "iChannel0"); if (ich0 != null) gl.uniform1i(ich0, 0);
var ich1 = gl.getUniformLocation(mProgram, "iChannel1"); if (ich1 != null) gl.uniform1i(ich1, 1);
var ich2 = gl.getUniformLocation(mProgram, "iChannel2"); if (ich2 != null) gl.uniform1i(ich2, 2);
var ich3 = gl.getUniformLocation(mProgram, "iChannel3"); if (ich3 != null) gl.uniform1i(ich3, 3);
//for (var i = 0; i < mInputs.Length; i++)
//{
// var inp = mInputs[i];
// gl.activeTexture((uint)(gl.TEXTURE0 + i));
// if (inp == null)
// {
// gl.bindTexture(gl.TEXTURE_2D, null);
// }
//}
var times = new[] { 0.0f, 0.0f, 0.0f, 0.0f };
var l5 = gl.getUniformLocation(mProgram, "iChannelTime");
示例4: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IDefault page = null)
{
var gl_viewportWidth = 500;
var gl_viewportHeight = 500;
var gl = new WebGLRenderingContext();
#region canvas
var canvas = gl.canvas.AttachToDocument();
Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;
canvas.style.SetLocation(0, 0, gl_viewportWidth, gl_viewportHeight);
canvas.width = gl_viewportWidth;
canvas.height = gl_viewportHeight;
#endregion
var h = 1f;
var r1 = .5f;
var r2 = .2f;
var nPhi = 500;
var prog = gl.createProgram();
#region createShader
Func<ScriptCoreLib.GLSL.Shader, WebGLShader> createShader = (src) =>
{
var shader = gl.createShader(src);
// verify
if (gl.getShaderParameter(shader, gl.COMPILE_STATUS) == null)
{
Native.window.alert("error in SHADER:\n" + gl.getShaderInfoLog(shader));
throw new InvalidOperationException("shader failed");
}
return shader;
};
#endregion
var vs = createShader(new GeometryVertexShader());
var fs = createShader(new GeometryFragmentShader());
gl.attachShader(prog, vs);
gl.attachShader(prog, fs);
gl.linkProgram(prog);
gl.useProgram(prog);
var pt = new IArray<float>();
var nt = new IArray<float>();
var Phi = 0.0;
var dPhi = 2 * Math.PI / (nPhi - 1);
var Nx = r1 - r2;
var Ny = h;
var N = (float)Math.Sqrt(Nx * Nx + Ny * Ny);
Nx /= N;
Ny /= N;
for (var i = 0; i < nPhi; i++)
{
var cosPhi = Math.Cos(Phi);
var sinPhi = Math.Sin(Phi);
var cosPhi2 = Math.Cos(Phi + dPhi / 2);
var sinPhi2 = Math.Sin(Phi + dPhi / 2);
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
//.........这里部分代码省略.........
示例5: Initialize
private void Initialize(IDefault page = null)
{
#region += Launched chrome.app.window
dynamic self = Native.self;
dynamic self_chrome = self.chrome;
object self_chrome_socket = self_chrome.socket;
if (self_chrome_socket != null)
{
if (!(Native.window.opener == null && Native.window.parent == Native.window.self))
{
Console.WriteLine("chrome.app.window.create, is that you?");
// pass thru
}
else
{
// should jsc send a copresence udp message?
chrome.runtime.UpdateAvailable += delegate
{
new chrome.Notification(title: "UpdateAvailable");
};
chrome.app.runtime.Launched += async delegate
{
// 0:12094ms chrome.app.window.create {{ href = chrome-extension://aemlnmcokphbneegoefdckonejmknohh/_generated_background_page.html }}
Console.WriteLine("chrome.app.window.create " + new { Native.document.location.href });
new chrome.Notification(title: "ChromeUDPSendAsync");
var xappwindow = await chrome.app.window.create(
Native.document.location.pathname, options: null
);
//xappwindow.setAlwaysOnTop
xappwindow.show();
await xappwindow.contentWindow.async.onload;
Console.WriteLine("chrome.app.window loaded!");
};
return;
}
}
#endregion
int w = Native.window.Width;
int h = Native.window.Height;
var gl = new WebGLRenderingContext(preserveDrawingBuffer: true);
var canvas = gl.canvas.AttachToDocument();
canvas.style.backgroundColor = JSColor.Black;
Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;
canvas.style.SetLocation(0, 0);
#region Dispose
var IsDisposed = false;
Dispose = delegate
{
if (IsDisposed)
return;
IsDisposed = true;
canvas.Orphanize();
};
#endregion
// http://cs.helsinki.fi/u/ilmarihe/metatunnel.html
var p = gl.createProgram(
new ChocoluxVertexShader(),
new ChocoluxFragmentShader()
);
gl.bindAttribLocation(p, 0, "position");
gl.linkProgram(p);
gl.useProgram(p);
var uniforms = p.Uniforms(gl);
gl.viewport(0, 0, w, h);
gl.enableVertexAttribArray(0);
//.........这里部分代码省略.........
示例6: 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);
}
示例7: ApplicationContent
//.........这里部分代码省略.........
var gl_viewportHeight = Native.window.Height;
var shaderProgram = gl.createProgram();
#region createShader
Func<ScriptCoreLib.GLSL.Shader, WebGLShader> createShader = (src) =>
{
var shader = gl.createShader(src);
// verify
if (gl.getShaderParameter(shader, gl.COMPILE_STATUS) == null)
{
Native.window.alert("error in SHADER:\n" + gl.getShaderInfoLog(shader));
throw new InvalidOperationException("shader failed");
}
return shader;
};
#endregion
#region initShaders
var vs = createShader(new GeometryVertexShader());
var fs = createShader(new GeometryFragmentShader());
gl.attachShader(shaderProgram, vs);
gl.attachShader(shaderProgram, fs);
gl.linkProgram(shaderProgram);
gl.useProgram(shaderProgram);
var shaderProgram_vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
gl.enableVertexAttribArray((uint)shaderProgram_vertexPositionAttribute);
// 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");
#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();
};
示例8: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IDefault page = null)
{
// works in IE11
style.Content.AttachToHead();
var gl_viewportWidth = Native.window.Width;
var gl_viewportHeight = Native.window.Height;
var gl = new WebGLRenderingContext();
var canvas = gl.canvas.AttachToDocument();
Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;
canvas.style.SetLocation(0, 0, gl_viewportWidth, gl_viewportHeight);
canvas.width = gl_viewportWidth;
canvas.height = gl_viewportHeight;
#region IsDisposed
var IsDisposed = false;
this.Dispose = delegate
{
if (IsDisposed)
return;
IsDisposed = true;
canvas.Orphanize();
};
#endregion
#region requestFullscreen
Native.Document.body.ondblclick +=
delegate
{
if (IsDisposed)
return;
// http://tutorialzine.com/2012/02/enhance-your-website-fullscreen-api/
Native.Document.body.requestFullscreen();
};
#endregion
#region init shaders
var shaderProgram = gl.createProgram(
new Shaders.GeometryVertexShader(),
new Shaders.GeometryFragmentShader()
);
gl.linkProgram(shaderProgram);
gl.useProgram(shaderProgram);
#region getAttribLocation
Func<string, long> getAttribLocation =
name => gl.getAttribLocation(shaderProgram, name);
#endregion
#region getUniformLocation
Func<string, WebGLUniformLocation> getUniformLocation =
name => gl.getUniformLocation(shaderProgram, name);
#endregion
#endregion
var shaderProgram_vertexPositionAttribute = getAttribLocation("aVertexPosition");
gl.enableVertexAttribArray((uint)shaderProgram_vertexPositionAttribute);
var shaderProgram_textureCoordAttribute = getAttribLocation("aTextureCoord");
gl.enableVertexAttribArray((uint)shaderProgram_textureCoordAttribute);
var shaderProgram_pMatrixUniform = getUniformLocation("uPMatrix");
var shaderProgram_mvMatrixUniform = getUniformLocation("uMVMatrix");
var shaderProgram_samplerUniform = getUniformLocation("uSampler");
var mvMatrix = glMatrix.mat4.create();
//.........这里部分代码省略.........
示例9: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IDefault page = null)
{
var gl_viewportWidth = Native.window.Width;
var gl_viewportHeight = Native.window.Height;
var gl = new WebGLRenderingContext();
var canvas = gl.canvas.AttachToDocument();
Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;
canvas.style.SetLocation(0, 0, gl_viewportWidth, gl_viewportWidth);
gl.viewport(0, 0, gl_viewportWidth, gl_viewportWidth);
var prog = gl.createProgram(
new CubicVertexShader(),
new CubicFragmentShader()
);
var posLoc = 0U;
gl.bindAttribLocation(prog, posLoc, "aPos");
var normLoc = 1U;
gl.bindAttribLocation(prog, normLoc, "aNorm");
gl.linkProgram(prog);
gl.useProgram(prog);
#region data
var a = 1.0f; // where is it used? what shall be the type?
var pt0 = new float[] {-a,-a,a, a,-a,a, -a,a,a, a,a,a, // cubic
-a,a,a, a,a,a, -a,a,-a, a,a,-a,
-a,a,-a, a,a,-a, -a,-a,-a, a,-a,-a, -a,-a,-a, a,-a,-a, -a,-a,a, a,-a,a,
a,a,a, a,a,-a, a,-a,a, a,-a,-a, -a,a,a, -a,a,-a, -a,-a,a, -a,-a,-a};
var nt = new float[] {0,0,1, 0,0,1, 0,0,1, 0,0,1, 0,1,0, 0,1,0, 0,1,0, 0,1,0,
0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, 0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0,
1,0,0, 1,0,0, 1,0,0, 1,0,0, -1,0,0, -1,0,0, -1,0,0, -1,0,0};
var ind = new ushort[] {0,1,2,1,2,3, 4,5,6,5,6,7, 8,9,10,9,10,11,
12,13,14,13,14,15, 16,17,18,17,18,19, 20,21,22,21,22,23};
var nPhi = 25;
var nTheta = 12;
var r = .15;
var dPhi = 2.0 * Math.PI / nPhi;
var dTheta = Math.PI / nTheta;
for (var j = 0; j <= nTheta; j++)
{
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);
((IArray<float>)(object)pt0).push((float)(r * cosPhi * sinTheta));
((IArray<float>)(object)pt0).push((float)(-r * sinPhi * sinTheta));
((IArray<float>)(object)pt0).push((float)(r * cosTheta));
((IArray<float>)(object)nt).push((float)(cosPhi * sinTheta));
((IArray<float>)(object)nt).push((float)(-sinPhi * sinTheta));
((IArray<float>)(object)nt).push((float)(cosTheta));
}
}
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);
//.........这里部分代码省略.........
示例10: Application
//.........这里部分代码省略.........
gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.enable(gl.DEPTH_TEST);
var teapotAngle = 180f;
var lastTime = 0L;
#region animate
Action animate = () =>
{
var timeNow = new IDate().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
teapotAngle += 0.05f * elapsed;
}
lastTime = timeNow;
};
#endregion
//Func<string, f> parseFloat = Convert.ToSingle;
Func<string, f> parseFloat = x => float.Parse(x);
#region drawScene
Action drawScene = () =>
{
gl.useProgram(currentProgram.program);
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
//if (teapotVertexPositionBuffer == null || teapotVertexNormalBuffer == null || teapotVertexTextureCoordBuffer == null || teapotVertexIndexBuffer == null) {
// return;
//}
glMatrix.mat4.perspective(45, gl_viewportWidth / gl_viewportHeight, 0.1f, 100.0f, pMatrix);
var shaderProgram = currentProgram;
var specularHighlights = [email protected];
#region [uniform] bool uShowSpecularHighlights <- [email protected]
gl.uniform1i(shaderProgram.showSpecularHighlightsUniform, Convert.ToInt32(specularHighlights));
#endregion
var lighting = [email protected];
#region [uniform] bool uUseLighting <- [email protected]
gl.uniform1i(shaderProgram.useLightingUniform, Convert.ToInt32(lighting));
#endregion
if (lighting)
{
#region [uniform] uAmbientColor <- ambientR, ambientG, ambientB
gl.uniform3f(
shaderProgram.ambientColorUniform,
parseFloat(toolbar.ambientR.value),
parseFloat(toolbar.ambientG.value),
示例11: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IDefault page = null)
{
var size = 500;
var gl = new WebGLRenderingContext();
var canvas = gl.canvas.AttachToDocument();
Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;
canvas.style.SetLocation(0, 0, size, size);
canvas.width = size;
canvas.height = size;
var gl_viewportWidth = size;
var gl_viewportHeight = size;
#region IsDisposed
var IsDisposed = false;
this.Dispose = delegate
{
if (IsDisposed)
return;
IsDisposed = true;
canvas.Orphanize();
};
#endregion
#region AtResize
Action AtResize =
delegate
{
gl_viewportWidth = Native.window.Width;
gl_viewportHeight = Native.window.Height;
canvas.style.SetLocation(0, 0, gl_viewportWidth, gl_viewportHeight);
canvas.width = gl_viewportWidth;
canvas.height = gl_viewportHeight;
};
Native.window.onresize +=
e =>
{
AtResize();
};
AtResize();
#endregion
#region requestFullscreen
Native.Document.body.ondblclick +=
delegate
{
if (IsDisposed)
return;
// http://tutorialzine.com/2012/02/enhance-your-website-fullscreen-api/
Native.Document.body.requestFullscreen();
};
#endregion
#region initShaders
var shaderProgram = gl.createProgram(
new GeometryVertexShader(),
new GeometryFragmentShader()
);
gl.linkProgram(shaderProgram);
gl.useProgram(shaderProgram);
var shaderProgram_vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
gl.enableVertexAttribArray((uint)shaderProgram_vertexPositionAttribute);
// new in lesson 02
var shaderProgram_vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
//.........这里部分代码省略.........
示例12: Application
//.........这里部分代码省略.........
gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.enable(gl.DEPTH_TEST);
var earthAngle = 180f;
var lastTime = 0L;
#region animate
Action animate = () =>
{
var timeNow = new IDate().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
earthAngle += 0.05f * elapsed;
}
lastTime = timeNow;
};
#endregion
//Func<string, f> parseFloat = Convert.ToSingle;
//Func<string, f> parseFloat = x => float.Parse(x);
#region drawScene
Action drawScene = () =>
{
var shaderProgram = currentProgram;
gl.useProgram(shaderProgram.program);
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
glMatrix.mat4.perspective(45, gl_viewportWidth / gl_viewportHeight, 0.1f, 100.0f, pMatrix);
#region [uniform] uUseColorMap <- color_map
var useColorMap = [email protected];
gl.uniform1i(shaderProgram.useColorMapUniform, Convert.ToInt32(useColorMap));
#endregion
#region [uniform] uUseSpecularMap <- specular_map
var useSpecularMap = [email protected];
gl.uniform1i(shaderProgram.useSpecularMapUniform, Convert.ToInt32(useSpecularMap));
#endregion
#region [uniform] uUseLighting <- lighting
var lighting = [email protected];
gl.uniform1i(shaderProgram.useLightingUniform, Convert.ToInt32(lighting));
#endregion
if (lighting)
{
#region [uniform] uAmbientColor <- ambientR, ambientG, ambientB
gl.uniform3f(
shaderProgram.ambientColorUniform,
float.Parse(toolbar.ambientR.value),
float.Parse(toolbar.ambientG.value),
float.Parse(toolbar.ambientB.value)
);
#endregion
示例13: Application
/* Source: http://www.ibiblio.org/e-notes/webgl/models/ethanol.html
*
*/
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IDefault page = null)
{
var gl_viewportWidth = 500;
var gl_viewportHeight = 500;
var gl = new WebGLRenderingContext();
var canvas = gl.canvas.AttachToDocument();
Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;
canvas.style.SetLocation(0, 0, gl_viewportWidth, gl_viewportHeight);
canvas.width = gl_viewportWidth;
canvas.height = gl_viewportHeight;
var h = 1f;
var r1 = .5f;
var r2 = .2f;
var prog = gl.createProgram();
#region createShader
Func<ScriptCoreLib.GLSL.Shader, WebGLShader> createShader = (src) =>
{
var shader = gl.createShader(src);
// verify
if (gl.getShaderParameter(shader, gl.COMPILE_STATUS) == null)
{
Native.window.alert("error in SHADER:\n" + gl.getShaderInfoLog(shader));
throw new InvalidOperationException("shader failed");
}
return shader;
};
#endregion
var vs = createShader(new GeometryVertexShader());
var fs = createShader(new GeometryFragmentShader());
gl.attachShader(prog, vs);
gl.attachShader(prog, fs);
gl.linkProgram(prog);
gl.useProgram(prog);
var nPhi = 100;
var nTheta = 50;
var dPhi = 2 * Math.PI / nPhi;
var dTheta = Math.PI / nTheta;
var vertices = new IArray<float>();
var ind = new IArray<ushort>();
for (var j = 0; j <= nTheta; j++)
{
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);
//.........这里部分代码省略.........
示例14: Application
// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150719/chromeudpwindwheel
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IApp page)
{
#region += Launched chrome.app.window
dynamic self = Native.self;
dynamic self_chrome = self.chrome;
object self_chrome_socket = self_chrome.socket;
if (self_chrome_socket != null)
{
if (!(Native.window.opener == null && Native.window.parent == Native.window.self))
{
Console.WriteLine("chrome.app.window.create, is that you?");
// pass thru
}
else
{
// should jsc send a copresence udp message?
chrome.runtime.UpdateAvailable += delegate
{
new chrome.Notification(title: "UpdateAvailable");
};
chrome.app.runtime.Launched += async delegate
{
// 0:12094ms chrome.app.window.create {{ href = chrome-extension://aemlnmcokphbneegoefdckonejmknohh/_generated_background_page.html }}
Console.WriteLine("chrome.app.window.create " + new { Native.document.location.href });
new chrome.Notification(title: "ChromeUDPSendAsync");
// https://developer.chrome.com/apps/app_window#type-CreateWindowOptions
var xappwindow = await chrome.app.window.create(
Native.document.location.pathname, options: new
{
alwaysOnTop = true,
visibleOnAllWorkspaces = true
}
);
//xappwindow.setAlwaysOnTop
xappwindow.show();
await xappwindow.contentWindow.async.onload;
Console.WriteLine("chrome.app.window loaded!");
};
return;
}
}
#endregion
// X:\jsc.svn\examples\javascript\WorkerMD5Experiment\WorkerMD5Experiment\Application.cs
// "C:\Users\Arvo\AppData\Local\Google\Chrome SxS\Application\chrome.exe - es3.lnk"
var size = 600;
var gl = new WebGLRenderingContext();
var canvas = gl.canvas.AttachToDocument();
Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;
canvas.style.SetLocation(0, 0, size, size);
canvas.width = size;
canvas.height = size;
var gl_viewportWidth = size;
var gl_viewportHeight = size;
// can AssetLibrary create a special type
// and define the variables
// for it we need to parse glsl?
// if we dont parse the code yet,
// do we parse the macros and fields neogh already to do that?
// Geometry
var shaderProgram = gl.createProgram(
new WebGLWindWheel.Shaders.GeometryVertexShader(),
new WebGLWindWheel.Shaders.GeometryFragmentShader()
);
gl.linkProgram(shaderProgram);
gl.useProgram(shaderProgram);
//.........这里部分代码省略.........
示例15: Application
//.........这里部分代码省略.........
AtResize();
#endregion
#region requestFullscreen
Native.Document.body.ondblclick +=
delegate
{
if (IsDisposed)
return;
// http://tutorialzine.com/2012/02/enhance-your-website-fullscreen-api/
Native.Document.body.requestFullscreen();
};
#endregion
#region init shaders
var shaderProgram = gl.createProgram(
new Shaders.GeometryVertexShader(),
new Shaders.GeometryFragmentShader()
);
gl.linkProgram(shaderProgram);
gl.useProgram(shaderProgram);
#region getAttribLocation
Func<string, long> getAttribLocation =
name => gl.getAttribLocation(shaderProgram, name);
#endregion
#region getUniformLocation
Func<string, WebGLUniformLocation> getUniformLocation =
name => gl.getUniformLocation(shaderProgram, name);
#endregion
#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