pixel.pp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. {
  2. Ported to FPC by Nikolay Nikolov ([email protected])
  3. }
  4. {
  5. Pixel example for OpenPTC 1.0 C++ API
  6. Copyright (c) Glenn Fiedler ([email protected])
  7. This source code is licensed under the GNU GPL
  8. }
  9. program PixelExample;
  10. {$MODE objfpc}
  11. uses
  12. ptc;
  13. procedure putpixel(surface: IPTCSurface; x, y: Integer; r, g, b: Uint8);
  14. var
  15. pixels: PUint32;
  16. color: Uint32;
  17. begin
  18. { lock surface }
  19. pixels := surface.lock;
  20. try
  21. { pack the color integer from r,g,b components }
  22. color := (r shl 16) or (g shl 8) or b;
  23. { plot the pixel on the surface }
  24. pixels[x + y * surface.width] := color;
  25. finally
  26. { unlock surface }
  27. surface.unlock;
  28. end;
  29. end;
  30. var
  31. console: IPTCConsole;
  32. surface: IPTCSurface;
  33. format: IPTCFormat;
  34. begin
  35. try
  36. try
  37. { create console }
  38. console := TPTCConsoleFactory.CreateNew;
  39. { create format }
  40. format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
  41. { open the console }
  42. console.open('Pixel example', format);
  43. { create surface matching console dimensions }
  44. surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
  45. { plot a white pixel in the middle of the surface }
  46. putpixel(surface, surface.width div 2, surface.height div 2, 255, 255, 255);
  47. { copy to console }
  48. surface.copy(console);
  49. { update console }
  50. console.update;
  51. { read key }
  52. console.ReadKey;
  53. finally
  54. if Assigned(console) then
  55. console.close;
  56. end;
  57. except
  58. on error: TPTCError do
  59. { report error }
  60. error.report;
  61. end;
  62. end.