From: Lloyd D. <ll...@ga...> - 2001-10-29 21:07:37
|
i am currently in the process of finishing a new OpenGL font class. there is actually 3 examples font class. and i discover a bug in the bitmap/texture loading process. Bitmap img = new Bitmap("image file"); // ... BitmapData tex = img.LockBits(/*some param*/); tex.Scan0 seems to begin in the upper left corner and not in the lower left corner, as needed by glTexImage2D.... for this you should call img.RotateFlip(RotateFlipType.RotateNoneFlipY); before locking data. i will try to provide an OpenGLTexture utility object, as exemple, though i lack idea (and practice) here, as you could have multiple texture for multiple scale and different filtering for each texture. so i copy/paste here my current (and basic) OpenGLTexture object and wait for your critics..... ------------ OpenGLTexture --------------- using System; using System.Drawing; using System.Drawing.Imaging; namespace CsGL.OpenGL { /// <summary> /// load a texture from an image, though a simple topic /// there is problem of reverse order and such things which are handled /// byt this class. /// </summary> public abstract class OpenGLTexture : GL, IDisposable { uint[] texture = new uint[1]; public OpenGLTexture(Bitmap img) { img = (Bitmap) img.Clone(); img.RotateFlip(RotateFlipType.RotateNoneFlipY); BitmapData tex; Rectangle rect; rect = new Rectangle(0, 0, img.Width, img.Height); tex = img.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); glGenTextures(texture.Length, texture); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, (int)GL_RGB8, img.Width, img.Height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, tex.Scan0); img.UnlockBits(tex); img.Dispose(); } public uint this[int texID] { get { return texture[texID]; } } public int Length { get { return texture.Length; } } public void Dispose() { glDeleteTextures(texture.Length, texture); } } } |