I'm perplexing to bucket a PNG with OpenGL (via OpenTK) and a Image is
severely pixelated and has a wrong color.The code:private vacant
Create(SurfaceFormat format) { textureHandle =
(uint)GL.GenTexture(); //bind hardness
GL.BindTexture(TextureTarget.Texture2D, textureHandle);
Log.Error("Bound Texture: " + GL.GetError());
GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureWrapS, (int)format.WrapMode);
GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureWrapT, (int)format.WrapMode);
Log.Error("Created Texture Parameters: " + GL.GetError());
GL.TexImage2D(TextureTarget.Texture2D, 0, format.InternalFormat, Width,
Height, 0, format.PixelFormat, format.SourceType, format.Pixels);
Log.Error("Created Image: " + GL.GetError()); //unbind
hardness GL.BindTexture(TextureTarget.Texture2D, 0);
//create fbo fboHandle = (uint)GL.GenFramebuffer();
GL.BindFramebuffer(FramebufferTarget.Framebuffer, fboHandle);
GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt,
FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D,
textureHandle, 0);
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
Log.Error("Created Framebuffer: " + GL.GetError()); } open
vacant CreateFromPNG(string filePath) { //check if a
record exists if (System.IO.File.Exists(filePath)) {
//make a bitmap out of a record on a hoop
System.Drawing.Bitmap textureBitmap = new System.Drawing.Bitmap(filePath);
//get a information out of a bitmap
System.Drawing.Imaging.BitmapData textureData =
textureBitmap.LockBits( new
System.Drawing.Rectangle(0, 0, textureBitmap.Width, textureBitmap.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format32bppArgb
); if(textureBitmap.PixelFormat !=
System.Drawing.Imaging.PixelFormat.Format32bppArgb) {
Log.Error("PNG Pixel format not upheld ("+ filePath +") -> "
+ textureBitmap.PixelFormat.ToString()); return;
} SurfaceFormat format = new SurfaceFormat();
format.Pixels = textureData.Scan0;
format.SourceType = PixelType.Byte; Create(format);
//free a bitmap information (we dont need it anymore since it has
been upheld to a OpenGL engineer
textureBitmap.UnlockBits(textureData); } }What am we
doing wrong here?EDIT: we bound a colors viaformat.SourceType =
PixelType.UnsignedByte;format.PixelFormat = PixelFormat.Bgra;But a
duplicity is still going on
No comments:
Post a Comment