INTRO 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. For more complete documentation please refer to the C++ documentation of
  2. OpenPTC.
  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, please refer to the Free Pascal
  6. Reference guide, Chapter 5 - Classes.)
  7. There are 3 classes you should get familiar with: TPTCFormat, TPTCSurface and
  8. TPTCConsole.
  9. Ok, what is TPTCFormat? It basically describes a pixel format. To create a
  10. pixel format for 32 bpp use:
  11. Format := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
  12. 32 is the number of bits per pixel. (Only formats with 8, 16, 24 and 32 bits
  13. per pixel are supported). $FF0000, $FF00 and $FF are the red, green and blue
  14. masks.
  15. Now, when you have created your favourite pixel format, you should create a
  16. surface:
  17. Surface := TPTCSurface.Create(320, 200, Format);
  18. This will create a buffer in RAM to hold a single 320x200 frame in the given
  19. format. Note that TPTCSurface is always created in normal RAM, not video RAM,
  20. so it's not a problem if your video card doesn't have enough memory for it,
  21. or doesn't support e.g. 320x200x32bpp. You just create a TPTCConsole and open
  22. it in whatever mode is supported by the hardware and then PTC will blit the
  23. image stored in TPTCSurface to the console, doing any conversions that are
  24. necessary (i.e. converting to another pixel format, stretching the image to
  25. another resolution, etc...).
  26. How to use this TPTCConsole? Easy! First create it:
  27. Console := TPTCConsole.Create;
  28. This still doesn't do anything, just allocates memory and initializes stuff.
  29. Then you switch to the desired mode:
  30. Console.open('Hello, world!', 320, 200, Format);
  31. Note that if your hardware doesn't support the requested mode, PTC will try
  32. to switch to the best mode. If (for example) your card doesn't support
  33. 320x200 in 32bpp, only in 16bpp, PTC will (probably) switch to that mode.
  34. To see the actual mode that PTC has set use these properties:
  35. Console.width Console.height and Console.format
  36. Ok, now that you have created a TPTCSurface and opened a TPTCConsole, what to
  37. do next? Draw stuff... The lock function of TPTCSurface will give you a pointer
  38. to the internal buffer.
  39. ptr := Surface.lock;
  40. Now you can draw your frame in the buffer, pointed by ptr. Note that this buffer
  41. is guaranteed to be in the format and resolution you requested.
  42. When you're done you have to unlock the surface and copy it to the console:
  43. Surface.unlock;
  44. Surface.copy(Console);
  45. Console.update;
  46. The Surface.copy(Console) will do the conversion (if necessary) to the actual
  47. mode. Console.update will actually show the new frame (if the console driver
  48. supports multiple pages and you have enough video RAM for that, etc... :) ).
  49. See the example programs for additional details. (keyboard input, high
  50. resolution timers - they're pretty much straightforward)
  51. Enjoy!
  52. Nikolay Nikolov