private TexImage2D ( uint target, int level, uint internalformat, int width, int height, int border, uint format, uint type, IntPtr pixels ) : void | ||
target | uint | |
level | int | |
internalformat | uint | |
width | int | |
height | int | |
border | int | |
format | uint | |
type | uint | |
pixels | IntPtr | |
return | void |
private void InitTexture(Bitmap bitmap) { #if DEBUG var filename = string.Format("FontResource{0:yyyy-MM-dd_HH-mm-ss.ff}FontResource.log.bmp", DateTime.Now); bitmap.Save(filename); #endif // generate texture. // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); //GL.ActiveTexture(GL.GL_TEXTURE0); OpenGL.GetDelegateFor <OpenGL.glActiveTexture>()(OpenGL.GL_TEXTURE0); var ids = new uint[1]; OpenGL.GenTextures(1, ids); OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, ids[0]); /* Clamping to edges is important to prevent artifacts when scaling */ /* We require 1 byte alignment when uploading texture data */ //GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR); OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE); OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE); /* Linear filtering usually looks best for text */ OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR); OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RED, bitmap.Width, bitmap.Height, 0, OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); // Unlock the image. bitmap.UnlockBits(bitmapData); OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, 0); this.TextureSize = bitmap.Size; this.FontTextureId = ids[0]; }
/// <summary> /// upadte texture's content. /// </summary> /// <param name="texture"></param> /// <param name="bitmap"></param> public static void UpdateContent(this Texture texture, Bitmap bitmap) { // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); OpenGL.BindTexture((uint)texture.Target, texture.Id); if (texture.Target == TextureTarget.Texture1D) { OpenGL.TexImage1D((uint)texture.Target, 0, (int)OpenGL.GL_RGBA, bitmapData.Width, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); } else if (texture.Target == TextureTarget.Texture2D) { OpenGL.TexImage2D((uint)texture.Target, 0, (int)OpenGL.GL_RGBA, bitmapData.Width, bitmapData.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); } else { throw new NotImplementedException(); } OpenGL.BindTexture((uint)texture.Target, 0); // Unlock the image. bitmap.UnlockBits(bitmapData); //// TODO: TexSubImage2D() do not work. why? //BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), // ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); //OpenGL.BindTexture(this.Target, this.Id); //OpenGL.TexSubImage2D(this.Target, 0, 0, 0, bitmap.Width, bitmap.Height, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); //OpenGL.TexSubImage2D(TexSubImage2DTarget.Texture2D, 0, 0, 0, bitmap.Width, bitmap.Height, TexSubImage2DFormats.RGBA, TexSubImage2DType.UnsignedByte, bitmapData.Scan0); //OpenGL.BindTexture(this.Target, 0); //bitmap.UnlockBits(bitmapData); }
private void DoInitialize(System.Drawing.Bitmap bitmap) { // generate texture. // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); //GL.ActiveTexture(GL.GL_TEXTURE0); OpenGL.GetDelegateFor <OpenGL.glActiveTexture>()(OpenGL.GL_TEXTURE0); OpenGL.GenTextures(1, id); OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, id[0]); /* We require 1 byte alignment when uploading texture data */ //GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); /* Clamping to edges is important to prevent artifacts when scaling */ OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE); OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE); /* Linear filtering usually looks best for text */ OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR); OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR); OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA, bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); // Unlock the image. bitmap.UnlockBits(bitmapData); OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, 0); }
/// <summary> /// /// </summary> public override void Fill() { OpenGL.TexImage2D((uint)TextureTarget.Texture2D, 0, internalFormat, // OpenGL.GL_RGBA, width, height, 0, this.format, // OpenGL.GL_RGBA, this.type, // OpenGL.GL_UNSIGNED_BYTE, IntPtr.Zero); }
/// <summary> /// build texture's content with Bitmap. /// </summary> public override void Fill() { foreach (Tuple <uint, Bitmap> item in this.images) { uint target = item.Item1; Bitmap image = item.Item2; // generate texture. // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); OpenGL.TexImage2D(target, 0, this.internalformat, image.Width, image.Height, 0, this.format, this.type, bitmapData.Scan0); // Unlock the image. image.UnlockBits(bitmapData); } }
public void setFormat(uint internalfmt, int width, int height, uint format, bool mipmap, bool interpol) { m_width = width; m_height = height; m_internalfmt = internalfmt; m_fmt = format; m_mipmap = mipmap; m_interpol = interpol; m_texture_target = OpenGL.GL_TEXTURE_2D; OpenGL.GenTextures(1, m_texture_id); OpenGL.BindTexture(m_texture_target, m_texture_id[0]); OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_CLAMP_TO_EDGE); OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_CLAMP_TO_EDGE); if (mipmap) { OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR); OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR_MIPMAP_LINEAR); OpenGL.TexParameterf(m_texture_target, OpenGL.GL_GENERATE_MIPMAP, OpenGL.GL_TRUE); } else { if (interpol) { OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR); OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR); } else { OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_NEAREST); OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_NEAREST); } OpenGL.TexParameteri(m_texture_target, OpenGL.GL_GENERATE_MIPMAP, (int)OpenGL.GL_FALSE); } OpenGL.TexImage2D(m_texture_target, 0, internalfmt, width, height, 0, format, OpenGL.GL_UNSIGNED_BYTE, IntPtr.Zero); OpenGL.BindTexture(m_texture_target, 0); }
/// <summary> /// build texture's content with Bitmap. /// </summary> public override void Fill() { // generate texture. // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); if (target == TextureTarget.Texture1D) { OpenGL.TexImage1D((uint)target, 0, this.internalformat, bitmap.Width, 0, this.format, this.type, bitmapData.Scan0); } else if (target == TextureTarget.Texture2D) { OpenGL.TexImage2D((uint)target, 0, this.internalformat, bitmap.Width, bitmap.Height, 0, this.format, this.type, bitmapData.Scan0); } else { throw new NotImplementedException(); } // Unlock the image. bitmap.UnlockBits(bitmapData); }
/// <summary> /// build texture's content with Bitmap. /// </summary> public override void Build(BindTextureTarget target) { // generate texture. // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); if (target == BindTextureTarget.Texture1D) { OpenGL.TexImage1D((uint)target, 0, (int)OpenGL.GL_RGBA, bitmap.Width, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); } else if (target == BindTextureTarget.Texture2D) { OpenGL.TexImage2D((uint)target, 0, (int)OpenGL.GL_RGBA, bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); } else { throw new NotImplementedException(); } // Unlock the image. bitmap.UnlockBits(bitmapData); }
/// <summary> /// build texture's content with Bitmap. /// </summary> public override void Fill() { // generate texture. if (target == TextureTarget.Texture1D) { Bitmap bmp = null; for (int level = 0; level <= this.maxLevel; level++) { if (level == 0) { bmp = this.bitmap; } else { bmp.Dispose(); int width = bmp.Width / 2; if (width < 1) { width = 1; } bmp = new Bitmap(bmp, width, 1); } // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); OpenGL.TexImage1D((uint)target, level, this.internalformat, bitmap.Width, 0, this.format, this.type, bitmapData.Scan0); // Unlock the image. bmp.UnlockBits(bitmapData); } if (bmp != this.bitmap) { bmp.Dispose(); } } else if (target == TextureTarget.Texture2D) { Bitmap bmp = null; for (int level = 0; level <= this.maxLevel; level++) { if (level == 0) { bmp = this.bitmap; } else { bmp.Dispose(); int width = bmp.Width / 2, height = bmp.Height / 2; if (width < 1) { width = 1; } if (height < 1) { height = 1; } bmp = new Bitmap(bmp, width, height); } // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); OpenGL.TexImage2D((uint)target, level, this.internalformat, bmp.Width, bmp.Height, 0, this.format, this.type, bitmapData.Scan0); // Unlock the image. bmp.UnlockBits(bitmapData); } if (bmp != this.bitmap) { bmp.Dispose(); } } else { throw new Exception("Unexpected TextureTarget type!"); } }