demo01.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // RU: Этот дефайн необходим только в главном модуле.
  2. // EN: This define is needed only in main unit.
  3. #define ZGL_IMPORT
  4. #include "zglHeader.h"
  5. char* DirApp;
  6. char* DirHome;
  7. void Init()
  8. {
  9. // RU: Тут можно выполнять загрузку основных ресурсов.
  10. // EN: Here can be loading of main resources.
  11. }
  12. void Draw()
  13. {
  14. // RU: Тут "рисуем" что угодно :)
  15. // EN: Here "draw" anything :)
  16. }
  17. void Update( double dt )
  18. {
  19. // RU: Эта функция наземенима для реализация плавного движения чего-либо, т.к. точность таймеров ограничена FPS.
  20. // EN: This function is the best way to implement smooth moving of something, because accuracy of timers are restricted by FPS.
  21. }
  22. void Timer()
  23. {
  24. // RU: Будем в заголовке показывать количество кадров в секунду.
  25. // EN: Caption will show the frames per second.
  26. char caption[256];
  27. sprintf_s( caption, "01 - Initialization[ FPS: %i ]", (int)zgl_Get( RENDER_FPS ) );
  28. wnd_SetCaption( caption );
  29. }
  30. void Quit()
  31. {
  32. //
  33. }
  34. int main()
  35. {
  36. #ifdef __LINUX__
  37. // RU: В GNU/Linux все библиотеки принято хранить в /usr/lib, поэтому libZenGL.so должна быть предварительно установлена.
  38. // Но zglLoad сначала проверить есть ли libZenGL.so рядом с исполняемым файлом.
  39. //
  40. // EN: In GNU/Linux all libraries placed in /usr/lib, so libZenGL.so must be installed before it will be used.
  41. // But zglLoad will check first if there is libZenGL.so near executable file.
  42. if ( !zglLoad( libZenGL ) ) return 0;
  43. #endif
  44. #ifdef __WINDOWS__
  45. if ( !zglLoad( libZenGL ) ) return 0;
  46. #endif
  47. #ifdef __MACOSX__
  48. // RU: libZenGL.dylib следует предварительно поместить в каталог MyApp.app/Contents/Frameworks/, где MyApp.app - Bundle вашего приложения.
  49. // Также следует упомянуть, что лог-файл будет создаваться в корневом каталоге поэтому либо отключайте его, либо указывайте свой путь и имя, как описано в справке.
  50. //
  51. // EN: libZenGL.dylib must be placed into this directory MyApp.app/Contents/Frameworks/, where MyApp.app - Bundle of your application.
  52. // Also you must know, that log-file will be created in root directory, so you must disable a log, or choose your own path and name for it. How to do this you can find in documentation.
  53. if ( !zglLoad( libZenGL ) ) return 0;
  54. #endif
  55. // RU: Для загрузки/создания каких-то своих настроек/профилей/etc. можно получить путь к домашенему каталогу пользователя, или к исполняемому файлу(не работает для GNU/Linux).
  56. // EN: For loading/creating your own options/profiles/etc. you can get path to user home directory, or to executable file(not works for GNU/Linux).
  57. DirApp = (char*)zgl_Get( DIRECTORY_APPLICATION );
  58. DirHome = (char*)zgl_Get( DIRECTORY_HOME );
  59. // RU: Создаем таймер с интервалом 1000мс.
  60. // EN: Create a timer with interval 1000ms.
  61. timer_Add( (void*)&Timer, 1000, FALSE, NULL );
  62. // RU: Регистрируем процедуру, что выполнится сразу после инициализации ZenGL.
  63. // EN: Register the procedure, that will be executed after ZenGL initialization.
  64. zgl_Reg( SYS_LOAD, (void*)&Init );
  65. // RU: Регистрируем процедуру, где будет происходить рендер.
  66. // EN: Register the render procedure.
  67. zgl_Reg( SYS_DRAW, (void*)&Draw );
  68. // RU: Регистрируем процедуру, которая будет принимать разницу времени между кадрами.
  69. // EN: Register the procedure, that will get delta time between the frames.
  70. zgl_Reg( SYS_UPDATE, (void*)&Update );
  71. // RU: Регистрируем процедуру, которая выполнится после завершения работы ZenGL.
  72. // EN: Register the procedure, that will be executed after ZenGL shutdown.
  73. zgl_Reg( SYS_EXIT, (void*)&Quit );
  74. // RU: Устанавливаем заголовок окна.
  75. // EN: Set the caption of the window.
  76. wnd_SetCaption( "01 - Initialization" );
  77. // RU: Разрешаем курсор мыши.
  78. // EN: Allow to show the mouse cursor.
  79. wnd_ShowCursor( TRUE );
  80. // RU: Указываем первоначальные настройки.
  81. // EN: Set screen options.
  82. scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE );
  83. // RU: Инициализируем ZenGL.
  84. // EN: Initialize ZenGL.
  85. zgl_Init( 0, 0 );
  86. zglFree();
  87. return 0;
  88. }