demo05.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 );
  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 CALLBACK WinMain (
  46. __in HINSTANCE hInstance,
  47. __in_opt HINSTANCE hPrevInstance,
  48. __in_opt LPSTR lpCmdLine,
  49. __in int nShowCmd
  50. )
  51. {
  52. if ( !zglLoad( libZenGL ) ) return 0;
  53. srand( 0xDeaDBeeF );
  54. timer_Add( (void*)&Timer, 16 );
  55. zgl_Reg( SYS_LOAD, (void*)&Init );
  56. zgl_Reg( SYS_DRAW, (void*)&Draw );
  57. wnd_SetCaption( "05 - Primitives" );
  58. wnd_ShowCursor( TRUE );
  59. scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE );
  60. zgl_Init();
  61. zglFree();
  62. return 0;
  63. }