Files
Dashboard/tests/Dashboard.TestApplication/Program.cs
T

113 lines
3.4 KiB
C#

using Dashboard.BlurgText;
using Dashboard.BlurgText.OpenGL;
using Dashboard.Controls;
using Dashboard.Drawing;
using Dashboard.Events;
using Dashboard.OpenGL;
using Dashboard.OpenTK.PAL2;
using Dashboard.Pal;
using Dashboard.StbImage;
using OpenTK.Graphics.OpenGL;
using OpenTK.Mathematics;
using OpenTK.Platform;
using TK = OpenTK.Platform.Toolkit;
Application app = new Pal2Application(new ToolkitOptions()
{
ApplicationName = "DashTerm",
Windows = new ToolkitOptions.WindowsOptions()
{
EnableVisualStyles = true,
IsDPIAware = true,
},
FeatureFlags = ToolkitFlags.EnableOpenGL,
})
{
GraphicsApiHints = new OpenGLGraphicsApiHints()
{
Version = new Version(3, 2),
ForwardCompatibleFlag = true,
DebugFlag = true,
Profile = OpenGLProfile.Core,
sRGBFramebuffer = true,
SwapMethod = ContextSwapMethod.Undefined,
RedColorBits = 8,
GreenColorBits = 8,
BlueColorBits = 8,
AlphaColorBits = 8,
Multisamples = 0,
SupportTransparentFramebufferX11 = true,
}
};
CancellationTokenSource source = new CancellationTokenSource();
app.Initialize();
app.ExtensionRequire<StbImageLoader>();
app.ExtensionLoad(new BlurgTextExtension(new BlurgTextExtensionFactory()));
PhysicalWindow window = (PhysicalWindow)app.CreatePhysicalWindow();
MessageBox box = MessageBox.Create(window, "Are you sure you want to exit?", "Confirm Exit", MessageBoxIcon.Question,
MessageBoxButtons.YesNo);
// window.Title = "DashTerm";
TK.Window.SetMinClientSize(window.WindowHandle, 300, 200);
TK.Window.SetClientSize(window.WindowHandle, new Vector2i(320, 240));
TK.Window.SetBorderStyle(window.WindowHandle, WindowBorderStyle.ResizableBorder);
// TK.Window.SetTransparencyMode(wnd, WindowTransparencyMode.TransparentFramebuffer, 0.1f);
GLDeviceContext context = (GLDeviceContext)window.DeviceContext;
context.GLContext.MakeCurrent();
context.GLContext.SwapGroup.SwapInterval = 1;
GL.Disable(EnableCap.DepthTest);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
GL.ColorMask(true, true, true, true);
TK.Window.SetMode(window.WindowHandle, WindowMode.Normal);
window.DeviceContext.ExtensionRequire<IDeviceContextBase>().ScaleOverride = 1.5f;
IDirectRendering direct = window.DeviceContext.ExtensionRequire<IDirectRendering>();
IBuffer vertex = direct.CreateBuffer(BufferAccessPattern.Static, 1024);
float[] vertices = new float[]
{ // x, y, z, _, r, g, b, a
-0.5f, -0.5f, 0.0f, 0.0f, 1, 0, 0, 1,
+0.5f, -0.5f, 0.0f, 0.0f, 0, 1, 0, 1,
+0.0f, +0.5f, 0.0f, 0.0f, 0, 0, 1, 1,
};
vertex.Write(0, vertices);
DrawCall call = new DrawCall(MeshPrimitive.Triangle, vertex)
{
ShaderPipeline = null,
Attributes =
[
new VertexAttribute(0, 3, VertexAttributeType.Float, 0, 8 * sizeof(float)),
new VertexAttribute(1, 4, VertexAttributeType.Float, 4 * sizeof(float), 8 * sizeof(float))
],
};
window.EventRaised += (sender, eventArgs) =>
{
if (eventArgs is not PaintEventArgs paint)
return;
paint.DeviceContext.ExtensionRequire<IDirectRendering>().Draw(call);
};
app.Run(true, source.Token);
class BlurgTextExtensionFactory : IBlurgDcExtensionFactory
{
public BlurgDcExtension CreateExtension(BlurgTextExtension appExtension, DeviceContext dc)
{
return new BlurgGLExtension();
}
};