本文整理汇总了C#中WebGLRenderingContext.createTexture方法的典型用法代码示例。如果您正苦于以下问题:C# WebGLRenderingContext.createTexture方法的具体用法?C# WebGLRenderingContext.createTexture怎么用?C# WebGLRenderingContext.createTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebGLRenderingContext
的用法示例。
在下文中一共展示了WebGLRenderingContext.createTexture方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalConstructor
static WebGLTexture InternalConstructor(WebGLRenderingContext gl)
{
// X:\jsc.svn\examples\javascript\chrome\apps\WebGL\ChromeWebGLFrameBuffer\ChromeWebGLFrameBuffer\Application.cs
// X:\jsc.svn\examples\javascript\chrome\apps\WebGL\ChromeShaderToyColumns\ChromeShaderToyColumns\Library\ShaderToy.cs
var p = gl.createTexture();
return p;
}
示例2: Application
//.........这里部分代码省略.........
0.0f, 1.0f,
0.0f, 0.0f,
// Left face
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
};
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoords), gl.STATIC_DRAW);
var cubeVertexTextureCoordBuffer_itemSize = 2;
var cubeVertexTextureCoordBuffer_numItems = 24;
var cubeVertexIndexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
var cubeVertexIndices = new UInt16[]{
0, 1, 2, 0, 2, 3, // Front face
4, 5, 6, 4, 6, 7, // Back face
8, 9, 10, 8, 10, 11, // Top face
12, 13, 14, 12, 14, 15, // Bottom face
16, 17, 18, 16, 18, 19, // Right face
20, 21, 22, 20, 22, 23 // Left face
};
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(cubeVertexIndices), gl.STATIC_DRAW);
var cubeVertexIndexBuffer_itemSize = 1;
var cubeVertexIndexBuffer_numItems = cubeVertexPositionBuffer_numItems;
#endregion
#endregion
// initTexture new in lesson 05
var neheTexture = gl.createTexture();
var neheTexture_image = new WebGLLesson05.HTML.Images.FromAssets.nehe();
neheTexture_image.InvokeOnComplete(
delegate
{
gl.bindTexture(gl.TEXTURE_2D, neheTexture);
#region with neheTexture
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, neheTexture_image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, (int)gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (int)gl.NEAREST);
#endregion
gl.bindTexture(gl.TEXTURE_2D, null);
gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.enable(gl.DEPTH_TEST);
#region new in lesson 04
var xRot = 0.0f;
var yRot = 0.0f;
var zRot = 0.0f;
var lastTime = 0L;
Action animate = delegate
{
var timeNow = new IDate().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
示例3: Application
//.........这里部分代码省略.........
canvas.onmouseup +=
delegate
{
// keep at it...
//Native.Document.exitPointerLock();
};
#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
new HTML.Images.FromAssets.mud().InvokeOnComplete(
mud =>
{
var mudTexture = gl.createTexture();
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
gl.bindTexture(gl.TEXTURE_2D, mudTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, mud);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, (int)gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (int)gl.LINEAR);
gl.bindTexture(gl.TEXTURE_2D, null);
Func<string, f> parseFloat = x => (f)double.Parse(x);
var lines = data.Split('\n');
var vertexCount = 0;
var vertexPositions = new List<f>();
var vertexTextureCoords = new List<f>();
foreach (var i in lines)
{
var vals = i.Trim().Replace(" ", " ").Replace(" ", " ").Split(' ');
if (vals.Length == 5)
if (vals[0] != "//")
{
// It is a line describing a vertex; get X, Y and Z first
vertexPositions.Add(parseFloat(vals[0]));
vertexPositions.Add(parseFloat(vals[1]));
vertexPositions.Add(parseFloat(vals[2]));
// And then the texture coords
vertexTextureCoords.Add(parseFloat(vals[3]));
示例4: loadTexture
static WebGLTexture loadTexture(WebGLRenderingContext gl, string url, Action callback)
{
//gl.enable(gl.TEXTURE_2D);
var texture = gl.createTexture();
var image = new IHTMLImage();
Console.WriteLine("loading: " + url);
image.src = url;
image.InvokeOnComplete(
delegate
{
Console.WriteLine("loaded: " + url);
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);
gl.bindTexture(gl.TEXTURE_2D, null);
callback();
}
);
return texture;
}
示例5: InitializeContent
//.........这里部分代码省略.........
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);
// INVALID_OPERATION: generateMipmap: level 0 not power of 2 or not all the same size
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
};
#endregion
var crateTexture = gl.createTexture();
handleLoadedTexture(crateTexture, crate);
var moonTexture = gl.createTexture();
handleLoadedTexture(moonTexture, moon);
#region initTextureFramebuffer
var rttFramebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, rttFramebuffer);
var rttFramebuffer_width = 512;
var rttFramebuffer_height = 512;
var rttTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, rttTexture);
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_NEAREST);
gl.generateMipmap(gl.TEXTURE_2D);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, rttFramebuffer_width, rttFramebuffer_height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
var renderbuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, rttFramebuffer_width, rttFramebuffer_height);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, rttTexture, 0);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuffer);
gl.bindTexture(gl.TEXTURE_2D, null);
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
#endregion
示例6: Application
//.........这里部分代码省略.........
gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
#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
new HTML.Images.FromAssets.star().InvokeOnComplete(
texture_image =>
{
var starTexture = gl.createTexture();
#region handleLoadedTexture
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
gl.bindTexture(gl.TEXTURE_2D, starTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture_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);
gl.bindTexture(gl.TEXTURE_2D, null);
#endregion
#region drawStar
Action drawStar = () =>
{
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, starTexture);
gl.uniform1i(shaderProgram_samplerUniform, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, starVertexTextureCoordBuffer);
gl.vertexAttribPointer((uint)shaderProgram_textureCoordAttribute, starVertexTextureCoordBuffer_itemSize, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, starVertexPositionBuffer);
gl.vertexAttribPointer((uint)shaderProgram_vertexPositionAttribute, starVertexPositionBuffer_itemSize, gl.FLOAT, false, 0, 0);
setMatrixUniforms();
gl.drawArrays(gl.TRIANGLE_STRIP, 0, starVertexPositionBuffer_numItems);
};
#endregion
#region drawScene
Action drawScene = delegate
{
示例7: Application
//.........这里部分代码省略.........
//1.0f, 1.0f,
//0.0f, 1.0f,
//0.0f, 0.0f,
//// Left face
//0.0f, 0.0f,
//1.0f, 0.0f,
//1.0f, 1.0f,
//0.0f, 1.0f,
};
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoords), gl.STATIC_DRAW);
var cubeVertexTextureCoordBuffer_itemSize = 2;
var cubeVertexTextureCoordBuffer_numItems = 24;
var cubeVertexIndexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
var cubeVertexIndices = new UInt16[]{
0, 1, 2, 0, 2, 3, // Front face
4, 5, 6, 4, 6, 7, // Back face
8, 9, 10, 8, 10, 11, // Top face
12, 13, 14, 12, 14, 15, // Bottom face
16, 17, 18, 16, 18, 19, // Right face
20, 21, 22, 20, 22, 23 // Left face
};
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(cubeVertexIndices), gl.STATIC_DRAW);
var cubeVertexIndexBuffer_itemSize = 1;
var cubeVertexIndexBuffer_numItems = cubeVertexPositionBuffer_numItems;
#endregion
#endregion
var tex1 = gl.createTexture();
var tex1i = new WebGLSVGAnonymous.HTML.Images.FromAssets.Anonymous_LogosSingleNoWings();
//var tex1i = new WebGLSVGAnonymous.HTML.Images.FromAssets.nehe();
// WebGL: drawElements: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering or is not 'texture complete'. Or the texture is Float or Half Float type with linear filtering while OES_float_linear or OES_half_float_linear extension is not enabled.
tex1i.width = 1024 * 2;
tex1i.height = 1024 * 2;
// initTexture new in lesson 05
var tex0 = gl.createTexture();
var tex0i = new WebGLSVGAnonymous.HTML.Images.FromAssets.Anonymous_LogosSingleWings();
//var tex0i = new WebGLSVGAnonymous.HTML.Images.FromAssets.nehe();
// WebGL: drawElements: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering or is not 'texture complete'. Or the texture is Float or Half Float type with linear filtering while OES_float_linear or OES_half_float_linear extension is not enabled.
tex0i.width = 1024 * 2;
tex0i.height = 1024 * 2;
tex1i.InvokeOnComplete(
delegate
{
tex0i.InvokeOnComplete(
delegate
{
// this is a workaround
// chrome has a bug where svg textures are merged..
var tex1ii = new CanvasRenderingContext2D(1024 * 2, 1024 * 2);
tex1ii.drawImage(
tex1i, 0, 0, 1024 * 2, 1024 * 2);
示例8: Application
//.........这里部分代码省略.........
// Left face
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
};
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoords), gl.STATIC_DRAW);
var cubeVertexTextureCoordBuffer_itemSize = 2;
var cubeVertexTextureCoordBuffer_numItems = 24;
var cubeVertexIndexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
var cubeVertexIndices = new UInt16[]{
0, 1, 2, 0, 2, 3, // Front face
4, 5, 6, 4, 6, 7, // Back face
8, 9, 10, 8, 10, 11, // Top face
12, 13, 14, 12, 14, 15, // Bottom face
16, 17, 18, 16, 18, 19, // Right face
20, 21, 22, 20, 22, 23 // Left face
};
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(cubeVertexIndices), gl.STATIC_DRAW);
var cubeVertexIndexBuffer_itemSize = 1;
var cubeVertexIndexBuffer_numItems = cubeVertexPositionBuffer_numItems;
#endregion
#endregion
// initTexture new in lesson 05
var textures = new[]
{
gl.createTexture(),
gl.createTexture(),
gl.createTexture(),
};
var xRot = 0.0f;
var xSpeed = 2.0f;
var yRot = 0.0f;
var ySpeed = 2.0f;
var z = -5.0f;
var filter = 2;
#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;
if (e.KeyCode == 13)
示例9: Application
//.........这里部分代码省略.........
var moonVertexTextureCoordBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, moonVertexTextureCoordBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoordData.ToArray()), gl.STATIC_DRAW);
var moonVertexTextureCoordBuffer_itemSize = 2;
var moonVertexTextureCoordBuffer_numItems = textureCoordData.Count / 2;
var moonVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, moonVertexPositionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertexPositionData.ToArray()), gl.STATIC_DRAW);
var moonVertexPositionBuffer_itemSize = 3;
var moonVertexPositionBuffer_numItems = vertexPositionData.Count / 3;
var moonVertexIndexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, moonVertexIndexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData.ToArray()), gl.STREAM_DRAW);
var moonVertexIndexBuffer_itemSize = 1;
var moonVertexIndexBuffer_numItems = indexData.Count;
#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, gl.TEXTURE_MAG_FILTER, (int)gl.LINEAR);
gl.texParameteri((uint)gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (int)gl.LINEAR_MIPMAP_NEAREST);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
};
#endregion
var moonTexture = gl.createTexture();
handleLoadedTexture(moonTexture, moon);
var crateTexture = gl.createTexture();
handleLoadedTexture(crateTexture, crate);
gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.enable(gl.DEPTH_TEST);
var moonAngle = 180f;
var cubeAngle = 0f;
var lastTime = 0L;
#region animate
Action animate = () =>
{
var timeNow = new IDate().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
moonAngle += 0.05f * elapsed;
cubeAngle += 0.05f * elapsed;
}
lastTime = timeNow;
};
#endregion
示例10: Application
//.........这里部分代码省略.........
#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(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, (int)gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (int)gl.LINEAR_MIPMAP_NEAREST);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
};
#endregion
var earthTexture = gl.createTexture();
handleLoadedTexture(earthTexture, earth);
var galvanizedTexture = gl.createTexture();
handleLoadedTexture(galvanizedTexture, metal);
new WebGLLesson14.Data.Teapot().Content.AttachToDocument().onload +=
delegate
{
#region loadTeapot
var teapotData = Application.Teapot;
var teapotVertexNormalBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, teapotVertexNormalBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(teapotData.vertexNormals), gl.STATIC_DRAW);
var teapotVertexNormalBuffer_itemSize = 3;
var teapotVertexNormalBuffer_numItems = teapotData.vertexNormals.Length / 3;
var teapotVertexTextureCoordBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, teapotVertexTextureCoordBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(teapotData.vertexTextureCoords), gl.STATIC_DRAW);
var teapotVertexTextureCoordBuffer_itemSize = 2;
var teapotVertexTextureCoordBuffer_numItems = teapotData.vertexTextureCoords.Length / 2;
var teapotVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, teapotVertexPositionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(teapotData.vertexPositions), gl.STATIC_DRAW);
var teapotVertexPositionBuffer_itemSize = 3;
var teapotVertexPositionBuffer_numItems = teapotData.vertexPositions.Length / 3;
示例11: Application
//.........这里部分代码省略.........
#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();
handleLoadedTexture(earthColorMapTexture, earth);
var earthSpecularMapTexture = gl.createTexture();
handleLoadedTexture(earthSpecularMapTexture, earth_specular);
#region initBuffers
var latitudeBands = 30;
var longitudeBands = 30;
var radius = 13;
var vertexPositionData = new List<f>();
var normalData = new List<f>();
var textureCoordData = new List<f>();
for (var latNumber = 0; latNumber <= latitudeBands; latNumber++)
{
var theta = latNumber * Math.PI / latitudeBands;
var sinTheta = (f)Math.Sin(theta);
var cosTheta = (f)Math.Cos(theta);
for (var longNumber = 0; longNumber <= longitudeBands; longNumber++)
{
var phi = longNumber * 2 * Math.PI / longitudeBands;
var sinPhi = (f)Math.Sin(phi);
var cosPhi = (f)Math.Cos(phi);
var x = cosPhi * sinTheta;
var y = cosTheta;
var z = sinPhi * sinTheta;
var u = 1 - (longNumber / longitudeBands);
var v = 1 - (latNumber / latitudeBands);
normalData.Add(x);
示例12: 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();
//.........这里部分代码省略.........
示例13: Application
//.........这里部分代码省略.........
}
}
var moonVertexNormalBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, moonVertexNormalBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(normalData.ToArray()), gl.STATIC_DRAW);
var moonVertexNormalBuffer_itemSize = 3;
var moonVertexNormalBuffer_numItems = normalData.Count / 3;
var moonVertexTextureCoordBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, moonVertexTextureCoordBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoordData.ToArray()), gl.STATIC_DRAW);
var moonVertexTextureCoordBuffer_itemSize = 2;
var moonVertexTextureCoordBuffer_numItems = textureCoordData.Count / 2;
var moonVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, moonVertexPositionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertexPositionData.ToArray()), gl.STATIC_DRAW);
var moonVertexPositionBuffer_itemSize = 3;
var moonVertexPositionBuffer_numItems = vertexPositionData.Count / 3;
var moonVertexIndexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, moonVertexIndexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData.ToArray()), gl.STATIC_DRAW);
var moonVertexIndexBuffer_itemSize = 1;
var moonVertexIndexBuffer_numItems = indexData.Count;
new HTML.Images.FromAssets.moon().InvokeOnComplete(
mud =>
{
var moonTexture = gl.createTexture();
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
gl.bindTexture(gl.TEXTURE_2D, moonTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, mud);
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_NEAREST);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.enable(gl.DEPTH_TEST);
#region drawScene
Action drawScene = () =>
{
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);
var lighting = [email protected];
#region [uniform] bool uUseLighting <- lighting