static void Render(WebGLRenderingContext gl, TextureLoader textureLoader, ProgramManager programManager, Level level) { gl.Viewport(0, 0, gl.DrawingBufferWidth, gl.DrawingBufferHeight); gl.ClearColor(0, 0, 0, 1); gl.Clear(gl.COLOR_BUFFER_BIT); level.Render(gl, textureLoader, programManager); }
void DrawInternal() { WebGlRenderingContext.Viewport(0, 0, canvas.Width, canvas.Height); WebGlRenderingContext.Clear(WebGlRenderingContext.COLOR_BUFFER_BIT | WebGlRenderingContext.DEPTH_BUFFER_BIT); foreach (var sprite in Sprites) { DrawSprite(sprite); } }
public void DrawScene() { gl.Viewport(0, 0, canvas.Width, canvas.Height); gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); Mat4.Perspective(45, (double)canvas.Width / canvas.Height, 0.1, 100, pMatrix); Mat4.Identity(mvMatrix); Mat4.Translate(mvMatrix, new double[] { 0.0, 0.0, z }); Mat4.Rotate(mvMatrix, this.DegToRad(xRotation), new double[] { 1, 0, 0 }); Mat4.Rotate(mvMatrix, this.DegToRad(yRotation), new double[] { 0, 1, 0 }); gl.BindBuffer(gl.ARRAY_BUFFER, this.cubeVertexPositionBuffer); gl.VertexAttribPointer(this.vertexPositionAttribute, 3, gl.FLOAT, false, 0, 0); gl.BindBuffer(gl.ARRAY_BUFFER, this.cubeVertexNormalBuffer); gl.VertexAttribPointer(this.vertexNormalAttribute, 3, gl.FLOAT, false, 0, 0); gl.BindBuffer(gl.ARRAY_BUFFER, this.cubeVertexTextureCoordBuffer); gl.VertexAttribPointer(this.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); gl.ActiveTexture(gl.TEXTURE0); gl.BindTexture(gl.TEXTURE_2D, this.texture); gl.Uniform1i(this.samplerUniform, 0); // Add Blending if (this.useBlending) { gl.BlendFunc(gl.SRC_ALPHA, gl.ONE); gl.Enable(gl.BLEND); gl.Disable(gl.DEPTH_TEST); gl.Uniform1f(this.alphaUniform, this.alpha); } else { gl.Disable(gl.BLEND); gl.Enable(gl.DEPTH_TEST); gl.Uniform1f(this.alphaUniform, 1); } // Add Lighting gl.Uniform1i(this.useLightingUniform, this.useLighting); if (this.useLighting) { gl.Uniform3f(this.ambientColorUniform, this.ambientR, this.ambientG, this.ambientB); var lightingDirection = new double[] { this.lightDirectionX, this.lightDirectionY, this.lightDirectionZ }; var adjustedLD = Vec3.Create(); Vec3.Normalize(lightingDirection, adjustedLD); Vec3.Scale(adjustedLD, -1); gl.Uniform3fv(this.lightingDirectionUniform, adjustedLD); gl.Uniform3f(this.directionalColorUniform, this.directionalR, this.directionalG, this.directionalB); } gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.cubeVertexIndexBuffer); this.SetMatrixUniforms(); gl.DrawElements(gl.TRIANGLES, 36, gl.UNSIGNED_SHORT, 0); }
public static spriteCanvas CreateScreenCanvas(WebGLRenderingContext webgl, canvasAction useraction) { var el = webgl.Canvas; el.Width = el.ClientWidth; el.Height = el.ClientHeight; var c = new spriteCanvas(webgl, webgl.DrawingBufferWidth, webgl.DrawingBufferHeight); //var asp = range.width / range.height; c.spriteBatcher.matrix = new Float32Array(new float[] { 1.0f * 2 / c.width, 0, 0, 0, //去掉asp的影响 0, 1 * -1 * 2 / c.height, 0, 0, 0, 0, 1, 0, -1, 1, 0, 1 }); c.spriteBatcher.ztest = false;//最前不需要ztest var ua = useraction; Bridge.Html5.Window.SetInterval(() => { webgl.Viewport(0, 0, webgl.DrawingBufferWidth, webgl.DrawingBufferHeight); webgl.Clear(webgl.COLOR_BUFFER_BIT | webgl.DEPTH_BUFFER_BIT); webgl.ClearColor(1.0, 0.0, 1.0, 1.0); c.spriteBatcher.begindraw(); ua.ondraw(c); c.spriteBatcher.enddraw(); //dynamic _webgl = webgl; //_webgl.flush(); //webgl.Flush(); }, 20); Window.AddEventListener("resize", () => { var sel = webgl.Canvas; sel.Width = sel.ClientWidth; sel.Height = sel.ClientHeight; sel.Width = sel.ClientWidth; sel.Height = sel.ClientHeight; c.width = sel.Width; c.height = sel.Height; c.spriteBatcher.matrix = new Float32Array(new float[] { 1.0f * 2 / c.width, 0, 0, 0,//去掉asp的影响 0, 1.0f * -1 * 2 / c.height, 0, 0, 0, 0, 1, 0, -1, 1, 0, 1 }); ////do resize func ua.onresize(c); }); el.OnMouseMove = (ev) => { ua.onpointevent(c, canvaspointevent.POINT_MOVE, (float)ev["offsetX"], (float)ev["offsetY"]); }; el.OnMouseUp = (MouseEvent <HTMLCanvasElement> ev) => { ua.onpointevent(c, canvaspointevent.POINT_UP, (float)ev["offsetX"], (float)ev["offsetY"]); }; el.OnMouseDown = (MouseEvent <HTMLCanvasElement> ev) => { ua.onpointevent(c, canvaspointevent.POINT_DOWN, (float)ev["offsetX"], (float)ev["offsetY"]); }; //scene.onPointerObservable.add((pinfo: BABYLON.PointerInfo, state: BABYLON.EventState) => //{ // var range = scene.getEngine().getRenderingCanvasClientRect(); // //输入 // var e: lighttool.canvaspointevent = lighttool.canvaspointevent.NONE; // if (pinfo.type == BABYLON.PointerEventTypes.POINTERDOWN) // e = lighttool.canvaspointevent.POINT_DOWN; // if (pinfo.type == BABYLON.PointerEventTypes.POINTERMOVE) // e = lighttool.canvaspointevent.POINT_MOVE; // if (pinfo.type == BABYLON.PointerEventTypes.POINTERUP) // e = lighttool.canvaspointevent.POINT_UP; // //缩放到canvas size // var x = pinfo.event.offsetX / range.width * c.width; // var y = pinfo.event.offsetY / range.height * c.height; // var skip: boolean = ua.onpointevent(c, e, x, y); // //对 babylon,来说 2d在这里输入,3d 要 pick 以后咯 // state.skipNextObservers = skip;//是否中断事件 //} //); return(c); }
public override void Clear(uint mask) { gl.Clear(mask); CheckError("glClear"); }