Hi all,
Here is a really straight forward way of loading OpenGL textures. It
seems simpler than how it is currently being done in the various
examples and such.
-----
// convert bitmap to be square because OpenGL likes that
Bitmap bitmapSquare = new Bitmap( bitmap, 256, 256 );
// get the size of the bitmap
// in this case it will be (0,0,256,256)
Rectangle rect = new Rectangle(
0, 0, bitmapSquare.Width, bitmapSquare.Height );
// request the bitmap's data in a particular pixel format.
// this function is nice because it will automatically
// convert the bitmap data into whatever format you request.
// (in this case 32bit RGBA data)
BitmapData bitmapdata = bitmapSquare.LockBits(
rect,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb );
// set the OpenGL texture map data
GL.glTexImage2D(
GL.GL_TEXTURE_2D,
0,
(int) GL.GL_RGB8,
bitmapdata.Width,
bitmapdata.Height,
0,
GL.GL_BGRA_EXT,
GL.GL_UNSIGNED_BYTE,
bitmapdata.Scan0 );
// unlock the bitmap since we are done with it
bitmapSquare.UnlockBits( bitmapdata );
-----
I recommend doing away with the class 'PreTexture2D' since I don't think
that it is really needed.
All the best,
-ben houston
4th Year Cognitive Science/Neuroscience
Carleton University, Ottawa, Canada
( be...@ex... / 613-266-0637 )
|