亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? textures.pas

?? 自己剛剛作的一個關于opengl的小離子
?? PAS
字號:
//----------------------------------------------------------------------------
//
// Author      : Jan Horn
// Email       : jhorn@global.co.za
// Website     : http://home.global.co.za/~jhorn
// Version     : 1.01
// Date        : 1 May 2001
// Description : A unit that used with OpenGL projects to load BMP, JPG and TGA
//               files from the disk or a resource file.
// Usage       : LoadTexture(Filename, TextureName, LoadFromResource);
//
//               eg : LoadTexture('logo.jpg', LogoTex, TRUE);
//                    will load a JPG texture from the resource included
//                    with the EXE. File has to be loaded into the Resource
//                    using this format  "logo JPEG logo.jpg"
//
//----------------------------------------------------------------------------
unit Textures;

interface

uses
  Windows, OpenGL, Graphics, Classes, JPEG, SysUtils;

function LoadTexture(Filename: String; var Texture: GLuint; LoadFromRes : Boolean): Boolean;

implementation


function gluBuild2DMipmaps(Target: GLenum; Components, Width, Height: GLint; Format, atype: GLenum; Data: Pointer): GLint; stdcall; external glu32;
procedure glGenTextures(n: GLsizei; var textures: GLuint); stdcall; external opengl32;
procedure glBindTexture(target: GLenum; texture: GLuint); stdcall; external opengl32;


{------------------------------------------------------------------}
{  Create the Texture                                              }
{------------------------------------------------------------------}
function CreateTexture(Width, Height, Format : Word; pData : Pointer) : Integer;
var
  Texture : GLuint;
begin
  glGenTextures(1, Texture);
  glBindTexture(GL_TEXTURE_2D, Texture);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);  {Texture blends with object background}
//  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);  {Texture does NOT blend with object background}

  { Select a filtering type. BiLinear filtering produces very good results with little performance impact
    GL_NEAREST               - Basic texture (grainy looking texture)
    GL_LINEAR                - BiLinear filtering
    GL_LINEAR_MIPMAP_NEAREST - Basic mipmapped texture
    GL_LINEAR_MIPMAP_LINEAR  - BiLinear Mipmapped texture
  }  

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); { only first two can be used }
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); { all of the above can be used }

  if Format = GL_RGBA then
    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pData)
  else
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData);
//  glTexImage2D(GL_TEXTURE_2D, 0, 3, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, pData);  // Use when not wanting mipmaps to be built by openGL

  result :=Texture;
end;


{------------------------------------------------------------------}
{  Load BMP textures                                               }
{------------------------------------------------------------------}
function LoadBMPTexture(Filename: String; var Texture : GLuint; LoadFromResource : Boolean) : Boolean;
var
  FileHeader: BITMAPFILEHEADER;
  InfoHeader: BITMAPINFOHEADER;
  Palette: array of RGBQUAD;
  BitmapFile: THandle;
  BitmapLength: LongWord;
  PaletteLength: LongWord;
  ReadBytes: LongWord;
  Front: ^Byte;
  Back: ^Byte;
  Temp: Byte;
  I : Integer;
  Width, Height : Integer;
  pData : Pointer;

  // used for loading from resource
  ResStream : TResourceStream;
begin
  result :=FALSE;

  if LoadFromResource then // Load from resource
  begin
    try
      ResStream := TResourceStream.Create(hInstance, PChar(copy(Filename, 1, Pos('.', Filename)-1)), 'BMP');
      ResStream.ReadBuffer(FileHeader, SizeOf(FileHeader));  // FileHeader
      ResStream.ReadBuffer(InfoHeader, SizeOf(InfoHeader));  // InfoHeader
      PaletteLength := InfoHeader.biClrUsed;
      SetLength(Palette, PaletteLength);
      ResStream.ReadBuffer(Palette, PaletteLength);          // Palette

      Width := InfoHeader.biWidth;
      Height := InfoHeader.biHeight;

      BitmapLength := InfoHeader.biSizeImage;
      if BitmapLength = 0 then
        BitmapLength := Width * Height * InfoHeader.biBitCount Div 8;

      GetMem(pData, BitmapLength);
      ResStream.ReadBuffer(pData^, BitmapLength);            // Bitmap Data
      ResStream.Free;
    except on
      EResNotFound do
      begin
        MessageBox(0, PChar('File not found in resource - ' + Filename), PChar('BMP Texture'), MB_OK);
        Exit;
      end
      else
      begin
        MessageBox(0, PChar('Unable to read from resource - ' + Filename), PChar('BMP Unit'), MB_OK);
        Exit;
      end;
    end;
  end
  else
  begin   // Load image from file
    BitmapFile := CreateFile(PChar(Filename), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
    if (BitmapFile = INVALID_HANDLE_VALUE) then begin
      MessageBox(0, PChar('Error opening ' + Filename), PChar('BMP Unit'), MB_OK);
      Exit;
    end;

    // Get header information
    ReadFile(BitmapFile, FileHeader, SizeOf(FileHeader), ReadBytes, nil);
    ReadFile(BitmapFile, InfoHeader, SizeOf(InfoHeader), ReadBytes, nil);

    // Get palette
    PaletteLength := InfoHeader.biClrUsed;
    SetLength(Palette, PaletteLength);
    ReadFile(BitmapFile, Palette, PaletteLength, ReadBytes, nil);
    if (ReadBytes <> PaletteLength) then begin
      MessageBox(0, PChar('Error reading palette'), PChar('BMP Unit'), MB_OK);
      Exit;
    end;

    Width  := InfoHeader.biWidth;
    Height := InfoHeader.biHeight;
    BitmapLength := InfoHeader.biSizeImage;
    if BitmapLength = 0 then
      BitmapLength := Width * Height * InfoHeader.biBitCount Div 8;

    // Get the actual pixel data
    GetMem(pData, BitmapLength);
    ReadFile(BitmapFile, pData^, BitmapLength, ReadBytes, nil);
    if (ReadBytes <> BitmapLength) then begin
      MessageBox(0, PChar('Error reading bitmap data'), PChar('BMP Unit'), MB_OK);
      Exit;
    end;
    CloseHandle(BitmapFile);
  end;

  // Bitmaps are stored BGR and not RGB, so swap the R and B bytes.
  for I :=0 to Width * Height - 1 do
  begin
    Front := Pointer(Integer(pData) + I*3);
    Back := Pointer(Integer(pData) + I*3 + 2);
    Temp := Front^;
    Front^ := Back^;
    Back^ := Temp;
  end;

  Texture :=CreateTexture(Width, Height, GL_RGB, pData);
  FreeMem(pData);
  result :=TRUE;
end;


{------------------------------------------------------------------}
{  Load JPEG textures                                              }
{------------------------------------------------------------------}
function LoadJPGTexture(Filename: String; var Texture: GLuint; LoadFromResource : Boolean): Boolean;
var
  Data : Array of LongWord;
  W, Width : Integer;
  H, Height : Integer;
  BMP : TBitmap;
  JPG : TJPEGImage;
  C : LongWord;
  Line : ^LongWord;
  ResStream : TResourceStream;      // used for loading from resource
begin
  result :=FALSE;
  JPG:=TJPEGImage.Create;

  if LoadFromResource then // Load from resource
  begin
    try
      ResStream := TResourceStream.Create(hInstance, PChar(copy(Filename, 1, Pos('.', Filename)-1)), 'JPEG');
      JPG.LoadFromStream(ResStream);
      ResStream.Free;
    except on
      EResNotFound do
      begin
        MessageBox(0, PChar('File not found in resource - ' + Filename), PChar('JPG Texture'), MB_OK);
        Exit;
      end
      else
      begin
        MessageBox(0, PChar('Couldn''t load JPG Resource - "'+ Filename +'"'), PChar('BMP Unit'), MB_OK);
        Exit;
      end;
    end;
  end
  else
  begin
    try
      JPG.LoadFromFile(Filename);
    except
      MessageBox(0, PChar('Couldn''t load JPG - "'+ Filename +'"'), PChar('BMP Unit'), MB_OK);
      Exit;
    end;
  end;

  // Create Bitmap
  BMP:=TBitmap.Create;
  BMP.pixelformat:=pf32bit;
  BMP.width:=JPG.width;
  BMP.height:=JPG.height;
  BMP.canvas.draw(0,0,JPG);        // Copy the JPEG onto the Bitmap

  //  BMP.SaveToFile('D:\test.bmp');
  Width :=BMP.Width;
  Height :=BMP.Height;
  SetLength(Data, Width*Height);

  For H:=0 to Height-1 do
  Begin
    Line :=BMP.scanline[Height-H-1];   // flip JPEG
    For W:=0 to Width-1 do
    Begin
      c:=Line^ and $FFFFFF; // Need to do a color swap
      Data[W+(H*Width)] :=(((c and $FF) shl 16)+(c shr 16)+(c and $FF00)) or $FF000000;  // 4 channel.
      inc(Line);
    End;
  End;

  BMP.free;
  JPG.free;

  Texture :=CreateTexture(Width, Height, GL_RGBA, addr(Data[0]));
  result :=TRUE;
end;


{------------------------------------------------------------------}
{  Loads 24 and 32bpp (alpha channel) TGA textures                 }
{------------------------------------------------------------------}
function LoadTGATexture(Filename: String; var Texture: GLuint; LoadFromResource : Boolean): Boolean;
var
  TGAHeader : packed record   // Header type for TGA images
    FileType     : Byte;
    ColorMapType : Byte;
    ImageType    : Byte;
    ColorMapSpec : Array[0..4] of Byte;
    OrigX  : Array [0..1] of Byte;
    OrigY  : Array [0..1] of Byte;
    Width  : Array [0..1] of Byte;
    Height : Array [0..1] of Byte;
    BPP    : Byte;
    ImageInfo : Byte;
  end;
  TGAFile   : File;
  bytesRead : Integer;
  image     : Pointer;    {or PRGBTRIPLE}
  Width, Height : Integer;
  ColorDepth    : Integer;
  ImageSize     : Integer;
  I : Integer;
  Front: ^Byte;
  Back: ^Byte;
  Temp: Byte;

  ResStream : TResourceStream;      // used for loading from resource
begin
  result :=FALSE;
  GetMem(Image, 0);
  if LoadFromResource then // Load from resource
  begin
    try
      ResStream := TResourceStream.Create(hInstance, PChar(copy(Filename, 1, Pos('.', Filename)-1)), 'TGA');
      ResStream.ReadBuffer(TGAHeader, SizeOf(TGAHeader));  // FileHeader
      result :=TRUE;
    except on
      EResNotFound do
      begin
        MessageBox(0, PChar('File not found in resource - ' + Filename), PChar('TGA Texture'), MB_OK);
        Exit;
      end
      else
      begin
        MessageBox(0, PChar('Unable to read from resource - ' + Filename), PChar('BMP Unit'), MB_OK);
        Exit;
      end;
    end;
  end
  else
  begin
    if FileExists(Filename) then
    begin
      AssignFile(TGAFile, Filename);
      Reset(TGAFile, 1);

      // Read in the bitmap file header
      BlockRead(TGAFile, TGAHeader, SizeOf(TGAHeader));
      result :=TRUE;
    end
    else
    begin
      MessageBox(0, PChar('File not found  - ' + Filename), PChar('TGA Texture'), MB_OK);
      Exit;
    end;
  end;

  if Result = TRUE then
  begin
    Result :=FALSE;

    // Only support uncompressed images
    if (TGAHeader.ImageType <> 2) then  { TGA_RGB }
    begin
      Result := False;
      CloseFile(tgaFile);
      MessageBox(0, PChar('Couldn''t load "'+ Filename +'". Compressed TGA files not supported.'), PChar('TGA File Error'), MB_OK);
      Exit;
    end;

    // Don't support colormapped files
    if TGAHeader.ColorMapType <> 0 then
    begin
      Result := False;
      CloseFile(TGAFile);
      MessageBox(0, PChar('Couldn''t load "'+ Filename +'". Colormapped TGA files not supported.'), PChar('TGA File Error'), MB_OK);
      Exit;
    end;

    // Get the width, height, and color depth
    Width  := TGAHeader.Width[0]  + TGAHeader.Width[1]  * 256;
    Height := TGAHeader.Height[0] + TGAHeader.Height[1] * 256;
    ColorDepth := TGAHeader.BPP;
    ImageSize  := Width*Height*(ColorDepth div 8);

    if ColorDepth <> 24 then
    begin
      Result := False;
      CloseFile(TGAFile);
      MessageBox(0, PChar('Couldn''t load "'+ Filename +'". Only 24 bit TGA files supported.'), PChar('TGA File Error'), MB_OK);
      Exit;
    end;

    GetMem(Image, ImageSize);

    if LoadFromResource then // Load from resource
    begin
      try
        ResStream.ReadBuffer(Image^, ImageSize);
        ResStream.Free;
      except
        MessageBox(0, PChar('Unable to read from resource - ' + Filename), PChar('BMP Unit'), MB_OK);
        Exit;
      end;
    end
    else         // Read in the image from file
    begin
      BlockRead(TGAFile, image^, ImageSize, bytesRead);
      if bytesRead <> ImageSize then
      begin
        Result := False;
        CloseFile(TGAFile);
        MessageBox(0, PChar('Couldn''t read file "'+ Filename +'".'), PChar('TGA File Error'), MB_OK);
        Exit;
      end;
    end;
  end;

  // TGAs are stored BGR and not RGB, so swap the R and B bytes.
  for I :=0 to Width * Height - 1 do
  begin
    Front := Pointer(Integer(Image) + I*3);
    Back := Pointer(Integer(Image) + I*3 + 2);
    Temp := Front^;
    Front^ := Back^;
    Back^ := Temp;
  end;

  Texture :=CreateTexture(Width, Height, GL_RGB, Image);
  Result :=TRUE;
  FreeMem(Image);
end;


{------------------------------------------------------------------}
{  Determines file type and sends to correct function              }
{------------------------------------------------------------------}
function LoadTexture(Filename: String; var Texture : GLuint; LoadFromRes : Boolean) : Boolean;
begin
  if copy(filename, length(filename)-3, 4) = '.bmp' then
    LoadBMPTexture(Filename, Texture, LoadFromRes);
  if copy(filename, length(filename)-3, 4) = '.jpg' then
    LoadJPGTexture(Filename, Texture, LoadFromRes);
  if copy(filename, length(filename)-3, 4) = '.tga' then
    LoadTGATexture(Filename, Texture, LoadFromRes);
end;


end.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
韩国毛片一区二区三区| 香蕉影视欧美成人| 欧美一区二区成人6969| 欧美影视一区在线| 欧美在线观看18| 欧美视频一区在线| 欧美日韩的一区二区| 欧美三级日韩在线| 欧美妇女性影城| 欧美成人免费网站| 久久精子c满五个校花| 日本一区二区三区四区| 欧美国产1区2区| 亚洲精品久久久蜜桃| 亚洲一区二区欧美激情| 美日韩一区二区三区| 国产一区二区美女| 不卡av在线免费观看| 欧美综合亚洲图片综合区| 91精品国产色综合久久不卡电影| 精品国产一区二区三区忘忧草 | 日韩精品电影在线| 蜜臀久久久99精品久久久久久| 国内精品国产三级国产a久久| 成人妖精视频yjsp地址| 色噜噜偷拍精品综合在线| 91精品国产欧美一区二区18 | 成人国产精品视频| 欧美日韩在线三区| 2021久久国产精品不只是精品| 国产人妖乱国产精品人妖| 一区二区三区久久| 波多野结衣中文字幕一区| 99v久久综合狠狠综合久久| 欧美日本在线播放| 欧美国产亚洲另类动漫| 亚洲一二三区不卡| 国产精品66部| 欧美巨大另类极品videosbest| 久久久亚洲国产美女国产盗摄| 亚洲精品视频一区| 国产一区二区成人久久免费影院| 97超碰欧美中文字幕| 日韩女优视频免费观看| 一区二区中文字幕在线| 激情综合色播激情啊| 欧美日韩精品一区二区三区四区| 国产性做久久久久久| 日韩国产成人精品| 色爱区综合激月婷婷| 国产日产欧美一区二区三区| 日一区二区三区| 色噜噜狠狠色综合欧洲selulu| 欧美v亚洲v综合ⅴ国产v| 亚洲一线二线三线久久久| 成人看片黄a免费看在线| 欧美成人免费网站| 日韩和欧美一区二区三区| 91亚洲精品乱码久久久久久蜜桃| 久久久久久久久岛国免费| 奇米一区二区三区av| 色婷婷久久99综合精品jk白丝 | 99v久久综合狠狠综合久久| 久久综合久久综合久久综合| 亚洲18女电影在线观看| 91免费视频网址| 亚洲欧洲精品天堂一级 | 亚洲bdsm女犯bdsm网站| 91蜜桃视频在线| 亚洲乱码中文字幕| 91同城在线观看| 亚洲欧美另类久久久精品| av中文字幕在线不卡| 亚洲午夜日本在线观看| 色一区在线观看| 亚洲激情第一区| 欧美日韩中字一区| 亚洲成av人片在线观看无码| 欧美亚洲禁片免费| 午夜精品久久久久久| 欧美日韩一级视频| 免费成人在线观看视频| 精品国产一区二区三区四区四 | 国产精品久久久久久久久快鸭 | 天使萌一区二区三区免费观看| 欧美色电影在线| 日韩精品每日更新| 日韩女优av电影在线观看| 国产麻豆成人传媒免费观看| 国产校园另类小说区| 色综合久久九月婷婷色综合| 亚洲午夜影视影院在线观看| 欧美一区二区福利在线| 国产大片一区二区| 亚洲欧美综合另类在线卡通| 色狠狠一区二区三区香蕉| 五月激情六月综合| 久久免费精品国产久精品久久久久| 国产麻豆91精品| 亚洲免费观看在线视频| 欧美一区二区精品在线| 国产成人精品免费| 一区二区三区四区不卡在线 | 亚洲精品伦理在线| 日韩视频免费观看高清在线视频| 国产精品一区二区久久精品爱涩| 国产精品麻豆久久久| 欧美色图第一页| 国产成人精品一区二| 一区二区三区四区蜜桃| 国产日产亚洲精品系列| 欧美性猛交xxxx黑人交| 久久精品国产77777蜜臀| 国产精品久久久久四虎| 日韩一区二区精品在线观看| fc2成人免费人成在线观看播放| 亚洲综合在线视频| 国产清纯美女被跳蛋高潮一区二区久久w| 波多野结衣欧美| 精品影院一区二区久久久| 亚洲日本青草视频在线怡红院| 欧美一区二区三区系列电影| 成人avav在线| 精品一区精品二区高清| 亚洲国产aⅴ成人精品无吗| 国产日韩欧美麻豆| 91精品啪在线观看国产60岁| 91免费看视频| 国产精品99久久久久久似苏梦涵 | 午夜久久福利影院| 中文字幕一区二区三区四区不卡| 日韩一区二区三区免费观看| 91麻豆.com| 99久久夜色精品国产网站| 国产一区二区三区免费观看| 午夜欧美在线一二页| 亚洲精品高清视频在线观看| 亚洲国产经典视频| 久久精品欧美一区二区三区不卡| 91精品国产福利| 51午夜精品国产| 欧美日韩精品二区第二页| 色老汉av一区二区三区| 99r国产精品| proumb性欧美在线观看| 懂色av中文字幕一区二区三区| 六月丁香综合在线视频| 日本在线不卡视频| 天天影视涩香欲综合网| 亚洲大型综合色站| 亚洲国产视频在线| 亚瑟在线精品视频| 首页国产丝袜综合| 午夜电影一区二区三区| 亚洲国产成人91porn| 一区二区三区日韩精品| 一区二区三区四区在线免费观看| 一区二区高清免费观看影视大全 | 欧美一二三区精品| 日韩色视频在线观看| 精品剧情v国产在线观看在线| 日韩免费视频一区| 久久久精品人体av艺术| 国产日韩欧美综合一区| 国产精品久久久久婷婷| 亚洲精品成人精品456| 亚洲成人免费视| 美女视频网站黄色亚洲| 国内国产精品久久| 成人福利视频在线| 色综合久久66| 91精品欧美福利在线观看| 精品国产成人系列| 中文字幕中文字幕中文字幕亚洲无线| 国产精品情趣视频| 亚洲二区视频在线| 久久成人av少妇免费| 不卡免费追剧大全电视剧网站| 在线免费一区三区| 欧美一区二区三区在线电影| 国产午夜精品福利| 亚洲美女屁股眼交| 蜜桃av一区二区三区| 成人精品国产一区二区4080| 日韩欧美一区二区免费| 国产欧美日本一区视频| 一区二区三区在线观看网站| 青青草视频一区| 不卡的av在线| 欧美变态凌虐bdsm| 亚洲欧美日韩国产另类专区| 蜜桃在线一区二区三区| av不卡在线播放| 日韩一区二区免费视频| 亚洲精品自拍动漫在线| 国产成人综合在线播放| 欧美日韩高清影院| 成人欧美一区二区三区黑人麻豆| 奇米色777欧美一区二区| av成人老司机|