1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
public static uint LoadTexture(String fileName)
{
BitmapData bData = new BitmapData();
Bitmap textureBMP;
try
{
textureBMP = new Bitmap(fileName);
}
catch (ArgumentException)
{
return 0;
}
// Obtenir l'adresse du tampons de l'image
Rectangle rect = new Rectangle(0, 0, textureBMP.Width, textureBMP.Height);
bData = textureBMP.LockBits(rect,ImageLockMode.ReadOnly,textureBMP.PixelFormat);
textureBMP.UnlockBits(bData);
// Passer de BGR à RGB ( Inverser les couleurs )
Color temp;
Color newColor;
for (int y = 0; y < textureBMP.Height; y++)
for (int x = 0; x < textureBMP.Width; x++)
{
temp = textureBMP.GetPixel(x, y);
newColor = Color.FromArgb(temp.B,temp.G,temp.R);
textureBMP.SetPixel(x, y, newColor);
}
// Affecter la texture
uint[] texture = new uint[1];
GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);
GL.glGenTextures(1, texture);
GL.glBindTexture(GL.GL_TEXTURE_2D, texture[0]);
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB, textureBMP.Width, textureBMP.Height, 0, GL.GL_RGB, GL.GL_UNSIGNED_byte, bData.Scan0);
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
return texture[0];
} |
Partager