* split TglBitmap into TglBitmap and TglBitmapData to be able to handle load, save...
[glBitmap.git] / examples / SimpleLoadFromFile / SimpleLoadFromFile.lpr
1 program SimpleLoadFromFile;
2
3 {$mode objfpc}{$H+}
4
5 uses
6   {$IFDEF UNIX}{$IFDEF UseCThreads}
7   cthreads,
8   {$ENDIF}{$ENDIF}
9   Classes, Windows, SysUtils, dglOpenGL, glBitmap, Helper;
10
11 var
12   oglWindow: TOpenGLWindow;
13   running: Boolean = true;
14   tex: TglBitmap2D;
15   data: TglBitmapData;
16
17 function WindowProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
18 begin
19   case Msg of
20     WM_DESTROY: begin
21       running := false;
22     end;
23   end;
24   result := DefWindowProc(hWnd, Msg, wParam, lParam);
25 end;
26
27 procedure RenderLoop;
28 begin
29   tex.Bind();
30   glColor4f(1, 1, 1, 1);
31   glBegin(GL_QUADS);
32     glTexCoord2f(0, 0); glVertex2f(100, 100);
33     glTexCoord2f(1, 0); glVertex2f(700, 100);
34     glTexCoord2f(1, 1); glVertex2f(700, 500);
35     glTexCoord2f(0, 1); glVertex2f(100, 500);
36   glEnd;
37   tex.Unbind();
38 end;
39
40 begin
41   oglWindow := CreateOpenGLWindow('SimpleLoadFromFile', 800, 600, @WindowProc);
42   try
43     tex  := TglBitmap2D.Create;               // create texture object
44     data := TglBitmapData.Create;             // create texture data object
45     try
46       data.LoadFromFile(                      // load texture data from file
47         ExtractFilePath(ApplicationName) +
48         '../textures/BMP_24_RGB8.bmp');
49       tex.UploadData(data);                   // upload data to video card
50     finally
51       FreeAndNil(data);                       // after upload is done, the data object could be freed to save memory
52     end;
53
54     while running and ProgressMesages do begin
55       RenderLoop;
56       SwapBuffers(oglWindow.DC);
57     end;
58   finally
59     FreeAndNil(tex);
60     DestroyOpenGLWindow(oglWindow);
61   end;
62 end.
63