You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.8 KiB

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