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.

57 lines
1.2 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. function WindowProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
  13. begin
  14. case Msg of
  15. WM_DESTROY: begin
  16. running := false;
  17. end;
  18. end;
  19. result := DefWindowProc(hWnd, Msg, wParam, lParam);
  20. end;
  21. procedure RenderLoop;
  22. begin
  23. tex.Bind();
  24. glColor4f(1, 1, 1, 1);
  25. glBegin(GL_QUADS);
  26. glTexCoord2f(0, 0); glVertex2f(100, 100);
  27. glTexCoord2f(1, 0); glVertex2f(700, 100);
  28. glTexCoord2f(1, 1); glVertex2f(700, 500);
  29. glTexCoord2f(0, 1); glVertex2f(100, 500);
  30. glEnd;
  31. tex.Unbind();
  32. end;
  33. begin
  34. oglWindow := CreateOpenGLWindow('SimpleLoadFromFile', 800, 600, @WindowProc);
  35. try
  36. // load texture
  37. tex := TglBitmap2D.Create;
  38. tex.LoadFromFile(ExtractFilePath(ApplicationName) + '../textures/BMP_24_RGB8.bmp');
  39. tex.GenTexture;
  40. while running and ProgressMesages do begin
  41. RenderLoop;
  42. SwapBuffers(oglWindow.DC);
  43. end;
  44. finally
  45. FreeAndNil(tex);
  46. DestroyOpenGLWindow(oglWindow);
  47. end;
  48. end.