const
IID_IPicture : TGUID = '{7BF80980-BF32-101A-8BBB-00AA00300CAB}';
function OleLoadPicturePath(szURLorPath: POleStr; unkCaller: IUnknown;
dwReserved: Longint; clrReserved: TOleColor;
const iid: TIID; ppvRet: Pointer): HResult; stdcall; external 'oleaut32.dll';
//----------------------------------------------------------
function LoadBMP(FileName : PChar; idTex : GLUINT) : Boolean;
var
F : THandle;
DC, MemDC : HDC;
bmp : HBITMAP;
pPicture : IPicture;
wszPath : array[0..MAX_PATH + 1] of TOleChar; // Full Path To Picture (WCHAR)
Width, aWidth,
Height, aHeight : Integer;
MaxSize : GLint;
BI : PBITMAPINFO;
pBits : Pointer;
begin
Result := False;
if FileName = #0 then
Exit;
F := CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if F <> 0 then
begin
CloseHandle(F);
MultiByteToWideChar(CP_ACP, 0, FileName, -1, wszPath, MAX_PATH);
if OleLoadPicturePath(wszPath, NIL, 0, 0, IID_IPicture, @pPicture) <> S_OK then
Exit;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxSize);
DC := GetDC(0);
MemDC := CreateCompatibleDC(DC);
try
if MemDC = 0 then
Exit;
pPicture.get_Width(aWidth);
pPicture.get_Height(aHeight);
Width := MulDiv(aWidth, GetDeviceCaps(DC, LOGPIXELSX), 2540);
Height := MulDiv(aHeight, GetDeviceCaps(DC, LOGPIXELSY), 2540);
if Width <= MaxSize then
Width := 1 shl Floor((Ln(Width) / Ln(2.0)) + 0.5)
else
Width := MaxSize;
if Height <= MaxSize then
Height := 1 shl Floor((Ln(Height) / Ln(2.0)) + 0.5)
else
Height := MaxSize;
GetMem(BI, SizeOf(TBitmapInfo));
try
pBits := NIL;
FillChar(BI^, SizeOf(TBITMAPINFO), 0);
with BI^.bmiHeader do
begin
biSize := SizeOf(TBITMAPINFOHEADER);
biBitCount := 24;
biWidth := Width;
biHeight := Height;
biCompression := BI_RGB;
biPlanes := 1;
end;
bmp := CreateDIBSection(MemDC, BI^, DIB_RGB_COLORS, pBits, 0, 0);
try
if bmp = 0 then
Exit;
SelectObject(MemDC, bmp);
pPicture.Render(MemDC, 0, 0, Width, Height, 0, aHeight, aWidth, -aHeight, TRect(NIL^));
GetDIBits(MemDC, bmp, 0, BI^.bmiHeader.biHeight, NIL, TBitmapInfo(BI^), DIB_RGB_COLORS);
glBindTexture(GL_TEXTURE_2D, idTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE_EXT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE_EXT);
glTexImage2d(GL_TEXTURE_2D, 0, 3, Width, Height, 0, GL_BGR, GL_UNSIGNED_BYTE, pBits);
// gluBuild2dMipmaps(GL_TEXTURE_2D, 3, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pBits);
// gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Width, Height, GL_BGR, GL_UNSIGNED_BYTE, pBits);
finally
if bmp <> 0 then
DeleteObject(bmp);
end;
finally
FreeMem(BI, SizeOf(TBitmapInfo));
end;
finally
if MemDC <> 0 then
DeleteDC(MemDC);
if DC <> 0 then
ReleaseDC(0, DC);
end;
end;
Result := True;
end;
for i := 0 to 5 do
LoadBmp(PAnsiChar(LocalPath + 'TextureCube\' + cubemap[i]), texList[i]);
for i := 0 to countbann - 1 do
LoadBmp(PAnsiChar(PathList[i]), texList[i + 7]);