/// <summary> /// copies the backcound to the foreground. /// </summary> public void CopyFromBackGround() { // Draw the Texture from Backbuffer by a Polygon Rectangle for the full screen xyArray FP = new xyArray(); FP.data = new xy[] { new xy(0, 0), new xy(0, 1), new xy(1, 1), new xy(1, 0) }; Matrix P = ProjectionMatrix; GLShader S = Shader; RenderKind K = RenderKind; RenderKind = RenderKind.Render; Shader = BackGroundShader; Texture T = texture; texture = BackBuffer.Texture; PushMatrix(); ModelMatrix = Matrix.Translation(new xyz(0, 0, 1)); PolygonMode PM = PolygonMode; PolygonMode = PolygonMode.Fill; ProjectionMatrix = Bias; drawPolyLine(FP); ProjectionMatrix = P; PopMatrix(); // Save Back RenderKind = K; texture = T; this.Shader = S; PolygonMode = PM; }
/// <summary> /// refreshes the back ground for <see cref="ForeGroundDraw"/>. /// </summary> public void RefreshBackGround() { Texture Savet = texture; GLShader S = Shader; BackBuffer.BackGround = BackColor; if (BackBuffer.FboHandle <= 0) { BackBuffer.Init((int)ViewPort.Width, (int)ViewPort.Height); } RenderKind K = RenderKind; RenderKind = RenderKind.Render; Matrix P = ProjectionMatrix; ProjectionMatrix = Matrix.scale(new xyz(1, -1, 1)) * P; //--------- Draw scene to Backbuffer BackBuffer.EnableWriting(); OnPaint(); BackBuffer.DisableWriting(); texture = Savet; ProjectionMatrix = P; RenderKind = K; Shader = S; }
/// <summary> /// calculates a new shadow. /// </summary> public void ResetShadow() { ShadowDirty = false; if (!Shadow) { return; } GLShader SaveShader = this.Shader; RenderKind = RenderKind.Render; Matrix SaveP = ProjectionMatrix; Texture SaveTexture = texture; GL.Enable(EnableCap.PolygonOffsetFill); GL.PolygonOffset(1, 0); Shader = ShadowDepthShader; ProjectionMatrix = GetLightProjectionMatrix(); ShadowFBO.EnableWriting(); OnPaint(); ShadowFBO.DisableWriting(); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, ShadowFBO.FboTexture); ProjectionMatrix = SaveP; Shader = SaveShader; GL.ActiveTexture(TextureUnit.Texture0); }
/// <summary> /// is called from <see cref="OpenGlDevice.setTexture(Texture)"/> to set the values to the current <see cref="OpenGlDevice.Shader"/>. /// </summary> /// <param name="Shader">the current <see cref="OpenGlDevice.Shader"/>.</param> public void SetAttributes(GLShader Shader) { Matrix M = Matrix.Scale(new xyz(1 / WorldWidth, -1 / WorldHeight, 1 / WorldWidth)); Matrix TextureMatrix = Matrix.identity; if (SoBigAsPossible != Texture.BigAsPosible.None) { TextureMatrix = Matrix.Scale(new xyz(1, -1, 1)); } else { TextureMatrix = M * Matrix.Translation(new xyz(-Translation.x, -Translation.y, 0)) * Matrix.Rotation(new xyz(0, 0, 1), -Rotation); } GL.ActiveTexture(TextureUnit.Texture0 + Index); GL.BindTexture(TextureTarget.Texture2D, Handle); OpenGlDevice.CheckError(); Field T = Shader.getvar("Texture" + Index.ToString() + "Enabled"); if (T != null) { T.SetValue(1); } T = Shader.getvar("Texture" + Index.ToString() + "_"); if (T != null) { T.SetValue(Index); } T = Shader.getvar("Texture" + Index.ToString() + "Matrix"); if (T != null) { T.SetMatrix(TextureMatrix); } if (NormalMap) { T = Shader.getvar("NormalMap"); if (T != null) { T.SetValue(true); } } if (Tesselation) { T = Shader.getvar("Tesselation"); if (T != null) { T.SetValue(true); } } }
void ActivateShader() { ShadowDepthShader = new GLShader(OpenGlDevice.DepthFragment, OpenGlDevice.DepthVertex, this); BackGroundShader = new GLShader(BackGroundFragment, BackGroundVertex, this); PickingShader = new GLShader(Selector.PickingFragmentShader, Selector.PickingVertexShader, this); }
/// <summary> /// overrides the draw method . /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { int StoredObject = -1; if (Selector.WriteToSnap) { CompiledMesh C = this as CompiledMesh; if (C != null) { StoredObject = C.SnapObject; } Device.Selector.SetObjectNumber(StoredObject); } Entity.CurrentEntity = this; if (Compiling) { MeshCreator.AddProg(this); return; } float PW = Device.PenWidth; PenStyles PS = Device.PenStyle; Material Save = Device.Material; if (Mode == PolygonMode.Line) { Device.PenWidth = PenWidth; Device.PenStyle = PenStyle; Device.Emission = PenColor; } else { Device.Material = Material; } PolygonMode SavePolygonMode = Device.PolygonMode; Device.PolygonMode = Mode; if ((VAO >= 0) && (Device.RenderKind == RenderKind.Render)) { OpenGlDevice.CheckError(); Field C = null; if (Colors != null) { C = Device.Shader.getvar("ColorEnabled"); if (C != null) { C.SetValue(1); } } GL.BindVertexArray(VAO); if (!TesselateOn) { GL.DrawElements(Primitives, VBOIndices.IndexArray.Length, DrawElementsType.UnsignedInt, 0); OpenGlDevice.CheckError(); } else { GLShader SaveShader = Device.Shader; Device.Shader = Device.TesselationtShader; if (FieldResolutionFactor == null) { FieldResolutionFactor = Device.Shader.getvar("ResolutionFactor"); } if (FieldDispFactor == null) { FieldDispFactor = Device.Shader.getvar("gDispFactor"); } if (FieldEyePos == null) { FieldEyePos = Device.Shader.getvar("gEyeWorldPos"); } if (FieldDispFactor != null) { FieldDispFactor.SetValue((float)TessDispFactor); } if (FieldEyePos != null) { FieldEyePos.SetValue(Device.Camera.Position); } Device.texture = TessDisplacementMap; //GL.ActiveTexture(TextureUnit.Texture0 + 1); //GL.BindTexture(TextureTarget.Texture2D, TessDisplacementMap.Handle); if (Texture != null) { Device.texture = Texture; } if (FieldResolutionFactor != null) { FieldResolutionFactor.SetValue((float)TessResolutionFactor); } GL.DrawElements(BeginMode.Patches, VBOIndices.IndexArray.Length, DrawElementsType.UnsignedInt, 0); TessDisplacementMap.Hide(); Device.Shader = SaveShader; Device.texture = null; } GL.BindVertexArray(0); if (Colors != null) { if (C != null) { C.SetValue(0); } } } else { if (Primitives == BeginMode.Quads) { DrawQuads(Device); } else { Texture SaveTexture = Device.texture; Device.texture = Texture; Device.drawMesh(Indices, VBOPosition.xyzPoints, VBONormals.xyzPoints, VBOTexture.xyPoints, VBOColors.xyzPoints); Device.texture = SaveTexture; } } Device.PolygonMode = SavePolygonMode; if (Mode == PolygonMode.Line) { Device.PenWidth = PW; Device.PenStyle = PS; Device.Emission = Color.Black; } Device.Material = Save; }