INTRO.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. For more detailed documentation please see the API reference found in the
  2. 'api-reference' directory (as well as online on the official PTCPas website).
  3. This will explain the basics of creating a simple graphics application using
  4. PTC for FPC. :)
  5. (If you aren't familiar with Delphi classes and interfaces, please refer to the
  6. Free Pascal Reference guide, Chapter 6 - Classes and Chapter 7 - Interfaces.)
  7. There are 3 interfaces you should get familiar with: IPTCFormat, IPTCSurface
  8. and IPTCConsole.
  9. Ok, what is IPTCFormat? It basically describes a pixel format. To create a
  10. pixel format for 32 bpp use:
  11. var
  12. Format: IPTCFormat;
  13. begin
  14. Format := TPTCFormatFactory.CreateNew(32, $FF0000, $FF00, $FF);
  15. 32 is the number of bits per pixel. (Only formats with 8, 16, 24 and 32 bits
  16. per pixel are supported). $FF0000, $FF00 and $FF are the red, green and blue
  17. masks.
  18. Note that you no longer need to call Format.Free. The object is reference
  19. counted and will be freed automatically when it's no longer needed. This also
  20. applies to all the other PTC objects created by their TPTC*Factory.CreateNew
  21. methods.
  22. Now, when you have created your favourite pixel format, you should create a
  23. surface:
  24. var
  25. Surface: IPTCSurface;
  26. begin
  27. Surface := TPTCSurfaceFactory.CreateNew(320, 200, Format);
  28. This will create a buffer in RAM to hold a single 320x200 frame in the given
  29. format. Note that surfaces, created by TPTCSurfaceFactory.CreateNew are always
  30. created in normal RAM, not video RAM, so it's not a problem if your video card
  31. doesn't have enough memory for it, or doesn't support the exact resolution that
  32. you requested. You just create a IPTCConsole and open it in whatever mode is
  33. supported by the hardware and then PTC will blit the image stored in
  34. IPTCSurface to the console, doing any conversions that are necessary (i.e.
  35. converting to another pixel format, stretch the image to another resolution,
  36. etc...).
  37. How to use this IPTCConsole? Easy! First create it:
  38. var
  39. Console: IPTCConsole;
  40. begin
  41. Console := TPTCConsoleFactory.CreateNew;
  42. This still doesn't do anything, just allocates memory and initializes stuff.
  43. Then you switch to the desired mode:
  44. Console.Open('Hello, world!', 320, 200, Format);
  45. Note that if your hardware doesn't support the requested mode, PTC will try
  46. to switch to the best mode. If (for example) your card doesn't support
  47. 320x200 in 32bpp, only in 16bpp, PTC will (probably) switch to that mode.
  48. To see the actual mode that PTC has set use these properties:
  49. Console.Width Console.Height and Console.Format
  50. Ok, now that you have created an IPTCSurface and opened an IPTCConsole, what to
  51. do next? Draw stuff... The lock function of IPTCSurface will give you a pointer
  52. to its internal buffer.
  53. ptr := Surface.Lock;
  54. Now you can draw your frame in the buffer, pointed by ptr. Note that this buffer
  55. is guaranteed to be in the format and resolution you requested.
  56. When you're done you have to unlock the surface and copy it to the console:
  57. Surface.Unlock;
  58. Surface.Copy(Console);
  59. Console.Update;
  60. The Surface.Copy(Console) will do the conversion (if necessary) to the actual
  61. mode. Console.Update will actually show the new frame (if the console driver
  62. supports multiple video pages and you have enough video RAM for that, etc... :) ).
  63. See the example programs for additional details. (keyboard and mouse input,
  64. high resolution timers - they're pretty much straightforward)
  65. Enjoy!
  66. Nikolay Nikolov