ptcgl.pp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {
  2. PTC OpenGL example for PTCPas
  3. Copyright (c) Nikolay Nikolov ([email protected])
  4. This source code is in the public domain
  5. }
  6. program PtcGLExample;
  7. {$MODE objfpc}
  8. uses
  9. ptc, gl, SysUtils;
  10. var
  11. Console: IPTCConsole;
  12. Event: IPTCEvent;
  13. Done: Boolean = False;
  14. begin
  15. try
  16. try
  17. { create console }
  18. Console := TPTCConsoleFactory.CreateNew;
  19. { tell PTC we want OpenGL }
  20. Console.OpenGL_Enabled := True;
  21. { enable OpenGL double buffering }
  22. Console.OpenGL_Attributes.DoubleBuffer := True;
  23. { open the console }
  24. Console.Open('PTC OpenGL example');
  25. glClearColor(0.0, 0.0, 0.0, 0.0);
  26. glMatrixMode(GL_PROJECTION);
  27. glLoadIdentity;
  28. glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
  29. { loop until the key 'q' is pressed }
  30. repeat
  31. { draw scene }
  32. glClear(GL_COLOR_BUFFER_BIT);
  33. glBegin(GL_POLYGON);
  34. glColor3f(1.0, 0.0, 0.0);
  35. glVertex3f(0.25, 0.25, 0.0);
  36. glColor3f(1.0, 1.0, 0.0);
  37. glVertex3f(0.75, 0.25, 0.0);
  38. glColor3f(0.5, 0.0, 1.0);
  39. glVertex3f(0.75, 0.75, 0.0);
  40. glColor3f(0.0, 1.0, 0.0);
  41. glVertex3f(0.25, 0.75, 0.0);
  42. glEnd;
  43. glFlush;
  44. { swap buffers }
  45. Console.OpenGL_SwapBuffers;
  46. { check for events }
  47. if Console.NextEvent(Event, False, PTCAnyEvent) then
  48. begin
  49. { handle keyboard events }
  50. if Supports(event, IPTCKeyEvent) and (event as IPTCKeyEvent).Press then
  51. begin
  52. case (event as IPTCKeyEvent).Code of
  53. PTCKEY_Q: Done := True;
  54. end;
  55. end;
  56. end;
  57. until Done;
  58. finally
  59. if Assigned(Console) then
  60. Console.Close;
  61. end;
  62. except
  63. on Error: TPTCError do
  64. { report error }
  65. Error.Report;
  66. end;
  67. end.