- type
 - PGLRGBQUAD = ^TGLRGBQUAD;
 - TGLRGBQUAD = record
 - red: Byte;
 - green: Byte;
 - blue: Byte;
 - alpha: Byte;
 - end;
 - TGLJpg = record
 - TexID: GLuint;
 - Width: integer;
 - Height: integer;
 - ImageData: PGLRGBQUAD;
 - end;
 - var
 - Background: Array[0..7, 0..5] of TGLJpg;
 - procedure LoadBackground(RoomID: integer);
 - const
 - GL_BGRA = $80E1;
 - var
 - Bmp: TBitmap;
 - Jpg: TJPEGImage;
 - Header: PBitmapInfo;
 - minFilter: TGLInt; // Texture minification filter
 - magFilter: TGLInt; // Texture magnification filter
 - texWrapS: TGLInt; // Texture wrapping in s direction
 - texWrapT: TGLInt; // Texture wrapping in t direction
 - begin
 - if FileExists(ExtractFilePath(Application.ExeName) + 'room_' + IntToStr(RoomID) + '.jpg') then
 - begin
 - // cut / Prepare filters (the one's with TGLInt)
 - // cut / Load picture from file (tested and 100% working) and Draw on Bmp Canvas
 - // Split (not yet done. Store everything in first pic)
 - Background[0, 0].Width := Bmp.Width;
 - Background[0, 0].Height := Bmp.Height;
 - // Prepare GetDIBits
 - GetMem(Header, SizeOf(TBitmapInfoHeader));
 - with Header^.bmiHeader do
 - begin
 - biSize := SizeOf(TBitmapInfoHeader);
 - biWidth := Background[0, 0].Width;
 - biHeight := Background[0, 0].Height;
 - biPlanes := 1;
 - biBitCount := 32;
 - biCompression := BI_RGB;
 - biSizeImage := Background[0, 0].Width * Background[0, 0].Height * 4;
 - end;
 - GetDIBits(Bmp.Canvas.Handle, Bmp.Handle, 0, Background[0, 0].Height, Background[0, 0].ImageData, TBitmapInfo(Header^), DIB_RGB_COLORS);
 - // GetDIBits returns 512, what is correct. But Background[0, 0].ImageData still contains no data...why?
 - SetAlpha(255); // sets alpha channel and gives an exception (that's why Background[0, 0].ImageData is nil
 - // Free up memory
 - FreeMem(Header);
 - Jpg.Free;
 - Bmp.Free;
 - // Generate the texture
 - if Background[0, 0].TexID > 0 then glDeleteTextures(1, Background[0, 0].TexID);
 - glGenTextures(1, Background[0, 0].TexID);
 - glBindTexture(GL_TEXTURE_2D, Background[0, 0].TexID);
 - // Set up parameters
 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texWrapS);
 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texWrapT);
 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
 - // won't work with no image data...
 - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Background[0, 0].Width, Background[0, 0].Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, Background[0, 0].ImageData);
 - // gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Background[0, 0].Width, Background[0, 0].Height, GL_BGRA, GL_UNSIGNED_BYTE, PByte(Background[0, 0].ImageData));
 - end;
 - end;
 

