demo05.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #define ZGL_IMPORT
  2. #include "zglHeader.h"
  3. int calc;
  4. zglTPoint2D points[360];
  5. void Init()
  6. {
  7. for ( int i = 0; i < 360; i++ )
  8. {
  9. points[ i ].X = 400 + m_Cos( i ) * ( 96 + rand() % 32 );
  10. points[ i ].Y = 300 + m_Sin( i ) * ( 96 + rand() % 32 );
  11. }
  12. }
  13. void Draw()
  14. {
  15. // RU: Устанавливаем цвет и альфу для каждой вершины.
  16. // EN: Set color and alpha for each vertex.
  17. fx2d_SetVCA( 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFFFF, 255, 255, 255, 255 );
  18. // RU: Рисуем прямоугольник с заливкой(флаг PR2D_FILL) с использованием отдельных цветов для каждой вершины(флаг FX2D_VCA).
  19. // EN: Render filled rectangle(flag PR2D_FILL) and use different colors for each vertex(flag FX2D_VCA).
  20. pr2d_Rect( 0, 0, 800, 600, 0x000000, 255, FX2D_VCA | PR2D_FILL );
  21. // RU: Рисуем в центре экрана круг с радиусом 128 пиксела.
  22. // EN: Render circle in the center of screen with radius 128 pixels.
  23. pr2d_Circle( 400, 300, 128, 0x000000, 155, 32, PR2D_FILL );
  24. calc++;
  25. if ( calc > 359 )
  26. calc = 0;
  27. points[ calc ].X = 400 + m_Cos( calc ) * ( 96 + rand() % 32 );
  28. points[ calc ].Y = 300 + m_Sin( calc ) * ( 96 + rand() % 32 );
  29. // RU: Рисуем линии внутри круга.
  30. // EN: Render lines inside the circle.
  31. for ( int i = 0; i < 360; i++ )
  32. pr2d_Line( 400, 300, points[ i ].X, points[ i ].Y, 0xFFFFFF, 255, 0 );
  33. // RU: Рисуем эллипсы с заливкой и без, со сглаженными контурами(флаг PR2D_SMOOTH).
  34. // EN: Render filled ellipses with smoothed edges(flag PR2D_SMOOTH).
  35. pr2d_Ellipse( 400 + 300, 300, 64, 256, 0xFFFFFF, 55, 32, PR2D_FILL | PR2D_SMOOTH );
  36. pr2d_Ellipse( 400 + 300, 300, 64, 256, 0x000000, 255, 32, PR2D_SMOOTH );
  37. pr2d_Ellipse( 400 - 300, 300, 64, 256, 0xFFFFFF, 55, 32, PR2D_FILL | PR2D_SMOOTH );
  38. pr2d_Ellipse( 400 - 300, 300, 64, 256, 0x000000, 255, 32, PR2D_SMOOTH );
  39. }
  40. void Timer()
  41. {
  42. if ( key_Press( K_ESCAPE ) ) zgl_Exit();
  43. key_ClearState();
  44. }
  45. int main()
  46. {
  47. if ( !zglLoad( libZenGL ) ) return 0;
  48. srand( 0xDeaDBeeF );
  49. timer_Add( (void*)&Timer, 16, FALSE, NULL );
  50. zgl_Reg( SYS_LOAD, (void*)&Init );
  51. zgl_Reg( SYS_DRAW, (void*)&Draw );
  52. wnd_SetCaption( "05 - Primitives" );
  53. wnd_ShowCursor( TRUE );
  54. scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE );
  55. zgl_Init( 0, 0 );
  56. zglFree();
  57. return 0;
  58. }