* some small OpenGLES fixes
[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       if not data.FormatDescriptor.HasOpenGLSupport then    // check if format is supported by OpenGL
50         data.ConvertTo(data.FormatDescriptor.OpenGLFormat); // if not then convert
51       tex.UploadData(data);                                 // upload data to video card
52     finally
53       FreeAndNil(data);                                     // after upload is done, the data object could be freed to save memory
54     end;
55
56     while running and ProgressMesages do begin
57       RenderLoop;
58       SwapBuffers(oglWindow.DC);
59     end;
60   finally
61     FreeAndNil(tex);
62     DestroyOpenGLWindow(oglWindow);
63   end;
64 end.
65