mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-22 18:35:30 +00:00
40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using OpenTK;
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
namespace PckStudio.Rendering.Texture
|
|
{
|
|
public class Texture2D : Texture
|
|
{
|
|
public Texture2D() : base(TextureTarget.Texture2D)
|
|
{
|
|
}
|
|
|
|
public void SetSize(Size size)
|
|
{
|
|
Bind();
|
|
GL.TexImage2D(TextureTarget.Texture2D, 0, InternalPixelFormat, size.Width, size.Height, 0, PixelFormat, PixelType.UnsignedByte, IntPtr.Zero);
|
|
Unbind();
|
|
}
|
|
|
|
public override void SetTexture(Image image)
|
|
{
|
|
Bind();
|
|
var bitmap = new Bitmap(image);
|
|
BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
GL.TexImage2D(TextureTarget.Texture2D, 0, InternalPixelFormat, bitmap.Width, bitmap.Height, 0, PixelFormat, PixelType.UnsignedByte, data.Scan0);
|
|
bitmap.UnlockBits(data);
|
|
Unbind();
|
|
}
|
|
|
|
public void AttachToFramebuffer(FrameBuffer frameBuffer, FramebufferAttachment attachment)
|
|
{
|
|
frameBuffer.Bind();
|
|
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachment, Target, _GL_Id, 0);
|
|
}
|
|
}
|
|
}
|