pixel.pp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 : TPTCSurface; x, y : Integer; r, g, b : char8);
  14. Var
  15. pixels : Pint32;
  16. color : int32;
  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 : TPTCConsole;
  32. surface : TPTCSurface;
  33. format : TPTCFormat;
  34. Begin
  35. format := Nil;
  36. surface := Nil;
  37. console := Nil;
  38. Try
  39. Try
  40. { create console }
  41. console := TPTCConsole.Create;
  42. { create format }
  43. format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
  44. { open the console }
  45. console.open('Pixel example', format);
  46. { create surface matching console dimensions }
  47. surface := TPTCSurface.Create(console.width, console.height, format);
  48. { plot a white pixel in the middle of the surface }
  49. putpixel(surface, surface.width Div 2, surface.height Div 2, 255, 255, 255);
  50. { copy to console }
  51. surface.copy(console);
  52. { update console }
  53. console.update;
  54. { read key }
  55. console.ReadKey;
  56. Finally
  57. console.close;
  58. console.Free;
  59. surface.Free;
  60. format.Free;
  61. End;
  62. Except
  63. On error : TPTCError Do
  64. { report error }
  65. error.report;
  66. End;
  67. End.