demo01.cpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // RU: Этот дефайн необходим только в главном модуле.
  2. // EN: This define is needed only in main unit.
  3. #define ZGL_IMPORT
  4. #include "zglHeader.h"
  5. const char* DirApp;
  6. const 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 CALLBACK WinMain (
  35. __in HINSTANCE hInstance,
  36. __in_opt HINSTANCE hPrevInstance,
  37. __in_opt LPSTR lpCmdLine,
  38. __in int nShowCmd
  39. )
  40. {
  41. if ( !zglLoad( libZenGL ) ) return 0;
  42. // RU: Для загрузки/создания каких-то своих настроек/профилей/etc. можно получить путь к домашенему каталогу пользователя, или к исполняемому файлу(не работает для GNU/Linux).
  43. // 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).
  44. DirApp = (const char*)zgl_Get( DIRECTORY_APPLICATION );
  45. DirHome = (const char*)zgl_Get( DIRECTORY_HOME );
  46. // RU: Создаем таймер с интервалом 1000мс.
  47. // EN: Create a timer with interval 1000ms.
  48. timer_Add( (void*)&Timer, 1000 );
  49. // RU: Регистрируем процедуру, что выполнится сразу после инициализации ZenGL.
  50. // EN: Register the procedure, that will be executed after ZenGL initialization.
  51. zgl_Reg( SYS_LOAD, (void*)&Init );
  52. // RU: Регистрируем процедуру, где будет происходить рендер.
  53. // EN: Register the render procedure.
  54. zgl_Reg( SYS_DRAW, (void*)&Draw );
  55. // RU: Регистрируем процедуру, которая будет принимать разницу времени между кадрами.
  56. // EN: Register the procedure, that will get delta time between the frames.
  57. zgl_Reg( SYS_UPDATE, (void*)&Update );
  58. // RU: Регистрируем процедуру, которая выполнится после завершения работы ZenGL.
  59. // EN: Register the procedure, that will be executed after ZenGL shutdown.
  60. zgl_Reg( SYS_EXIT, (void*)&Quit );
  61. // RU: Устанавливаем заголовок окна.
  62. // EN: Set the caption of the window.
  63. wnd_SetCaption( "01 - Initialization" );
  64. // RU: Разрешаем курсор мыши.
  65. // EN: Allow to show the mouse cursor.
  66. wnd_ShowCursor( TRUE );
  67. // RU: Указываем первоначальные настройки.
  68. // EN: Set screen options.
  69. scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE );
  70. // RU: Инициализируем ZenGL.
  71. // EN: Initialize ZenGL.
  72. zgl_Init();
  73. zglFree();
  74. return 0;
  75. }