demo05.lpr 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. program demo05;
  2. {$I zglCustomConfig.cfg}
  3. {$IFDEF WINDOWS}
  4. {$R *.res}
  5. {$ENDIF}
  6. uses
  7. {$IFDEF USE_ZENGL_STATIC}
  8. zgl_main,
  9. zgl_screen,
  10. zgl_window,
  11. zgl_timers,
  12. zgl_keyboard,
  13. zgl_fx,
  14. zgl_render_2d,
  15. zgl_primitives_2d,
  16. zgl_math_2d,
  17. zgl_utils
  18. {$ELSE}
  19. zglHeader
  20. {$ENDIF}
  21. ;
  22. var
  23. calc : Integer;
  24. points : array[ 0..359 ] of zglTPoint2D;
  25. procedure Init;
  26. var
  27. i : Integer;
  28. begin
  29. for i := 0 to 359 do
  30. begin
  31. points[ i ].X := 400 + m_Cos( i ) * ( 96 + random( 32 ) );
  32. points[ i ].Y := 300 + m_Sin( i ) * ( 96 + random( 32 ) );
  33. end;
  34. end;
  35. procedure Draw;
  36. var
  37. i : Integer;
  38. begin
  39. // RU: Устанавливаем цвет и альфу для каждой вершины.
  40. // EN: Set color and alpha for each vertex.
  41. fx2d_SetVCA( $FF0000, $00FF00, $0000FF, $FFFFFF, 255, 255, 255, 255 );
  42. // RU: Рисуем прямоугольник с заливкой(флаг PR2D_FILL) с использованием отдельных цветов для каждой вершины(флаг FX2D_VCA).
  43. // EN: Render filled rectangle(flag PR2D_FILL) and use different colors for each vertex(flag FX2D_VCA).
  44. pr2d_Rect( 0, 0, 800, 600, $000000, 255, FX2D_VCA or PR2D_FILL );
  45. // RU: Рисуем в центре экрана круг с радиусом 128 пиксела.
  46. // EN: Render circle in the center of screen with radius 128 pixels.
  47. pr2d_Circle( 400, 300, 128, $000000, 155, 32, PR2D_FILL );
  48. INC( calc );
  49. if calc > 359 Then calc := 0;
  50. points[ calc ].X := 400 + m_Cos( calc ) * ( 96 + random( 32 ) );
  51. points[ calc ].Y := 300 + m_Sin( calc ) * ( 96 + random( 32 ) );
  52. // RU: Рисуем линии внутри круга.
  53. // EN: Render lines inside the circle.
  54. for i := 0 to 359 do
  55. pr2d_Line( 400, 300, points[ i ].X, points[ i ].Y, $FFFFFF, 255 );
  56. // RU: Рисуем эллипсы с заливкой и без, со сглаженными контурами(флаг PR2D_SMOOTH).
  57. // EN: Render filled ellipses with smoothed edges(flag PR2D_SMOOTH).
  58. pr2d_Ellipse( 400 + 300, 300, 64, 256, $FFFFFF, 55, 32, PR2D_FILL or PR2D_SMOOTH );
  59. pr2d_Ellipse( 400 + 300, 300, 64, 256, $000000, 255, 32, PR2D_SMOOTH );
  60. pr2d_Ellipse( 400 - 300, 300, 64, 256, $FFFFFF, 55, 32, PR2D_FILL or PR2D_SMOOTH );
  61. pr2d_Ellipse( 400 - 300, 300, 64, 256, $000000, 255, 32, PR2D_SMOOTH );
  62. end;
  63. procedure Timer;
  64. begin
  65. if key_Press( K_ESCAPE ) Then zgl_Exit();
  66. key_ClearState();
  67. end;
  68. Begin
  69. {$IFNDEF USE_ZENGL_STATIC}
  70. if not zglLoad( libZenGL ) Then exit;
  71. {$ENDIF}
  72. timer_Add( @Timer, 16 );
  73. zgl_Reg( SYS_LOAD, @Init );
  74. zgl_Reg( SYS_DRAW, @Draw );
  75. wnd_SetCaption( '05 - Primitives' );
  76. wnd_ShowCursor( TRUE );
  77. scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE );
  78. zgl_Init();
  79. End.