18.09.2020
+ Textures ~ Changed 2D coordnate system to lower right as XY+
This commit is contained in:
parent
589d131246
commit
a603ecc417
26 changed files with 267 additions and 16 deletions
51
SMCode/SM.Base/Textures/Texture.cs
Normal file
51
SMCode/SM.Base/Textures/Texture.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.OGL.Texture;
|
||||
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
||||
|
||||
namespace SM.Base.Textures
|
||||
{
|
||||
public class Texture : TextureBase
|
||||
{
|
||||
public Bitmap Map;
|
||||
|
||||
public Texture(Bitmap map) : this(map, TextureMinFilter.Linear, TextureWrapMode.Repeat) {}
|
||||
|
||||
public Texture(Bitmap map, TextureMinFilter filter, TextureWrapMode wrapMode)
|
||||
{
|
||||
Map = map;
|
||||
Filter = filter;
|
||||
WrapMode = wrapMode;
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
base.Compile();
|
||||
|
||||
_id = GL.GenTexture();
|
||||
GL.BindTexture(TextureTarget.Texture2D, _id);
|
||||
|
||||
BitmapData data = Map.LockBits(new Rectangle(0, 0, Map.Width, Map.Height), ImageLockMode.ReadOnly,
|
||||
Map.PixelFormat);
|
||||
|
||||
bool transparenz = Map.PixelFormat == PixelFormat.Format32bppArgb;
|
||||
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0,
|
||||
transparenz ? PixelInternalFormat.Rgba : PixelInternalFormat.Rgb,
|
||||
data.Width, data.Height, 0,
|
||||
transparenz ? OpenTK.Graphics.OpenGL4.PixelFormat.Bgra : OpenTK.Graphics.OpenGL4.PixelFormat.Bgr,
|
||||
PixelType.UnsignedByte, data.Scan0);
|
||||
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)Filter);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)Filter);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) WrapMode);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) WrapMode);
|
||||
|
||||
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
Map.UnlockBits(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue