2023-06-30 02:10:24 +00:00
|
|
|
using OpenTK.Graphics.OpenGL4;
|
|
|
|
using OpenTK.Mathematics;
|
|
|
|
using OpenTK.Windowing.Common;
|
|
|
|
using OpenTK.Windowing.Desktop;
|
|
|
|
using OpenTK.Windowing.GraphicsLibraryFramework;
|
|
|
|
// https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Image.html
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using Image = SixLabors.ImageSharp.Image;
|
|
|
|
|
|
|
|
namespace SemiColinGames;
|
|
|
|
|
2023-07-06 22:31:50 +00:00
|
|
|
public class CameraInfo {
|
|
|
|
public readonly Vector2i Resolution;
|
|
|
|
|
|
|
|
private CameraInfo(Vector2i resolution) {
|
|
|
|
Resolution = resolution;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly CameraInfo NIKON_D7000 = new CameraInfo(new Vector2i(4928, 3264));
|
|
|
|
public static readonly CameraInfo IPHONE_12_MINI = new CameraInfo(new Vector2i(4032, 3024));
|
|
|
|
}
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
public class Shader : IDisposable {
|
2023-07-08 03:29:51 +00:00
|
|
|
public int Handle;
|
|
|
|
private bool init = false;
|
|
|
|
|
|
|
|
public Shader() {}
|
2023-06-30 02:10:24 +00:00
|
|
|
|
2023-07-08 03:29:51 +00:00
|
|
|
public void Init() {
|
|
|
|
init = true;
|
2023-06-30 02:10:24 +00:00
|
|
|
int VertexShader;
|
|
|
|
int FragmentShader;
|
|
|
|
|
|
|
|
string VertexShaderSource = @"
|
|
|
|
#version 330
|
|
|
|
|
|
|
|
layout(location = 0) in vec3 aPosition;
|
|
|
|
layout(location = 1) in vec2 aTexCoord;
|
|
|
|
|
|
|
|
out vec2 texCoord;
|
|
|
|
|
|
|
|
uniform mat4 projection;
|
|
|
|
|
|
|
|
void main(void) {
|
|
|
|
texCoord = aTexCoord;
|
|
|
|
gl_Position = vec4(aPosition, 1.0) * projection;
|
|
|
|
}";
|
|
|
|
|
|
|
|
string FragmentShaderSource = @"
|
|
|
|
#version 330
|
|
|
|
|
|
|
|
out vec4 outputColor;
|
|
|
|
in vec2 texCoord;
|
|
|
|
uniform sampler2D texture0;
|
2023-07-07 03:14:55 +00:00
|
|
|
uniform vec4 color;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
|
|
void main() {
|
2023-07-07 03:14:55 +00:00
|
|
|
outputColor = texture(texture0, texCoord) * color;
|
2023-06-30 02:10:24 +00:00
|
|
|
}";
|
|
|
|
|
|
|
|
VertexShader = GL.CreateShader(ShaderType.VertexShader);
|
|
|
|
GL.ShaderSource(VertexShader, VertexShaderSource);
|
|
|
|
|
|
|
|
FragmentShader = GL.CreateShader(ShaderType.FragmentShader);
|
|
|
|
GL.ShaderSource(FragmentShader, FragmentShaderSource);
|
|
|
|
|
|
|
|
GL.CompileShader(VertexShader);
|
|
|
|
|
|
|
|
int success;
|
|
|
|
GL.GetShader(VertexShader, ShaderParameter.CompileStatus, out success);
|
|
|
|
if (success == 0) {
|
|
|
|
string infoLog = GL.GetShaderInfoLog(VertexShader);
|
|
|
|
Console.WriteLine(infoLog);
|
|
|
|
}
|
|
|
|
|
|
|
|
GL.CompileShader(FragmentShader);
|
|
|
|
|
|
|
|
GL.GetShader(FragmentShader, ShaderParameter.CompileStatus, out success);
|
|
|
|
if (success == 0) {
|
|
|
|
string infoLog = GL.GetShaderInfoLog(FragmentShader);
|
|
|
|
Console.WriteLine(infoLog);
|
|
|
|
}
|
|
|
|
Handle = GL.CreateProgram();
|
|
|
|
|
|
|
|
GL.AttachShader(Handle, VertexShader);
|
|
|
|
GL.AttachShader(Handle, FragmentShader);
|
|
|
|
|
|
|
|
GL.LinkProgram(Handle);
|
|
|
|
|
|
|
|
GL.GetProgram(Handle, GetProgramParameterName.LinkStatus, out success);
|
|
|
|
if (success == 0) {
|
|
|
|
string infoLog = GL.GetProgramInfoLog(Handle);
|
|
|
|
Console.WriteLine(infoLog);
|
|
|
|
}
|
|
|
|
|
|
|
|
GL.DetachShader(Handle, VertexShader);
|
|
|
|
GL.DetachShader(Handle, FragmentShader);
|
|
|
|
GL.DeleteShader(FragmentShader);
|
|
|
|
GL.DeleteShader(VertexShader);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Use() {
|
2023-07-08 03:29:51 +00:00
|
|
|
if (!init) {
|
|
|
|
Console.WriteLine("Shader.Use(): must call Init() first");
|
|
|
|
}
|
2023-06-30 02:10:24 +00:00
|
|
|
GL.UseProgram(Handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool disposedValue = false;
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing) {
|
|
|
|
if (!disposedValue) {
|
|
|
|
GL.DeleteProgram(Handle);
|
|
|
|
disposedValue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~Shader() {
|
|
|
|
if (disposedValue == false) {
|
|
|
|
Console.WriteLine("~Shader(): resource leak? Dispose() should be called manually.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose() {
|
|
|
|
Dispose(true);
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetAttribLocation(string name) {
|
|
|
|
return GL.GetAttribLocation(Handle, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetUniformLocation(string name) {
|
|
|
|
return GL.GetUniformLocation(Handle, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Texture : IDisposable {
|
|
|
|
public int Handle;
|
2023-07-07 20:00:43 +00:00
|
|
|
// FIXME: use a Vector2i for dimensions.
|
2023-06-30 02:21:41 +00:00
|
|
|
public int Width;
|
|
|
|
public int Height;
|
2023-06-30 02:10:24 +00:00
|
|
|
|
2023-07-06 22:31:50 +00:00
|
|
|
public Texture(Image<Rgba32> image) {
|
2023-06-30 02:21:41 +00:00
|
|
|
Width = image.Width;
|
|
|
|
Height = image.Height;
|
|
|
|
Console.WriteLine($"image loaded: {Width}x{Height}");
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
//foreach (IExifValue exif in image.Metadata.ExifProfile.Values) {
|
|
|
|
// Console.WriteLine($"{exif.Tag} : {exif.GetValue()}");
|
|
|
|
//}
|
2023-06-30 02:21:41 +00:00
|
|
|
byte[] pixelBytes = new byte[Width * Height * Unsafe.SizeOf<Rgba32>()];
|
2023-06-30 02:10:24 +00:00
|
|
|
image.CopyPixelDataTo(pixelBytes);
|
|
|
|
image.Dispose();
|
|
|
|
|
|
|
|
Handle = GL.GenTexture();
|
|
|
|
GL.ActiveTexture(TextureUnit.Texture0);
|
|
|
|
GL.BindTexture(TextureTarget.Texture2D, Handle);
|
|
|
|
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, image.Width, image.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixelBytes);
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.LinearMipmapLinear); // FIXME: is this right?
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) TextureMagFilter.Nearest);
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) TextureWrapMode.ClampToBorder);
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) TextureWrapMode.ClampToBorder);
|
|
|
|
float[] borderColor = { 0.0f, 0.0f, 0.0f, 1.0f };
|
|
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, borderColor);
|
|
|
|
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool disposedValue = false;
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing) {
|
|
|
|
if (!disposedValue) {
|
|
|
|
GL.DeleteTexture(Handle);
|
|
|
|
disposedValue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~Texture() {
|
|
|
|
if (!disposedValue) {
|
|
|
|
Console.WriteLine("~Texture(): resource leak? Dispose() should be called manually.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose() {
|
|
|
|
Dispose(true);
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-07 18:24:43 +00:00
|
|
|
public class UiGeometry {
|
|
|
|
public static Vector2i MIN_WINDOW_SIZE = new Vector2i(640, 480);
|
2023-07-07 18:52:36 +00:00
|
|
|
private static CameraInfo activeCamera = CameraInfo.NIKON_D7000;
|
2023-07-07 18:24:43 +00:00
|
|
|
|
|
|
|
public readonly Vector2i WindowSize;
|
2023-07-07 18:52:36 +00:00
|
|
|
public readonly List<Box2i> ThumbnailBoxes = new();
|
2023-07-07 20:00:43 +00:00
|
|
|
public readonly Box2i PhotoBox;
|
2023-07-07 18:24:43 +00:00
|
|
|
|
|
|
|
public UiGeometry() : this(MIN_WINDOW_SIZE) {}
|
|
|
|
|
|
|
|
public UiGeometry(Vector2i windowSize) {
|
|
|
|
WindowSize = windowSize;
|
2023-07-07 18:52:36 +00:00
|
|
|
|
|
|
|
int thumbnailHeight = 150;
|
|
|
|
int thumbnailWidth = (int) 1.0 * thumbnailHeight * activeCamera.Resolution.X / activeCamera.Resolution.Y;
|
|
|
|
int numBoxes = 10; // FIXME
|
|
|
|
for (int i = 0; i < numBoxes; i++) {
|
|
|
|
Box2i box = Util.makeBox(WindowSize.X - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight);
|
|
|
|
ThumbnailBoxes.Add(box);
|
|
|
|
}
|
2023-07-07 20:00:43 +00:00
|
|
|
|
|
|
|
PhotoBox = new(0, 0, WindowSize.X - thumbnailWidth, WindowSize.Y);
|
2023-07-07 18:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Util {
|
|
|
|
public static Box2i makeBox(int left, int top, int width, int height) {
|
|
|
|
return new Box2i(left, top, left + width, top + height);
|
2023-07-07 18:24:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
public class Game : GameWindow {
|
|
|
|
public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) { }
|
|
|
|
|
2023-07-08 03:29:51 +00:00
|
|
|
private static Image<Rgba32> white1x1 = new(1, 1, new Rgba32(255, 255, 255));
|
|
|
|
private static Texture TEXTURE_WHITE = new Texture(white1x1);
|
2023-07-06 22:31:50 +00:00
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
UiGeometry geometry = new();
|
2023-07-07 18:24:43 +00:00
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
// Four points, each consisting of (x, y, z, tex_x, tex_y).
|
2023-07-07 18:24:43 +00:00
|
|
|
float[] vertices = new float[20];
|
2023-06-30 02:10:24 +00:00
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
// Indices to draw a rectangle from two triangles.
|
2023-06-30 02:10:24 +00:00
|
|
|
uint[] indices = {
|
|
|
|
0, 1, 3, // first triangle
|
|
|
|
1, 2, 3 // second triangle
|
|
|
|
};
|
|
|
|
|
|
|
|
int VertexBufferObject;
|
|
|
|
int ElementBufferObject;
|
|
|
|
int VertexArrayObject;
|
2023-07-07 18:52:36 +00:00
|
|
|
List<Texture> textures = new();
|
2023-06-30 02:10:24 +00:00
|
|
|
int textureIndex = 0;
|
2023-07-08 03:29:51 +00:00
|
|
|
Shader shader = new Shader();
|
2023-06-30 02:10:24 +00:00
|
|
|
Matrix4 projection;
|
|
|
|
|
|
|
|
protected override void OnUpdateFrame(FrameEventArgs e) {
|
|
|
|
base.OnUpdateFrame(e);
|
|
|
|
|
|
|
|
KeyboardState input = KeyboardState;
|
|
|
|
|
|
|
|
if (input.IsKeyDown(Keys.Escape)) {
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.IsKeyPressed(Keys.Down)) {
|
|
|
|
if (textureIndex < textures.Count - 1) {
|
|
|
|
textureIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (input.IsKeyPressed(Keys.Up)) {
|
|
|
|
if (textureIndex > 0) {
|
|
|
|
textureIndex--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnLoad() {
|
|
|
|
base.OnLoad();
|
|
|
|
|
2023-07-07 05:44:51 +00:00
|
|
|
GL.ClearColor(0f, 0f, 0f, 1f);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
|
|
|
VertexArrayObject = GL.GenVertexArray();
|
|
|
|
GL.BindVertexArray(VertexArrayObject);
|
|
|
|
|
|
|
|
VertexBufferObject = GL.GenBuffer();
|
|
|
|
ElementBufferObject = GL.GenBuffer();
|
|
|
|
|
|
|
|
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
|
|
|
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw);
|
|
|
|
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
|
|
|
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.DynamicDraw);
|
|
|
|
|
2023-07-08 03:29:51 +00:00
|
|
|
shader.Init();
|
2023-06-30 02:10:24 +00:00
|
|
|
shader.Use();
|
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
// Because there's 5 floats between the start of the first vertex and the start of the second,
|
|
|
|
// the stride is 5 * sizeof(float).
|
2023-06-30 02:10:24 +00:00
|
|
|
// This will now pass the new vertex array to the buffer.
|
|
|
|
var vertexLocation = shader.GetAttribLocation("aPosition");
|
|
|
|
GL.EnableVertexAttribArray(vertexLocation);
|
|
|
|
GL.VertexAttribPointer(vertexLocation, 3, VertexAttribPointerType.Float, false, 5 * sizeof(float), 0);
|
|
|
|
|
|
|
|
// Next, we also setup texture coordinates. It works in much the same way.
|
|
|
|
// We add an offset of 3, since the texture coordinates comes after the position data.
|
|
|
|
// We also change the amount of data to 2 because there's only 2 floats for texture coordinates.
|
|
|
|
var texCoordLocation = shader.GetAttribLocation("aTexCoord");
|
|
|
|
GL.EnableVertexAttribArray(texCoordLocation);
|
|
|
|
GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float));
|
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
// Create a blank white texture.
|
2023-07-08 03:29:51 +00:00
|
|
|
|
2023-07-06 23:18:59 +00:00
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
// Load textures from JPEGs.
|
|
|
|
string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\06\27\");
|
|
|
|
foreach (string file in files) {
|
|
|
|
if (file.ToLower().EndsWith(".jpg")) {
|
2023-07-06 22:31:50 +00:00
|
|
|
Image<Rgba32> image = Image.Load<Rgba32>(file);
|
|
|
|
textures.Add(new Texture(image));
|
2023-06-30 02:10:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnUnload() {
|
|
|
|
base.OnUnload();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnRenderFrame(FrameEventArgs e) {
|
|
|
|
base.OnRenderFrame(e);
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
2023-07-07 01:26:50 +00:00
|
|
|
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
|
|
|
GL.ActiveTexture(TextureUnit.Texture0);
|
2023-06-30 02:10:24 +00:00
|
|
|
|
2023-06-30 02:52:52 +00:00
|
|
|
Texture active = textures[textureIndex];
|
|
|
|
|
2023-07-07 20:00:43 +00:00
|
|
|
// FIXME: make a function for scaling & centering one box on another.
|
|
|
|
double scaleX = 1.0 * geometry.PhotoBox.Size.X / active.Width;
|
|
|
|
double scaleY = 1.0 * geometry.PhotoBox.Size.Y / active.Height;
|
|
|
|
double scale = Math.Min(scaleX, scaleY);
|
|
|
|
int renderWidth = (int) (active.Width * scale);
|
|
|
|
int renderHeight = (int) (active.Height * scale);
|
|
|
|
Box2i photoBox = Util.makeBox((int) geometry.PhotoBox.Center.X - renderWidth / 2, (int) geometry.PhotoBox.Center.Y - renderHeight / 2, renderWidth, renderHeight);
|
|
|
|
DrawTexture(active, photoBox);
|
2023-06-30 02:10:24 +00:00
|
|
|
for (int i = 0; i < textures.Count; i++) {
|
2023-07-07 18:52:36 +00:00
|
|
|
Box2i box = geometry.ThumbnailBoxes[i];
|
2023-07-07 01:55:51 +00:00
|
|
|
DrawTexture(textures[i], box);
|
2023-07-07 01:26:50 +00:00
|
|
|
if (i == textureIndex) {
|
2023-07-07 06:33:01 +00:00
|
|
|
DrawBox(box, 5, Color4.Black);
|
|
|
|
DrawBox(box, 3, Color4.White);
|
2023-07-07 01:26:50 +00:00
|
|
|
}
|
2023-06-30 02:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SwapBuffers();
|
|
|
|
}
|
|
|
|
|
2023-07-07 03:48:12 +00:00
|
|
|
void DrawTexture(Texture texture, Box2i box) {
|
2023-07-07 03:36:55 +00:00
|
|
|
DrawTexture(texture, box, Color4.White);
|
2023-07-07 03:14:55 +00:00
|
|
|
}
|
|
|
|
|
2023-07-07 03:48:12 +00:00
|
|
|
void DrawTexture(Texture texture, Box2i box, Color4 color) {
|
2023-07-07 05:07:58 +00:00
|
|
|
GL.Uniform4(shader.GetUniformLocation("color"), color);
|
2023-07-07 03:48:12 +00:00
|
|
|
SetVertices(box.Min.X, box.Min.Y, box.Size.X, box.Size.Y);
|
2023-07-07 01:26:50 +00:00
|
|
|
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw);
|
|
|
|
GL.BindTexture(TextureTarget.Texture2D, texture.Handle);
|
|
|
|
GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);
|
|
|
|
}
|
|
|
|
|
2023-07-07 03:48:12 +00:00
|
|
|
void DrawBox(Box2i box, int thickness, Color4 color) {
|
2023-07-07 18:52:36 +00:00
|
|
|
DrawTexture(TEXTURE_WHITE, Util.makeBox(box.Min.X, box.Min.Y, box.Size.X, thickness), color);
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.makeBox(box.Min.X, box.Min.Y, thickness, box.Size.Y), color);
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.makeBox(box.Min.X, box.Max.Y - thickness, box.Size.X, thickness), color);
|
|
|
|
DrawTexture(TEXTURE_WHITE, Util.makeBox(box.Max.X - thickness, box.Min.Y, thickness, box.Size.Y), color);
|
2023-07-07 01:26:50 +00:00
|
|
|
}
|
|
|
|
|
2023-06-30 02:10:24 +00:00
|
|
|
protected override void OnResize(ResizeEventArgs e) {
|
|
|
|
base.OnResize(e);
|
|
|
|
Console.WriteLine($"OnResize: {e.Width}x{e.Height}");
|
|
|
|
|
2023-07-07 18:24:43 +00:00
|
|
|
geometry = new UiGeometry(e.Size);
|
|
|
|
|
|
|
|
projection = Matrix4.CreateOrthographicOffCenter(0f, e.Width, e.Height, 0f, -1f, 1f);
|
2023-06-30 02:10:24 +00:00
|
|
|
GL.UniformMatrix4(shader.GetUniformLocation("projection"), true, ref projection);
|
2023-07-07 18:24:43 +00:00
|
|
|
GL.Viewport(0, 0, e.Width, e.Height);
|
2023-06-30 02:10:24 +00:00
|
|
|
}
|
|
|
|
|
2023-06-30 02:57:38 +00:00
|
|
|
private void SetVertices(float left, float top, float width, float height) {
|
2023-06-30 02:10:24 +00:00
|
|
|
// top left
|
|
|
|
vertices[0] = left;
|
|
|
|
vertices[1] = top;
|
|
|
|
vertices[2] = 0f;
|
|
|
|
vertices[3] = 0f;
|
|
|
|
vertices[4] = 0f;
|
|
|
|
|
|
|
|
// top right
|
2023-06-30 02:57:38 +00:00
|
|
|
vertices[5] = left + width;
|
2023-06-30 02:10:24 +00:00
|
|
|
vertices[6] = top;
|
|
|
|
vertices[7] = 0f;
|
|
|
|
vertices[8] = 1f;
|
|
|
|
vertices[9] = 0f;
|
|
|
|
|
|
|
|
// bottom right
|
2023-06-30 02:57:38 +00:00
|
|
|
vertices[10] = left + width;
|
|
|
|
vertices[11] = top + height;
|
2023-06-30 02:10:24 +00:00
|
|
|
vertices[12] = 0f;
|
|
|
|
vertices[13] = 1f;
|
|
|
|
vertices[14] = 1f;
|
|
|
|
|
|
|
|
// bottom left
|
|
|
|
vertices[15] = left;
|
2023-06-30 02:57:38 +00:00
|
|
|
vertices[16] = top + height;
|
2023-06-30 02:10:24 +00:00
|
|
|
vertices[17] = 0f;
|
|
|
|
vertices[18] = 0f;
|
|
|
|
vertices[19] = 1f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static class Program {
|
|
|
|
static void Main(string[] args) {
|
|
|
|
List<MonitorInfo> monitors = Monitors.GetMonitors();
|
|
|
|
MonitorInfo bestMonitor = monitors[0];
|
|
|
|
int bestResolution = bestMonitor.HorizontalResolution * bestMonitor.VerticalResolution;
|
|
|
|
for (int i = 1; i < monitors.Count; i++) {
|
|
|
|
MonitorInfo monitor = monitors[i];
|
|
|
|
int resolution = monitor.HorizontalResolution * monitor.VerticalResolution;
|
|
|
|
if (resolution > bestResolution) {
|
|
|
|
bestResolution = resolution;
|
|
|
|
bestMonitor = monitor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Console.WriteLine($"best monitor: {bestMonitor.HorizontalResolution}x{bestMonitor.VerticalResolution}");
|
2023-07-07 18:52:36 +00:00
|
|
|
GameWindowSettings gwSettings = new();
|
2023-06-30 02:10:24 +00:00
|
|
|
gwSettings.RenderFrequency = 60.0;
|
|
|
|
|
2023-07-07 18:52:36 +00:00
|
|
|
NativeWindowSettings nwSettings = new();
|
2023-06-30 02:10:24 +00:00
|
|
|
nwSettings.WindowState = WindowState.Normal;
|
|
|
|
nwSettings.CurrentMonitor = bestMonitor.Handle;
|
|
|
|
nwSettings.Location = new Vector2i(bestMonitor.WorkArea.Min.X + 1, bestMonitor.WorkArea.Min.Y + 31);
|
|
|
|
nwSettings.Size = new Vector2i(bestMonitor.WorkArea.Size.X - 2, bestMonitor.WorkArea.Size.Y - 32);
|
2023-07-07 18:24:43 +00:00
|
|
|
nwSettings.MinimumSize = UiGeometry.MIN_WINDOW_SIZE;
|
2023-06-30 02:10:24 +00:00
|
|
|
nwSettings.Title = "Totte";
|
|
|
|
// FIXME: nwSettings.Icon = ...
|
|
|
|
|
|
|
|
using (Game game = new Game(gwSettings, nwSettings)) {
|
|
|
|
game.Run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|