void RenderScene(ITexture2D scene) { sceneShader.Activate(); scene.Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); scene.Deactivate(); sceneShader.Deactivate(); }
/// <summary> /// Saves a texture to a buffer. /// </summary> /// <param name="texture">The texture to save.</param> /// <param name="buffer">The buffer to write to</param> public static void ToBuffer(this ITexture2D texture, ref float[,] buffer) { if (buffer is null) { throw new ArgumentNullException(nameof(buffer)); } try { texture.Activate(); GL.GetTexImage(TextureTarget.Texture2D, 0, PixelFormat.Red, PixelType.Float, buffer); texture.Deactivate(); } catch { texture.Deactivate(); } }
/// <summary> /// Saves to bitmap. /// </summary> /// <param name="texture">The texture.</param> /// <param name="format">The format.</param> /// <returns></returns> public static Bitmap SaveToBitmap(this ITexture2D texture, SysDraw.PixelFormat format = SysDraw.PixelFormat.Format32bppArgb) { try { var bmp = new Bitmap(texture.Width, texture.Height); texture.Activate(); var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), SysDraw.ImageLockMode.WriteOnly, format); GL.GetTexImage(TextureTarget.Texture2D, 0, SelectPixelFormat(format), PixelType.UnsignedByte, data.Scan0); bmp.UnlockBits(data); texture.Deactivate(); bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); return(bmp); } catch { texture.Deactivate(); return(null); } }
/// <summary> /// Draws the specified texture. /// </summary> /// <param name="texture">The texture.</param> public static void Draw(ITexture2D texture) { if (shaderProgram is null) { InitShader(); } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); texture.Activate(); shaderProgram.Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); shaderProgram.Deactivate(); texture.Deactivate(); }
internal void Draw(IEnumerable <ITile> tiles) { GL.Clear(ClearBufferMask.ColorBufferBit); GL.LoadIdentity(); GL.Scale(2f, 2f, 1f); GL.Translate(-.5f, -.5f, 0f); texTileSet.Activate(); foreach (var tile in tiles) { DrawTools.DrawTexturedRect(tile.Bounds, tile.TexCoords); } texTileSet.Deactivate(); }
protected void DrawPass(ITexture2D inputTexture, IRenderSurface surface, IShaderProgram shader) { surface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit); shader.Activate(); inputTexture.Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); inputTexture.Deactivate(); shader.Deactivate(); surface.Deactivate(); }
public void Draw(ITexture2D inputTexture) { _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _postProcessShader.Activate(); inputTexture.Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); inputTexture.Deactivate(); _postProcessShader.Deactivate(); _outputSurface.Deactivate(); }
private new void DrawPass(ITexture2D inputTexture, IRenderSurface surface, IShaderProgram shader) { surface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit); shader.Activate(); shader.Uniform("Size", _blurKernelSize); inputTexture.Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); inputTexture.Deactivate(); shader.Deactivate(); surface.Deactivate(); }
public void Draw(IRenderState renderState, ITransformation camera, float time) { _outputSurface.Activate(); var oldBackFaceCullingState = renderState.Get <BackFaceCulling>(); var oldDepthTestState = renderState.Get <DepthTest>(); renderState.Set(new DepthTest(true)); renderState.Set(new BackFaceCulling(true)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _tesselationProgram.Activate(); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); //Does not work with our FBOs. I don´t know why. Turn off for now or only test without FBO. GL.PatchParameter(PatchParameterInt.PatchVertices, 4); const int instanceSqrt = 3; _tesselationProgram.Uniform("camera", camera); _tesselationProgram.Uniform(nameof(instanceSqrt), instanceSqrt); _tesselationProgram.Uniform("iGlobalTime", time); _tesselationProgram.Uniform("size", 20); //Does not work _displacementMap.Activate(); GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 }); GL.DrawBuffers(_drawBuffers.Length, _drawBuffers); GL.DrawArraysInstanced(PrimitiveType.Patches, 0, 4, instanceSqrt * instanceSqrt); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); _displacementMap.Deactivate(); _tesselationProgram.Deactivate(); renderState.Set(oldDepthTestState); renderState.Set(oldBackFaceCullingState); _outputSurface.Deactivate(); }
public void ShowCubeMap(ITexture2D sphereTexture, int side) { GL.CullFace(CullFaceMode.Front); DefaultMesh cubeMesh = Meshes.CreateCubeWithNormals(); VAO renderCube = VAOLoader.FromMesh(cubeMesh, cubeProjectionShader); //Set up Projection Matrix and View Matrix for rendering into Cubemap Matrix4x4 captureProjection = Matrix4x4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(90.0f), 1.0f, 0.1f, 10.0f); Matrix4x4[] captureView = { Matrix4x4.CreateLookAt(Vector3.Zero, new Vector3(1.0f, 0.0f, 0.0f), new Vector3(0.0f, -1.0f, 0.0f)), Matrix4x4.CreateLookAt(Vector3.Zero, new Vector3(-1.0f, 0.0f, 0.0f), new Vector3(0.0f, -1.0f, 0.0f)), Matrix4x4.CreateLookAt(Vector3.Zero, new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f)), Matrix4x4.CreateLookAt(Vector3.Zero, new Vector3(0.0f, -1.0f, 0.0f), new Vector3(0.0f, 0.0f, -1.0f)), Matrix4x4.CreateLookAt(Vector3.Zero, new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, -1.0f, 0.0f)), Matrix4x4.CreateLookAt(Vector3.Zero, new Vector3(0.0f, 0.0f, -1.0f), new Vector3(0.0f, -1.0f, 0.0f)), }; //Setting up shader cubeProjectionShader.Activate(); SetSampler(cubeProjectionShader.ProgramID, 0, "equirectangularMap", sphereTexture); cubeProjectionShader.Uniform("projection", captureProjection, true); GL.ActiveTexture(TextureUnit.Texture0); sphereTexture.Activate(); //Render into Cubemap GL.Viewport(0, 0, 512, 512); cubeProjectionShader.Uniform("view", captureView[side], true); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); renderCube.Draw(); sphereTexture.Deactivate(); DeactivateTexture(0); GL.CullFace(CullFaceMode.Back); }
public void Deactivate() { text.Deactivate(); }