void initShaders() { var fragmentShader = getShader(gl, shader_fs, GL.FRAGMENT_SHADER); var vertexShader = getShader(gl, shader_vs, GL.VERTEX_SHADER); shaderProgram = gl.createProgram(); gl.attachShader(shaderProgram, vertexShader); gl.attachShader(shaderProgram, fragmentShader); gl.linkProgram(shaderProgram); if (gl.getProgramParameter(shaderProgram, GL.LINK_STATUS) == null) { alert("Could not initialise shaders"); } gl.useProgram(shaderProgram); shaderProgram_vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); gl.enableVertexAttribArray((GLuint)shaderProgram_vertexPositionAttribute); shaderProgram_vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor"); gl.enableVertexAttribArray((GLuint)shaderProgram_vertexColorAttribute); shaderProgram_pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix"); shaderProgram_mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix"); }
void handleLoadedTeapot(JsonValue teapotData) { teapotVertexNormalBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, teapotVertexNormalBuffer); gl.bufferData(GL.ARRAY_BUFFER, new Float32Array(teapotData["vertexNormals"].ReadAsType <float[]>()), GL.STATIC_DRAW); teapotVertexNormalBuffer_itemSize = 3; teapotVertexNormalBuffer_numItems = teapotData["vertexNormals"].Count / 3; teapotVertexTextureCoordBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, teapotVertexTextureCoordBuffer); gl.bufferData(GL.ARRAY_BUFFER, new Float32Array(teapotData["vertexTextureCoords"].ReadAsType <float[]>()), GL.STATIC_DRAW); teapotVertexTextureCoordBuffer_itemSize = 2; teapotVertexTextureCoordBuffer_numItems = teapotData["vertexTextureCoords"].Count / 2; teapotVertexPositionBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, teapotVertexPositionBuffer); gl.bufferData(GL.ARRAY_BUFFER, new Float32Array(teapotData["vertexPositions"].ReadAsType <float[]>()), GL.STATIC_DRAW); teapotVertexPositionBuffer_itemSize = 3; teapotVertexPositionBuffer_numItems = teapotData["vertexPositions"].Count / 3; teapotVertexIndexBuffer = gl.createBuffer(); gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, teapotVertexIndexBuffer); gl.bufferData(GL.ELEMENT_ARRAY_BUFFER, new Uint16Array(teapotData["indices"].ReadAsType <UInt16[]>()), GL.STATIC_DRAW); teapotVertexIndexBuffer_itemSize = 1; teapotVertexIndexBuffer_numItems = teapotData["indices"].Count; //document.GetElementById("loadingtext").textContent = ""; }
void initBuffers() { triangleVertexPositionBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, triangleVertexPositionBuffer); var vertices = new GLfloat[] { 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); triangleVertexPositionBuffer_itemSize = 3; triangleVertexPositionBuffer_numItems = 3; squareVertexPositionBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, squareVertexPositionBuffer); vertices = new GLfloat[] { 1.0f, 1.0f, 0.0f, -1.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); squareVertexPositionBuffer_itemSize = 3; squareVertexPositionBuffer_numItems = 4; }
void handleLoadedTexture(WebGLTexture texture, Image image) { gl.bindTexture(GL.TEXTURE_2D, texture); gl.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1 /*true*/); gl.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, image); gl.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST); gl.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST); gl.bindTexture(GL.TEXTURE_2D, null); }
public WebGLRenderingContext(HtmlElement canvas, WebGLContextAttributes attrs) { // TODO: Process attrs (e.g. {preserveDrawingBuffer: true}) context = canvas.Invoke("getContext", new object[] { "webgl" /*, attrs*/ }) as ScriptObject; if (context == null) { context = canvas.Invoke("getContext", new object[] { "experimental-webgl" }) as ScriptObject; } }
void initTexture() { neheTexture = gl.createTexture(); var neheTexture_image = new Image(); neheTexture_image.onload += delegate { handleLoadedTexture(neheTexture, neheTexture_image); }; neheTexture_image.src = "nehe.gif"; }
void initBuffers() { triangleVertexPositionBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, triangleVertexPositionBuffer); var vertices = new GLfloat[] { 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); triangleVertexPositionBuffer_itemSize = 3; triangleVertexPositionBuffer_numItems = 3; triangleVertexColorBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, triangleVertexColorBuffer); var colors = new GLfloat[] { 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); triangleVertexColorBuffer_itemSize = 4; triangleVertexColorBuffer_numItems = 3; squareVertexPositionBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, squareVertexPositionBuffer); vertices = new GLfloat[] { 1.0f, 1.0f, 0.0f, -1.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); squareVertexPositionBuffer_itemSize = 3; squareVertexPositionBuffer_numItems = 4; squareVertexColorBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, squareVertexColorBuffer); colors = new GLfloat[] {}; for (var i = 0; i < 4; i++) { colors = colors.concat(new GLfloat[] { 0.5f, 0.5f, 1.0f, 1.0f }); } gl.bufferData(GL.ARRAY_BUFFER, new Float32Array(colors), GL.STATIC_DRAW); squareVertexColorBuffer_itemSize = 4; squareVertexColorBuffer_numItems = 4; }
void initTexture() { earthTexture = gl.createTexture(); var earthTexture_image = new Image(); earthTexture_image.onload += delegate { handleLoadedTexture(earthTexture, earthTexture_image); }; earthTexture_image.src = "earth.jpg"; galvanizedTexture = gl.createTexture(); var galvanizedTexture_image = new Image(); galvanizedTexture_image.onload += delegate { handleLoadedTexture(galvanizedTexture, galvanizedTexture_image); }; galvanizedTexture_image.src = "arroway.de_metal+structure+06_d100_flat.jpg"; }
void initShaders() { var fragmentShader = getShader(gl, per_fragment_lighting_fs, GL.FRAGMENT_SHADER); var vertexShader = getShader(gl, per_fragment_lighting_vs, GL.VERTEX_SHADER); shaderProgram = gl.createProgram(); gl.attachShader(shaderProgram, vertexShader); gl.attachShader(shaderProgram, fragmentShader); gl.linkProgram(shaderProgram); if (gl.getProgramParameter(shaderProgram, GL.LINK_STATUS) == null) { alert("Could not initialise shaders"); } gl.useProgram(shaderProgram); shaderProgram_vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); gl.enableVertexAttribArray((GLuint)shaderProgram_vertexPositionAttribute); shaderProgram_vertexNormalAttribute = gl.getAttribLocation(shaderProgram, "aVertexNormal"); gl.enableVertexAttribArray((GLuint)shaderProgram_vertexNormalAttribute); shaderProgram_textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); gl.enableVertexAttribArray((GLuint)shaderProgram_textureCoordAttribute); shaderProgram_pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix"); shaderProgram_mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix"); shaderProgram_nMatrixUniform = gl.getUniformLocation(shaderProgram, "uNMatrix"); shaderProgram_samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); shaderProgram_materialShininessUniform = gl.getUniformLocation(shaderProgram, "uMaterialShininess"); shaderProgram_showSpecularHighlightsUniform = gl.getUniformLocation(shaderProgram, "uShowSpecularHighlights"); shaderProgram_useTexturesUniform = gl.getUniformLocation(shaderProgram, "uUseTextures"); shaderProgram_useLightingUniform = gl.getUniformLocation(shaderProgram, "uUseLighting"); shaderProgram_ambientColorUniform = gl.getUniformLocation(shaderProgram, "uAmbientColor"); shaderProgram_pointLightingLocationUniform = gl.getUniformLocation(shaderProgram, "uPointLightingLocation"); shaderProgram_pointLightingSpecularColorUniform = gl.getUniformLocation(shaderProgram, "uPointLightingSpecularColor"); shaderProgram_pointLightingDiffuseColorUniform = gl.getUniformLocation(shaderProgram, "uPointLightingDiffuseColor"); }
public void deleteFramebuffer(WebGLFramebuffer framebuffer) { Invoke("deleteFramebuffer", framebuffer); }
// WebGLActiveInfo getActiveAttrib(WebGLProgram program, GLuint index); // WebGLActiveInfo getActiveUniform(WebGLProgram program, GLuint index); // WebGLShader[ ] getAttachedShaders(WebGLProgram program); // GLint getAttribLocation(WebGLProgram program, DOMString name); public GLint getAttribLocation(WebGLProgram program, DOMString name) { return(GLint(Invoke("getAttribLocation", program, name))); }
public void useProgram(WebGLProgram program) { Invoke("useProgram", program); }
public void framebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, WebGLRenderbuffer renderbuffer) { Invoke("framebufferRenderbuffer", target, attachment, renderbuffertarget, renderbuffer); }
public GLboolean isTexture(WebGLTexture texture) { return((GLboolean)Invoke("isTexture", texture)); }
// void uniform1fv(WebGLUniformLocation location, FloatArray v); // void uniform1fv(WebGLUniformLocation location, sequence<float> v); public void uniform1i(WebGLUniformLocation location, GLint x) { Invoke("uniform1i", location, x); }
public GLboolean isBuffer(WebGLBuffer buffer) { return (GLboolean)Invoke("isBuffer", buffer); }
public GLboolean isFramebuffer(WebGLFramebuffer framebuffer) { return((GLboolean)Invoke("isFramebuffer", framebuffer)); }
// DOMString getProgramInfoLog(WebGLProgram program); // any getRenderbufferParameter(GLenum target, GLenum pname); public object getShaderParameter(WebGLShader shader, GLenum pname) { return Invoke("getShaderParameter", shader, pname); }
// DOMString getShaderInfoLog(WebGLShader shader); // DOMString getShaderSource(WebGLShader shader); // any getTexParameter(GLenum target, GLenum pname); // any getUniform(WebGLProgram program, WebGLUniformLocation location); public WebGLUniformLocation getUniformLocation(WebGLProgram program, DOMString name) { return (WebGLUniformLocation)Invoke("getUniformLocation", program, name); }
public DOMString getShaderInfoLog(WebGLShader shader) { return (DOMString) Invoke("getShaderInfoLog", shader); }
// any getFramebufferAttachmentParameter(GLenum target, GLenum attachment, // GLenum pname); public object getProgramParameter(WebGLProgram program, GLenum pname) { return Invoke("getProgramParameter", program, pname); }
// WebGLActiveInfo getActiveAttrib(WebGLProgram program, GLuint index); // WebGLActiveInfo getActiveUniform(WebGLProgram program, GLuint index); // WebGLShader[ ] getAttachedShaders(WebGLProgram program); // GLint getAttribLocation(WebGLProgram program, DOMString name); public GLint getAttribLocation(WebGLProgram program, DOMString name) { return GLint(Invoke("getAttribLocation", program, name)); }
// DOMString getProgramInfoLog(WebGLProgram program); // any getRenderbufferParameter(GLenum target, GLenum pname); public object getShaderParameter(WebGLShader shader, GLenum pname) { return(Invoke("getShaderParameter", shader, pname)); }
public GLboolean isFramebuffer(WebGLFramebuffer framebuffer) { return (GLboolean)Invoke("isFramebuffer", framebuffer); }
// DOMString getShaderInfoLog(WebGLShader shader); // DOMString getShaderSource(WebGLShader shader); // any getTexParameter(GLenum target, GLenum pname); // any getUniform(WebGLProgram program, WebGLUniformLocation location); public WebGLUniformLocation getUniformLocation(WebGLProgram program, DOMString name) { return((WebGLUniformLocation)Invoke("getUniformLocation", program, name)); }
public GLboolean isProgram(WebGLProgram program) { return (GLboolean)Invoke("isProgram", program); }
public GLboolean isRenderbuffer(WebGLRenderbuffer renderbuffer) { return((GLboolean)Invoke("isRenderbuffer", renderbuffer)); }
public GLboolean isRenderbuffer(WebGLRenderbuffer renderbuffer) { return (GLboolean)Invoke("isRenderbuffer", renderbuffer); }
public void shaderSource(WebGLShader shader, DOMString source) { Invoke("shaderSource", shader, source); }
public GLboolean isShader(WebGLShader shader) { return (GLboolean)Invoke("isShader", shader); }
public void uniformMatrix4fv(WebGLUniformLocation location, GLboolean transpose, Float32Array value) { Invoke("uniformMatrix4fv", location, transpose, value.Object); }
public GLboolean isTexture(WebGLTexture texture) { return (GLboolean)Invoke("isTexture", texture); }
public void deleteBuffer(WebGLBuffer buffer) { Invoke("deleteBuffer", buffer); }
public void linkProgram(WebGLProgram program) { Invoke("linkProgram", program); }
public void deleteProgram(WebGLProgram program) { Invoke("deleteProgram", program); }
// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLsizei width, GLsizei height, // GLenum format, GLenum type, ArrayBufferView pixels); // void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLenum format, GLenum type, ImageData pixels); // void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLenum format, GLenum type, HTMLImageElement image) raises (DOMException); // void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLenum format, GLenum type, HTMLCanvasElement canvas) raises (DOMException); // void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLenum format, GLenum type, HTMLVideoElement video) raises (DOMException); public void uniform1f(WebGLUniformLocation location, GLfloat x) { Invoke("uniform1f", location, x); }
// any getFramebufferAttachmentParameter(GLenum target, GLenum attachment, // GLenum pname); public object getProgramParameter(WebGLProgram program, GLenum pname) { return(Invoke("getProgramParameter", program, pname)); }
public DOMString getShaderInfoLog(WebGLShader shader) { return((DOMString)Invoke("getShaderInfoLog", shader)); }
// void uniform1iv(WebGLUniformLocation location, Int32Array v); // void uniform1iv(WebGLUniformLocation location, sequence<long> v); // void uniform2f(WebGLUniformLocation location, GLfloat x, GLfloat y); // void uniform2fv(WebGLUniformLocation location, FloatArray v); // void uniform2fv(WebGLUniformLocation location, sequence<float> v); // void uniform2i(WebGLUniformLocation location, GLint x, GLint y); // void uniform2iv(WebGLUniformLocation location, Int32Array v); // void uniform2iv(WebGLUniformLocation location, sequence<long> v); public void uniform3f(WebGLUniformLocation location, GLfloat x, GLfloat y, GLfloat z) { Invoke("uniform3f", location, x, y, z); }
public GLboolean isBuffer(WebGLBuffer buffer) { return((GLboolean)Invoke("isBuffer", buffer)); }
public GLboolean isProgram(WebGLProgram program) { return((GLboolean)Invoke("isProgram", program)); }
public void uniformMatrix4fv(WebGLUniformLocation location, GLboolean transpose, GLfloat[] value) { // FIXME: Passing float array as value into IE9 works but Firefox/Chrome gives an error Invoke("uniformMatrix4fv", location, transpose, new Float32Array(value).Object); }
public GLboolean isShader(WebGLShader shader) { return((GLboolean)Invoke("isShader", shader)); }
public void deleteTexture(WebGLTexture texture) { Invoke("deleteTexture", texture); }
public void deleteShader(WebGLShader shader) { Invoke("deleteShader", shader); }
public void deleteRenderbuffer(WebGLRenderbuffer renderbuffer) { Invoke("deleteRenderbuffer", renderbuffer); }
void initBuffers() { triangleVertexPositionBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, triangleVertexPositionBuffer); var vertices = new GLfloat[] { 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); triangleVertexPositionBuffer_itemSize = 3; triangleVertexPositionBuffer_numItems = 3; triangleVertexColorBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, triangleVertexColorBuffer); var colors = new GLfloat[] { 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); triangleVertexColorBuffer_itemSize = 4; triangleVertexColorBuffer_numItems = 3; squareVertexPositionBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, squareVertexPositionBuffer); vertices = new GLfloat[] { 1.0f, 1.0f, 0.0f, -1.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); squareVertexPositionBuffer_itemSize = 3; squareVertexPositionBuffer_numItems = 4; squareVertexColorBuffer = gl.createBuffer(); gl.bindBuffer(GL.ARRAY_BUFFER, squareVertexColorBuffer); colors = new GLfloat[] {}; for (var i=0; i < 4; i++) { colors = colors.concat(new GLfloat[] { 0.5f, 0.5f, 1.0f, 1.0f }); } gl.bufferData(GL.ARRAY_BUFFER, new Float32Array(colors), GL.STATIC_DRAW); squareVertexColorBuffer_itemSize = 4; squareVertexColorBuffer_numItems = 4; }
public void validateProgram(WebGLProgram program) { Invoke("validateProgram", program); }
public void detachShader(WebGLProgram program, WebGLShader shader) { Invoke("detachShader", program, shader); }