ptcgl2.pp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 PtcGL2Example;
  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. { use OpenGL single buffering }
  22. Console.OpenGL_Attributes.DoubleBuffer := False;
  23. { open the console }
  24. Console.Open('PTC OpenGL single buffering 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. { check for events }
  45. if Console.NextEvent(Event, False, PTCAnyEvent) then
  46. begin
  47. { handle keyboard events }
  48. if Supports(event, IPTCKeyEvent) and (event as IPTCKeyEvent).Press then
  49. begin
  50. case (event as IPTCKeyEvent).Code of
  51. PTCKEY_Q: Done := True;
  52. end;
  53. end;
  54. end;
  55. until Done;
  56. finally
  57. if Assigned(Console) then
  58. Console.Close;
  59. end;
  60. except
  61. on Error: TPTCError do
  62. { report error }
  63. Error.Report;
  64. end;
  65. end.