pixel.pp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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: 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: TPTCConsole = nil;
  32. surface: TPTCSurface = nil;
  33. format: TPTCFormat = nil;
  34. begin
  35. try
  36. try
  37. { create console }
  38. console := TPTCConsole.Create;
  39. { create format }
  40. format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
  41. { open the console }
  42. console.open('Pixel example', format);
  43. { create surface matching console dimensions }
  44. surface := TPTCSurface.Create(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. console.close;
  55. console.Free;
  56. surface.Free;
  57. format.Free;
  58. end;
  59. except
  60. on error: TPTCError do
  61. { report error }
  62. error.report;
  63. end;
  64. end.