After loading the image with the help of ImageSharp and then loading it into vram it renders just a white quad. I basicly have no clue what i could have done wrong, this is the first time working with opentk crossplatform not beeing abel to use BitmapData
.
Texture class:
public struct Texture2D
{
public readonly int Handle;
public readonly int Width;
public readonly int Height;
public Texture2D(int[] data, int width, int height)
{
Width = width;
Height = height;
GL.Enable(EnableCap.Texture2D);
GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
Handle = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, Handle);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
unsafe
{
fixed (int* dataptr = data)
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Width, Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, (IntPtr)dataptr);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
GL.Disable(EnableCap.Texture2D);
}
public static implicit operator int(Texture2D texture) => texture.Handle;
public static Texture2D FromFile(string file) => FromImage(Image.Load(Path.Combine("resources", file)));
public static Texture2D FromImage(Image<Rgba32> image)
{
var xL = image.Width;
var yL = image.Height;
var data = new int[image.Width * image.Height];
for (var x = 0; x < xL; x++)
for (var y = 0; y < yL; y++)
data[y * xL + x] = image[x, y].R << 24 | image[x, y].G << 16 | image[x, y].B << 8 | image[x, y].A;
return new Texture2D(data, image.Width, image.Height);
}
}
Rendering:
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.PushMatrix();
GL.Begin(PrimitiveType.Quads);
{
GL.BindTexture(TextureTarget.ProxyTexture2D, loadingTex.Handle);
var x = app.Width - loadingTex.Width;
var x2 = app.Width;
var y = 0;
var y2 = loadingTex.Height;
GL.TexCoord2(0, 0);
GL.Vertex2(x, 0);
GL.TexCoord2(0, 1);
GL.Vertex2(x2, 0);
GL.TexCoord2(1, 1);
GL.Vertex2(x2, y2);
GL.TexCoord2(1, 0);
GL.Vertex2(x, loadingTex.Height);
}
GL.End();
GL.PopMatrix();
GL.Flush();
SwapBuffers();
loadingTex
is a static variable referencing a Texture