add CameraInfo class; load textures from Image rather than a pathname

This commit is contained in:
Colin McMillen 2023-07-06 18:31:50 -04:00
parent 904726aba6
commit 855c97241b

View File

@ -15,6 +15,17 @@ using Image = SixLabors.ImageSharp.Image;
namespace SemiColinGames; namespace SemiColinGames;
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));
}
public class Shader : IDisposable { public class Shader : IDisposable {
int Handle; int Handle;
@ -128,8 +139,7 @@ public class Texture : IDisposable {
public int Width; public int Width;
public int Height; public int Height;
public Texture(string path) { public Texture(Image<Rgba32> image) {
Image<Rgba32> image = Image.Load<Rgba32>(path);
Width = image.Width; Width = image.Width;
Height = image.Height; Height = image.Height;
Console.WriteLine($"image loaded: {Width}x{Height}"); Console.WriteLine($"image loaded: {Width}x{Height}");
@ -178,6 +188,10 @@ public class Texture : IDisposable {
public class Game : GameWindow { public class Game : GameWindow {
public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) { } public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) { }
static CameraInfo activeCamera = CameraInfo.NIKON_D7000;
static int thumbnailHeight = 100;
static int thumbnailWidth = (int) 1.0 * thumbnailHeight * activeCamera.Resolution.X / activeCamera.Resolution.Y;
int frameCount; int frameCount;
int windowWidth; int windowWidth;
int windowHeight; int windowHeight;
@ -226,6 +240,8 @@ public class Game : GameWindow {
protected override void OnLoad() { protected override void OnLoad() {
base.OnLoad(); base.OnLoad();
Console.WriteLine($"thumbnail size: {thumbnailWidth}x{thumbnailHeight}");
GL.ClearColor(0.0f, 0.0f, 0.05f, 1.0f); GL.ClearColor(0.0f, 0.0f, 0.05f, 1.0f);
VertexArrayObject = GL.GenVertexArray(); VertexArrayObject = GL.GenVertexArray();
@ -261,7 +277,8 @@ public class Game : GameWindow {
textures = new List<Texture>(); textures = new List<Texture>();
foreach (string file in files) { foreach (string file in files) {
if (file.ToLower().EndsWith(".jpg")) { if (file.ToLower().EndsWith(".jpg")) {
textures.Add(new Texture(file)); Image<Rgba32> image = Image.Load<Rgba32>(file);
textures.Add(new Texture(image));
} }
} }
} }
@ -275,8 +292,6 @@ public class Game : GameWindow {
frameCount++; frameCount++;
GL.Clear(ClearBufferMask.ColorBufferBit); GL.Clear(ClearBufferMask.ColorBufferBit);
int thumbnailWidth = 150;
int thumbnailHeight = 100;
int borderWidth = 2; int borderWidth = 2;
int maxPhotoWidth = windowWidth - thumbnailWidth - borderWidth; int maxPhotoWidth = windowWidth - thumbnailWidth - borderWidth;