| @@ -40,15 +40,17 @@ end; | |||
| begin | |||
| oglWindow := CreateOpenGLWindow('SimpleLoadFromFile', 800, 600, @WindowProc); | |||
| try | |||
| tex := TglBitmap2D.Create; // create texture object | |||
| data := TglBitmapData.Create; // create texture data object | |||
| tex := TglBitmap2D.Create; // create texture object | |||
| data := TglBitmapData.Create; // create texture data object | |||
| try | |||
| data.LoadFromFile( // load texture data from file | |||
| data.LoadFromFile( // load texture data from file | |||
| ExtractFilePath(ApplicationName) + | |||
| '../textures/BMP_24_RGB8.bmp'); | |||
| tex.UploadData(data); // upload data to video card | |||
| if not data.FormatDescriptor.HasOpenGLSupport then // check if format is supported by OpenGL | |||
| data.ConvertTo(data.FormatDescriptor.OpenGLFormat); // if not then convert | |||
| tex.UploadData(data); // upload data to video card | |||
| finally | |||
| FreeAndNil(data); // after upload is done, the data object could be freed to save memory | |||
| FreeAndNil(data); // after upload is done, the data object could be freed to save memory | |||
| end; | |||
| while running and ProgressMesages do begin | |||
| @@ -8,9 +8,8 @@ | |||
| <Unit0> | |||
| <Filename Value="SimpleLoadFromFile.lpr"/> | |||
| <IsPartOfProject Value="True"/> | |||
| <IsVisibleTab Value="True"/> | |||
| <TopLine Value="30"/> | |||
| <CursorPos X="8" Y="45"/> | |||
| <CursorPos X="56" Y="46"/> | |||
| <UsageCount Value="20"/> | |||
| <Loaded Value="True"/> | |||
| </Unit0> | |||
| @@ -23,9 +22,10 @@ | |||
| <Filename Value="..\..\glBitmap.pas"/> | |||
| <IsPartOfProject Value="True"/> | |||
| <UnitName Value="glBitmap"/> | |||
| <IsVisibleTab Value="True"/> | |||
| <EditorIndex Value="1"/> | |||
| <TopLine Value="6544"/> | |||
| <CursorPos X="47" Y="6558"/> | |||
| <TopLine Value="3822"/> | |||
| <CursorPos X="65" Y="3838"/> | |||
| <UsageCount Value="20"/> | |||
| <Loaded Value="True"/> | |||
| </Unit2> | |||
| @@ -36,7 +36,6 @@ | |||
| </Unit3> | |||
| <Unit4> | |||
| <Filename Value="..\TextureFromFunction\TextureFromFunction.lpr"/> | |||
| <UnitName Value="SimpleLoadFromFile"/> | |||
| <EditorIndex Value="2"/> | |||
| <TopLine Value="68"/> | |||
| <CursorPos Y="78"/> | |||
| @@ -44,7 +43,7 @@ | |||
| <Loaded Value="True"/> | |||
| </Unit4> | |||
| </Units> | |||
| <JumpHistory Count="21" HistoryIndex="20"> | |||
| <JumpHistory Count="24" HistoryIndex="23"> | |||
| <Position1> | |||
| <Filename Value="SimpleLoadFromFile.lpr"/> | |||
| <Caret Line="47" Column="75" TopLine="22"/> | |||
| @@ -129,6 +128,18 @@ | |||
| <Filename Value="SimpleLoadFromFile.lpr"/> | |||
| <Caret Line="45" Column="8" TopLine="30"/> | |||
| </Position21> | |||
| <Position22> | |||
| <Filename Value="..\..\glBitmap.pas"/> | |||
| <Caret Line="446" Column="50" TopLine="420"/> | |||
| </Position22> | |||
| <Position23> | |||
| <Filename Value="SimpleLoadFromFile.lpr"/> | |||
| <Caret Line="46" Column="56" TopLine="30"/> | |||
| </Position23> | |||
| <Position24> | |||
| <Filename Value="..\..\glBitmap.pas"/> | |||
| <Caret Line="446" Column="14" TopLine="431"/> | |||
| </Position24> | |||
| </JumpHistory> | |||
| </ProjectSession> | |||
| </CONFIG> | |||
| @@ -390,6 +390,10 @@ type | |||
| { @return @true if the format is a grayscale format, @false otherwise } | |||
| function GetIsGrayscale: Boolean; | |||
| { @return @true if the format is supported by OpenGL, @false otherwise } | |||
| function GetHasOpenGLSupport: Boolean; | |||
| protected | |||
| fFormat: TglBitmapFormat; //< format this descriptor belongs to | |||
| fWithAlpha: TglBitmapFormat; //< suitable format with alpha channel | |||
| @@ -442,6 +446,8 @@ type | |||
| property HasColor: Boolean read GetHasColor; //< @true if the format has any color color channel, @false otherwise | |||
| property IsGrayscale: Boolean read GetIsGrayscale; //< @true if the format is a grayscale format, @false otherwise | |||
| property HasOpenGLSupport: Boolean read GetHasOpenGLSupport; //< @true if the format is supported by OpenGL, @false otherwise | |||
| function GetSize(const aSize: TglBitmapSize): Integer; overload; virtual; | |||
| function GetSize(const aWidth, aHeight: Integer): Integer; overload; virtual; | |||
| @@ -3837,6 +3843,11 @@ begin | |||
| result := (Mask.r = Mask.g) and (Mask.g = Mask.b) and (Mask.r > 0); | |||
| end; | |||
| function TglBitmapFormatDescriptor.GetHasOpenGLSupport: Boolean; | |||
| begin | |||
| result := (OpenGLFormat = Format); | |||
| end; | |||
| procedure TglBitmapFormatDescriptor.SetValues; | |||
| begin | |||
| fFormat := tfEmpty; | |||