public static void BeginDrawColor(IVertexBuffer vertexBuffer, Matrix4 transform, Vector4 color) { ColorShader.Use(); ColorShader.ModelMatrix.Set(transform); ColorShader.Color.Set(color); vertexBuffer.Bind(); vertexBuffer.BindAttribute(ColorShader.Position, 0); }
protected override void Begin(Vector2Int size, Color backgroundColor) { base.Begin(size, backgroundColor); _viewSize = size; // Update the projection in all of the shaders if the view size changes. if (_projectionSize != _viewSize) { _projectionSize = _viewSize; Matrix4 projection = Matrix4.CreateOrtho(0.0f, size.x, size.y, 0.0f, -1000.0f, 1000.0f); _colorShader.Use(); _colorShader.Projection = projection; _textureShaderA8.Use(); _textureShaderA8.Projection = projection; _textureShaderRGBA.Use(); _textureShaderRGBA.Projection = projection; _textureShaderRGB.Use(); _textureShaderRGB.Projection = projection; _textureShaderSDF.Use(); _textureShaderSDF.Projection = projection; _textureShaderStencil.Use(); _textureShaderStencil.Projection = projection; if (null != _batch.Shader) { _batch.Shader.Use(); } GL.ClearStencil(0); } // Initialize the viewport to the given size GL.Viewport(0, 0, size.x, size.y); GL.Enable(GL.EnableCapability.Blend); GL.BlendFunc(GL.BlendFactorSrc.SrcAlpha, GL.BlendFactorDest.OneMinusSrcAlpha); GL.Disable(GL.EnableCapability.StencilTest); GL.ColorMask(true, true, true, true); GL.DepthMask(true); // Clear the background if a background color was given if (backgroundColor.A > 0) { GL.ClearColor(backgroundColor); GL.Clear(GL.ClearBuffer.Color | GL.ClearBuffer.Depth); } else { GL.Clear(GL.ClearBuffer.Depth); } }
public static void DrawLine(Matrix4 transform, Vector4 color, Vector3 p1, Vector3 p2, float thickness = 1f) { ColorShader.Use(); ColorShader.ModelMatrix.Set(transform); ColorShader.Color.Set(color); GL.PushAttrib(AttribMask.LineBit); GL.LineWidth(thickness); GL.Begin(PrimitiveType.Lines); GL.Vertex3(p1); GL.Vertex3(p2); GL.End(); GL.PopAttrib(); }
public static void DrawBoundingBox(Matrix4 transform, BBox box, Vector4 color, float thickness = 1f) { ColorShader.Use(); ColorShader.ModelMatrix.Set(Matrix4.CreateScale(box.Size) * Matrix4.CreateTranslation(box.Center) * transform); ColorShader.Color.Set(color); BoundingBoxBufffer.Bind(); BoundingBoxBufffer.BindAttribute(ColorShader.Position, 0); GL.PushAttrib(AttribMask.LineBit); GL.LineWidth(thickness); BoundingBoxBufffer.DrawElements(PrimitiveType.Lines); GL.PopAttrib(); }
public static void DrawRectangle(Matrix4 transform, Vector2 size, Vector4 color, float thickness = 1f) { ColorShader.Use(); ColorShader.ModelMatrix.Set(transform); ColorShader.Color.Set(color); GL.PushAttrib(AttribMask.LineBit); GL.LineWidth(thickness); GL.Begin(PrimitiveType.LineStrip); GL.Vertex3(Vector3.Zero); GL.Vertex3(Vector3.UnitZ * size.Y); GL.Vertex3(Vector3.UnitX * size.X + Vector3.UnitZ * size.Y); GL.Vertex3(Vector3.UnitX * size.X); GL.Vertex3(Vector3.Zero); GL.End(); GL.PopAttrib(); }
public static void DrawGizmoAxes(Matrix4 transform, float size, float lineThickness = 1f) { ColorShader.Use(); ColorShader.ModelMatrix.Set(transform); GL.PushAttrib(AttribMask.LineBit); GL.LineWidth(lineThickness); for (int i = 0; i < 3; i++) { ColorShader.Color.Set(DefaultAxisColors[i]); GL.Begin(PrimitiveType.Lines); GL.Vertex3(Vector3.Zero); var axisVector = new Vector3(); axisVector[i] = 1f; GL.Vertex3(axisVector * size); GL.End(); } GL.PopAttrib(); }
public static void InitializeMatrices(Camera camera) { var viewMatrix = camera.GetViewMatrix(); var projection = camera.GetProjectionMatrix(); WireframeShader.Use(); WireframeShader.ViewMatrix.Set(viewMatrix); WireframeShader.Projection.Set(projection); WireframeShader2.Use(); WireframeShader2.ViewMatrix.Set(viewMatrix); WireframeShader2.Projection.Set(projection); ColorShader.Use(); ColorShader.ViewMatrix.Set(viewMatrix); ColorShader.Projection.Set(projection); ModelShader.Use(); ModelShader.ViewMatrix.Set(viewMatrix); ModelShader.Projection.Set(projection); ModelShader.ViewPosition.Set(camera.Position); StudConnectionShader.Use(); StudConnectionShader.ViewMatrix.Set(viewMatrix); StudConnectionShader.Projection.Set(projection); SimpleTextureShader.Use(); SimpleTextureShader.ViewMatrix.Set(viewMatrix); SimpleTextureShader.Projection.Set(projection); if (UIRenderHelper.Freetype6Loaded) { UIRenderHelper.TextRenderer.ProjectionMatrix = projection; UIRenderHelper.TextRenderer.DrawingPrimitives.Clear(); } TextViewMatrix = viewMatrix; GL.UseProgram(0); }