- function BMPToGL(FileName: String): gluInt;
- var
- Bild: TBitmap;
- Size: Integer; //In Byte
- PTexture, PStart: Pointer;
- x, y: Integer;
- r, g, b: Byte;
- Texture: GLuInt;
- begin
- Bild := TBitmap.Create;
- Bild.LoadFromFile(FileName);
- //Speicher berechnen...
- Size := Bild.Width*Bild.Height*3;
- //und reservieren:
- GetMem(PTexture, Size);
- PStart := PTexture;
- //Bildinfos in den Speicher schreiben:
- For y := 1 to Bild.Height do
- For x := 1 to Bild.Width do
- begin
- r := Bild.Canvas.Pixels[x,y] and 3;
- g := (Bild.Canvas.Pixels[x,y] shr 2) and 3;
- b := (Bild.Canvas.Pixels[x,y] shr 4) and 3;
- Byte(PTexture^) := r;
- Cardinal(PTexture) := Cardinal(PTexture) + 1;
- Byte(PTexture^) := g;
- Cardinal(PTexture) := Cardinal(PTexture) + 1;
- Byte(PTexture^) := b;
- Cardinal(PTexture) := Cardinal(PTexture) + 1;
- end;
- PTexture := PStart;
- //Bildinfos OpenGL übergeben;
- glGenTextures(1, @Texture);
- glBindTexture(GL_TEXTURE_2D, Texture);
- glTexImage2D(GL_TEXTURE_2D, 0, 3, Bild.Width, Bild.Height, 0, GL_RGB, GL_UNSIGNED_BYTE, PTexture);
- FreeMem(PTexture);
- Bild.Free;
- Result := Texture;
- end;