-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTextInstance.cs
97 lines (80 loc) · 2.88 KB
/
TextInstance.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Core;
using Core.Buffer;
using Core.MaterialBase;
using Core.Primitive;
using Core.Texture;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using System;
using System.Collections.Generic;
using OpenTK.Mathematics;
namespace Engine.Font
{
public class TextInstance : IDisposable
{
public TextInstance(string textContent, float x, float y)
{
TextContent = textContent;
originX = x;
originY = y;
GenerateVertices(x,y);
}
public void SetTextContent(string newTextContent)
{
if (TextContent != newTextContent)
{
TextContent = newTextContent;
GenerateVertices(originX, originY);
}
}
public void Dispose()
{
if (vb != null)
{
vb.Dispose();
}
}
public void RenderWithBox(MaterialBase fontRenderMaterial, MaterialBase fontBoxRenderMaterial)
{
RenderBox(fontBoxRenderMaterial);
Render(fontRenderMaterial);
}
private void RenderBox(MaterialBase fontBoxRenderMaterial)
{
using (var blend = new ScopedEnable(EnableCap.Blend))
using (var dummy = new ScopedDisable(EnableCap.DepthTest))
using (var blendFunc = new ScopedBlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha))
{
fontBoxRenderMaterial.BindAndExecute(boxVB, () =>
{
fontBoxRenderMaterial.SetUniformVariable("ScreenSize",
new Vector2(OpenGLContext.Instance.WindowWidth, OpenGLContext.Instance.WindowHeight));
fontBoxRenderMaterial.SetUniformVariable("BoxColor", new Vector3(0,0,0));
fontBoxRenderMaterial.SetUniformVariable("BoxAlpha", 0.70f);
GL.DrawArrays(PrimitiveType.Quads, 0, 4);
});
}
}
public void Render(MaterialBase fontRenderMaterial)
{
}
protected void GenerateVertices(float posX, float posY)
{
}
public string TextContent = "";
private DynamicVertexBuffer<PT_VertexAttribute> vb = null;
private DynamicVertexBuffer<PT_VertexAttribute> boxVB = null;
private List<PT_VertexAttribute> vertexList = new List<PT_VertexAttribute>();
private List<PT_VertexAttribute> boxVertexList = new List<PT_VertexAttribute>();
public float Left => left;
public float Right => right;
public float Top => top;
public float Bottom => bottom;
private float left = float.MaxValue;
private float right = float.MinValue;
private float top = float.MinValue;
private float bottom = float.MaxValue;
private float originX = 0;
private float originY = 0;
}
}