tglwindow.pas 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. {
  2. Copyright (c) 2026 Karoly Balogh
  3. Multibuffered TinyGL window context creation example
  4. Example program for Free Pascal's MorphOS bindings
  5. With thanks to Mark Olsen for his help.
  6. This example program is in the Public Domain under the terms of
  7. Unlicense: http://unlicense.org/
  8. **********************************************************************}
  9. program tglwindow;
  10. uses
  11. GL, TinyGL, Intuition, Exec, Utility, AmigaDOS;
  12. var
  13. glWindow: PWindow;
  14. const
  15. WIDTH = 640;
  16. HEIGHT = 480;
  17. function CreateGLWindow(w, h: dword): PWindow;
  18. var
  19. window: PWindow;
  20. pubscreen: PScreen;
  21. x, y: DWord;
  22. begin
  23. CreateGLWindow:=nil;
  24. window:=nil;
  25. if assigned(TinyGLBase) and assigned(tglContext) then
  26. begin
  27. pubscreen:=LockPubScreen(nil);
  28. if not assigned(pubscreen) then
  29. exit;
  30. x:=(pubscreen^.Width div 2) - (w div 2);
  31. y:=(pubscreen^.Height div 2) - (h div 2);
  32. window:=OpenWindowTags(nil,
  33. [ WA_SimpleRefresh, 1,
  34. WA_Activate, 1,
  35. WA_Left, x,
  36. WA_Top, y,
  37. WA_InnerWidth, w,
  38. WA_InnerHeight, h,
  39. WA_MinWidth, w,
  40. WA_MinHeight, h,
  41. WA_MaxWidth, w,
  42. WA_MaxHeight, h,
  43. WA_PubScreen, Tag(pubscreen),
  44. WA_Title, Tag(PChar('FPC TinyGL Window')),
  45. WA_Flags, WFLG_DRAGBAR or WFLG_DEPTHGADGET,
  46. TAG_DONE ]);
  47. UnlockPubScreen(nil, pubscreen);
  48. if assigned(window) then
  49. begin
  50. if not GLAInitializeContextTags(tglContext,
  51. [ TGL_CONTEXT_WINDOW, Tag(window),
  52. { TGL_CONTEXT_NODEPTH, 1, } { Enable this if no depth buffer is needed. }
  53. { TGL_CONTEXT_STENCIL, 1, } { Enable this if stencil buffer is needed. }
  54. TAG_DONE ]) then
  55. begin
  56. CloseWindow(window);
  57. window:=nil;
  58. end;
  59. end;
  60. end;
  61. CreateGLWindow:=window;
  62. end;
  63. procedure RenderGLWindow;
  64. begin
  65. { Make the window blue }
  66. glClearColor(0, 0, 1, 0);
  67. glClear(GL_COLOR_BUFFER_BIT);
  68. { TinyGL will handle double buffering and buffer swapping }
  69. { Call GLASwapBuffers() when you want the current frame displayed }
  70. GLASwapBuffers(tglContext);
  71. DOSDelay(100);
  72. end;
  73. procedure CloseGLWindow(window: PWindow);
  74. begin
  75. if assigned(window) then
  76. begin
  77. GLADestroyContext(tglContext);
  78. CloseWindow(window);
  79. end;
  80. end;
  81. begin
  82. glWindow:=CreateGLWindow(WIDTH, HEIGHT);
  83. RenderGLWindow;
  84. CloseGLWindow(glWindow);
  85. end.