demo05.pas 2.7 KB

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