Load your image with .NET API, use the LockBits function to access the raw data image (LockBits give you BitmapData and use Scan0 to get the pointer to the raw data.)
It’s a bit some work, but it works fine (Image class loads PNG, Jpeg, BMP, GIF )
Meanwhile i’ve made some progress using textureBitmap class, although i loose quality, because afterwords i build a mipmap:
Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, //target
3, //internal format : RGB so 3 components textureBitmap.Width, //image size
textureBitmap.Height,
Gl.GL_RGB, //fomat : RGB
Gl.GL_UNSIGNED_BYTE,
bitmapdata.Scan0);//picture represented as a byte array
I tried to build a texImage2D, but the result was blank:
// Gl.glTexImage2D(Gl.GL_TEXTURE_2D, //Target
0, //level
Gl.GL_RGB,//internalFormat
textureBitmap.Width, //Width
textureBitmap.Height, //Height
0, //border
Gl.GL_BGR, //Format
Gl.GL_BITMAP, //Type
bitmapdata.Stexelscan0);
I’ll try with Image class, but i think that my loss of quality is due to the mipMap2D.
rescale a Non-Power-of-Two texture to the nearest smaller Power-Of-Two (quite ugly rescale btw)
fill all mipmaps levels with rescaled version of texture (4 pixels averaged to 1)
to solve 2) :
use glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE ); on your texture. Most hardware support this extension.
or don’t use mipmaps :
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
to solve 1), either do it offline with a good image program (Gimp,Photoshop…) or take advantage of modern hardware able to use NPOT textures (not so common, so I don’t recommend it)