public GLTextRenderer(GLGraphicsDevice device, Font font, Camera camera) { this.colourpicker = (c, i) => this.currentDrawColour; this.state.Setup(); this.vertexCount = 0; this.vertices = new Vertex2[dataSize]; this.Camera = camera; this.glyphs = new Dictionary <uint, TexturedGlyph>(); this.SetupGrahpicsResources(device); this.SetFont(font); }
private void SetupGrahpicsResources(GLGraphicsDevice device) { this.vertexBuffer.Generate(); this.layout = device.CreateVertexLayout(); var attribute = new VertexAttribute(); attribute.Index = 0; attribute.Offset = 0; attribute.Stride = Marshal.SizeOf <Vertex2>(); attribute.Format = VertexAttributeFormat.Vector2f; attribute.Usage = VertexAttributeUsage.Position; layout.SetAttribute(attribute); attribute.Index = 1; attribute.Offset = Marshal.SizeOf <Vector2>(); attribute.Stride = Marshal.SizeOf <Vertex2>(); attribute.Format = VertexAttributeFormat.Vector2f; attribute.Usage = VertexAttributeUsage.TextureCoordinate; layout.SetAttribute(attribute); attribute.Index = 2; attribute.Offset = Marshal.SizeOf <Vector2>() * 2; attribute.Stride = Marshal.SizeOf <Vertex2>(); attribute.Format = VertexAttributeFormat.Vector4f; attribute.Usage = VertexAttributeUsage.Colour; layout.SetAttribute(attribute); var asm = typeof(GLTextRenderer).Assembly; var vertpath = $"{nameof(GLTextRenderer)}.vert.glsl"; var fragpath = $"{nameof(GLTextRenderer)}.frag.glsl"; this.program = (GLShader)device.CreateShader(ShaderFormat.GLSL, asm.GetManifestResourceStream(vertpath), asm.GetManifestResourceStream(fragpath)); this.program.SetVertexData(this.vertexBuffer, this.layout); this.fontTexture = device.CreateTexture2D(new Vector2i(1024, 2048), PixelFormat.GrayScale); this.fontTexture.Filter = TextureFilter.Linear; this.program.SetUniform("Texture", this.fontTexture, 0); }