OpenSceneGraph: construire Ă  partir des sources et de Hello World



Présentation


OpenSceneGraph (ci-après dénommé OSG) est un framework multiplateforme ouvert écrit en C ++ et représentant un moteur graphique qui fournit au programmeur une interface d'objet à OpenGL. Dans notre pays, ce moteur n'est pas particulièrement populaire, même sur Habré je n'ai vu qu'une publication plus ou moins décente à ce sujet . OSG est beaucoup utilisé à l'étranger où, par exemple, il est la base du simulateur de vol gratuit FlightGear , il existe une implémentation ouverte du jeu Morrowind, appelé OpenMW, dont le développement est également transféré à OSG à partir du moteur Ogre . La documentation en russe à ce sujet est extrêmement faible, et parmi la documentation en anglais, seule une série de livres de développeurs peut être notée: OpenSceneGraph 3.0. Guide du débutant et OpenSceneGraph 3. Cookbook .

Néanmoins, le moteur est assez intéressant pour les raisons suivantes:

  1. Une implémentation multiplateforme ouverte en C ++.
  2. Architecture modulaire.
  3. Extensibilité grâce au système de plug-in intégré.
  4. Possibilité de traitement multithread de données graphiques et d'outils intégrés pour sa mise en œuvre
  5. Gestion dynamique de la mémoire via un mécanisme de pointeur intelligent

Je pense qu'il sera intéressant pour les lecteurs de Habr de se familiariser avec ce projet plus en détail. La reconstitution de la base de connaissances OSG en russe ne sera pas superflue. Tous les documents que je publierai sur ce sujet sont basés sur le livre OpenSceneGraph 3.0. Guide du débutant , mais ce n'est pas sa traduction, mais plutôt une révision créative du matériel qui y est présenté. Si vous êtes intéressé par ce sujet, je demande une coupe

Le seul moyen sûr d'obtenir la dernière version d'OSG sur votre machine est de créer la bibliothèque à partir de la source. Le programme d'installation binaire existant pour Windows se concentre sur le compilateur MS Visual C ++. Pour moi, pour mes projets il faut utiliser le compilateur GCC, ou plutôt sa version de MinGW32, qui est incluse dans la fourniture des outils de développement du framework Qt. Il nous faut donc:

  1. Framework Qt installé et configuré avec le compilateur MinGW32 version 5.3 et l'IDE QtCreator
  2. Git Client pour Windows
  3. Utilitaire Cmake pour Windows

Le lecteur devrait être familier avec l'IDE QtCreator et le système de construction qmake utilisé dans les projets Qt. En outre, il est supposé que le lecteur connaît les bases de l'utilisation du système de contrôle de version Git et possède en principe des compétences de programmation non nulles.

1. Obtenir des sources OpenSceneGraph


Nous créons un répertoire sur notre disque dur où nous allons construire OSG, par exemple, le long du chemin D: \ OSG



Nous irons dans ce répertoire et obtiendrons la source du dépôt officiel OSG sur Github

D:\OSG> git clone https://github.com/openscenegraph/OpenSceneGraph.git 

La durée du processus de téléchargement dépend de la largeur de votre canal d'accès Internet. Tôt ou tard, nous recevrons une copie locale du référentiel OSG.

Après avoir téléchargé les sources, créez le répertoire build-win32-debug à proximité



Dans ce catalogue, nous allons construire le kit de débogage OSG. Mais avant

2. Configurer cmake


Pour que cmake fonctionne correctement, nous devons modifier le fichier install-path-cmake \ share \ cmake-3.13 \ Modules \ CMakeMinGWFindMake.cmake . Par défaut, cela ressemble à ceci

 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. find_program(CMAKE_MAKE_PROGRAM mingw32-make.exe PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MinGW;InstallLocation]/bin" c:/MinGW/bin /MinGW/bin "[HKEY_CURRENT_USER\\Software\\CodeBlocks;Path]/MinGW/bin" ) find_program(CMAKE_SH sh.exe ) if(CMAKE_SH) message(FATAL_ERROR "sh.exe was found in your PATH, here:\n${CMAKE_SH}\nFor MinGW make to work correctly sh.exe must NOT be in your path.\nRun cmake from a shell that does not have sh.exe in your PATH.\nIf you want to use a UNIX shell, then use MSYS Makefiles.\n") set(CMAKE_MAKE_PROGRAM NOTFOUND) endif() mark_as_advanced(CMAKE_MAKE_PROGRAM CMAKE_SH) 

Nous commentons quelques lignes, afin que l'utilitaire n'essaye pas de rechercher un shell Unix dans notre système, et s'il ne le trouve pas, il se termine par une erreur

 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. find_program(CMAKE_MAKE_PROGRAM mingw32-make.exe PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MinGW;InstallLocation]/bin" c:/MinGW/bin /MinGW/bin "[HKEY_CURRENT_USER\\Software\\CodeBlocks;Path]/MinGW/bin" ) #find_program(CMAKE_SH sh.exe ) #if(CMAKE_SH) # message(FATAL_ERROR "sh.exe was found in your PATH, here:\n${CMAKE_SH}\nFor MinGW make to work correctly sh.exe must NOT be in your path.\nRun cmake from a shell that does not have sh.exe in your PATH.\nIf you want to use a UNIX shell, then use MSYS Makefiles.\n") # set(CMAKE_MAKE_PROGRAM NOTFOUND) #endif() mark_as_advanced(CMAKE_MAKE_PROGRAM CMAKE_SH) 

3. Assemblage et installation des versions de débogage et de libération du moteur


Maintenant, exécutez le shell cmd, le raccourci sur lequel se trouve dans Démarrer-> Programmes-> Qt-> Qt 5.11.2-> Qt 5.11.2 for Desktop (MinGW 5.3.0 32bit)



Une session de ligne de commande en cours d'exécution configure l'ensemble de l'environnement nécessaire au fonctionnement des outils de génération mingw32. Accédez au répertoire source OSG

 C:\Qt\Qt5.11.2\5.11.2\mingw53_32>D: D:\> cd OSG\build-win32-debug 

Donnez une commande

 D:\OSG\build-win32-debug>cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=E:\Apps\OSG -DCMAKE_BUILD_TYPE=DEBUG ../OpenSceneGraph 

Analysons plus en détail la signification des paramètres:

  • -G "MinGW Makefiles" - indique qu'il est nĂ©cessaire de gĂ©nĂ©rer un Makefile pour l'utilitaire mingw32-make
  • -DCMAKE_INSTALL_PREFIX = E: \ Apps \ OSG - dĂ©finissez le chemin oĂą OSG sera installĂ©
  • -DCMAKE_BUILD_TYPE = DEBUG - indique qu'une version de dĂ©bogage du moteur doit ĂŞtre construite.

L'exécution de la commande vérifie l'état de préparation de l'environnement pour l'assemblage, génère un script de construction et le prochain échappement

Échappement Cmake lors de la configuration de la génération OSG
 -- The C compiler identification is GNU 5.3.0 -- The CXX compiler identification is GNU 5.3.0 -- Check for working C compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/gcc.exe -- Check for working C compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/gcc.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/g++.exe -- Check for working CXX compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/g++.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - found -- Found Threads: TRUE -- Found OpenGL: opengl32 -- Could NOT find EGL (missing: EGL_INCLUDE_DIR) -- Checking windows version... -- Performing Test GL_HEADER_HAS_GLINT64 -- Performing Test GL_HEADER_HAS_GLINT64 - Failed -- Performing Test GL_HEADER_HAS_GLUINT64 -- Performing Test GL_HEADER_HAS_GLUINT64 - Failed -- 32 bit architecture detected -- Could NOT find Freetype (missing: FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS) -- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR) -- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR JPEG_LIBRARIES) -- Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find GDAL (missing: GDAL_LIBRARY GDAL_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR) -- Trying to find DCMTK expecting DCMTKConfig.cmake -- Trying to find DCMTK expecting DCMTKConfig.cmake - failed -- Trying to find DCMTK relying on FindDCMTK.cmake -- Please set DCMTK_DIR and re-run configure (missing: DCMTK_config_INCLUDE_DIR DCMTK_dcmdata_INCLUDE_DIR DCMTK_dcmimage_INCLUDE_DIR DCMTK_dcmimgle_INCLUDE_DIR DCMTK_dcmjpeg_INCLUDE_DIR DCMTK_dcmjpls_INCLUDE_DIR DCMTK_dcmnet_INCLUDE_DIR DCMTK_dcmpstat_INCLUDE_DIR DCMTK_dcmqrdb_INCLUDE_DIR DCMTK_dcmsign_INCLUDE_DIR DCMTK_dcmsr_INCLUDE_DIR DCMTK_dcmtls_INCLUDE_DIR DCMTK_ofstd_INCLUDE_DIR DCMTK_oflog_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find GStreamer (missing: GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES GSTREAMER_VERSION GSTREAMER_BASE_INCLUDE_DIRS GSTREAMER_BASE_LIBRARIES GSTREAMER_APP_INCLUDE_DIRS GSTREAMER_APP_LIBRARIES GSTREAMER_PBUTILS_INCLUDE_DIRS GSTREAMER_PBUTILS_LIBRARIES) (found version "") -- Could NOT find SDL2 (missing: SDL2_LIBRARY SDL2_INCLUDE_DIR) -- Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR) -- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR) -- g++ version 5.3.0 -- Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS -- Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS - Success -- Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS -- Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS - Failed -- Performing Test _OPENTHREADS_ATOMIC_USE_SUN -- Performing Test _OPENTHREADS_ATOMIC_USE_SUN - Failed -- Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED -- Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED - Success -- Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC -- Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC - Failed -- Configuring done -- Generating done -- Build files have been written to: D:/OSG/build-win32-debug configure (manquants: DCMTK_config_INCLUDE_DIR DCMTK_dcmdata_INCLUDE_DIR DCMTK_dcmimage_INCLUDE_DIR DCMTK_dcmimgle_INCLUDE_DIR DCMTK_dcmjpeg_INCLUDE_DIR DCMTK_dcmjpls_INCLUDE_DIR DCMTK_dcmnet_INCLUDE_DIR DCMTK_dcmpstat_INCLUDE_DIR DCMTK_dcmqrdb_INCLUDE_DIR DCMTK_dcmsign_INCLUDE_DIR DCMTK_dcmsr_INCLUDE_DIR DCMTK_dcmtls_INCLUDE_DIR DCMTK_ofstd_INCLUDE_DIR DCMTK_oflog_INCLUDE_DIR) -- The C compiler identification is GNU 5.3.0 -- The CXX compiler identification is GNU 5.3.0 -- Check for working C compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/gcc.exe -- Check for working C compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/gcc.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/g++.exe -- Check for working CXX compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/g++.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - found -- Found Threads: TRUE -- Found OpenGL: opengl32 -- Could NOT find EGL (missing: EGL_INCLUDE_DIR) -- Checking windows version... -- Performing Test GL_HEADER_HAS_GLINT64 -- Performing Test GL_HEADER_HAS_GLINT64 - Failed -- Performing Test GL_HEADER_HAS_GLUINT64 -- Performing Test GL_HEADER_HAS_GLUINT64 - Failed -- 32 bit architecture detected -- Could NOT find Freetype (missing: FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS) -- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR) -- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR JPEG_LIBRARIES) -- Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find GDAL (missing: GDAL_LIBRARY GDAL_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR) -- Trying to find DCMTK expecting DCMTKConfig.cmake -- Trying to find DCMTK expecting DCMTKConfig.cmake - failed -- Trying to find DCMTK relying on FindDCMTK.cmake -- Please set DCMTK_DIR and re-run configure (missing: DCMTK_config_INCLUDE_DIR DCMTK_dcmdata_INCLUDE_DIR DCMTK_dcmimage_INCLUDE_DIR DCMTK_dcmimgle_INCLUDE_DIR DCMTK_dcmjpeg_INCLUDE_DIR DCMTK_dcmjpls_INCLUDE_DIR DCMTK_dcmnet_INCLUDE_DIR DCMTK_dcmpstat_INCLUDE_DIR DCMTK_dcmqrdb_INCLUDE_DIR DCMTK_dcmsign_INCLUDE_DIR DCMTK_dcmsr_INCLUDE_DIR DCMTK_dcmtls_INCLUDE_DIR DCMTK_ofstd_INCLUDE_DIR DCMTK_oflog_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find GStreamer (missing: GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES GSTREAMER_VERSION GSTREAMER_BASE_INCLUDE_DIRS GSTREAMER_BASE_LIBRARIES GSTREAMER_APP_INCLUDE_DIRS GSTREAMER_APP_LIBRARIES GSTREAMER_PBUTILS_INCLUDE_DIRS GSTREAMER_PBUTILS_LIBRARIES) (found version "") -- Could NOT find SDL2 (missing: SDL2_LIBRARY SDL2_INCLUDE_DIR) -- Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR) -- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR) -- g++ version 5.3.0 -- Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS -- Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS - Success -- Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS -- Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS - Failed -- Performing Test _OPENTHREADS_ATOMIC_USE_SUN -- Performing Test _OPENTHREADS_ATOMIC_USE_SUN - Failed -- Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED -- Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED - Success -- Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC -- Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC - Failed -- Configuring done -- Generating done -- Build files have been written to: D:/OSG/build-win32-debug de -- The C compiler identification is GNU 5.3.0 -- The CXX compiler identification is GNU 5.3.0 -- Check for working C compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/gcc.exe -- Check for working C compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/gcc.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/g++.exe -- Check for working CXX compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/g++.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - found -- Found Threads: TRUE -- Found OpenGL: opengl32 -- Could NOT find EGL (missing: EGL_INCLUDE_DIR) -- Checking windows version... -- Performing Test GL_HEADER_HAS_GLINT64 -- Performing Test GL_HEADER_HAS_GLINT64 - Failed -- Performing Test GL_HEADER_HAS_GLUINT64 -- Performing Test GL_HEADER_HAS_GLUINT64 - Failed -- 32 bit architecture detected -- Could NOT find Freetype (missing: FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS) -- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR) -- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR JPEG_LIBRARIES) -- Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find GDAL (missing: GDAL_LIBRARY GDAL_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR) -- Trying to find DCMTK expecting DCMTKConfig.cmake -- Trying to find DCMTK expecting DCMTKConfig.cmake - failed -- Trying to find DCMTK relying on FindDCMTK.cmake -- Please set DCMTK_DIR and re-run configure (missing: DCMTK_config_INCLUDE_DIR DCMTK_dcmdata_INCLUDE_DIR DCMTK_dcmimage_INCLUDE_DIR DCMTK_dcmimgle_INCLUDE_DIR DCMTK_dcmjpeg_INCLUDE_DIR DCMTK_dcmjpls_INCLUDE_DIR DCMTK_dcmnet_INCLUDE_DIR DCMTK_dcmpstat_INCLUDE_DIR DCMTK_dcmqrdb_INCLUDE_DIR DCMTK_dcmsign_INCLUDE_DIR DCMTK_dcmsr_INCLUDE_DIR DCMTK_dcmtls_INCLUDE_DIR DCMTK_ofstd_INCLUDE_DIR DCMTK_oflog_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find GStreamer (missing: GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES GSTREAMER_VERSION GSTREAMER_BASE_INCLUDE_DIRS GSTREAMER_BASE_LIBRARIES GSTREAMER_APP_INCLUDE_DIRS GSTREAMER_APP_LIBRARIES GSTREAMER_PBUTILS_INCLUDE_DIRS GSTREAMER_PBUTILS_LIBRARIES) (found version "") -- Could NOT find SDL2 (missing: SDL2_LIBRARY SDL2_INCLUDE_DIR) -- Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR) -- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR) -- g++ version 5.3.0 -- Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS -- Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS - Success -- Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS -- Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS - Failed -- Performing Test _OPENTHREADS_ATOMIC_USE_SUN -- Performing Test _OPENTHREADS_ATOMIC_USE_SUN - Failed -- Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED -- Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED - Success -- Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC -- Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC - Failed -- Configuring done -- Generating done -- Build files have been written to: D:/OSG/build-win32-debug GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES GSTREAMER_VERSION GSTREAMER_BASE_INCLUDE_DIRS GSTREAMER_BASE_LIBRARIES GSTREAMER_APP_INCLUDE_DIRS GSTREAMER_APP_LIBRARIES GSTREAMER_PBUTILS_INCLUDE_DIRS GSTREAMER_PBUTILS_LIBRARIES) (version trouvée "") -- The C compiler identification is GNU 5.3.0 -- The CXX compiler identification is GNU 5.3.0 -- Check for working C compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/gcc.exe -- Check for working C compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/gcc.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/g++.exe -- Check for working CXX compiler: C:/Qt/Qt5.11.2/Tools/mingw530_32/bin/g++.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - found -- Found Threads: TRUE -- Found OpenGL: opengl32 -- Could NOT find EGL (missing: EGL_INCLUDE_DIR) -- Checking windows version... -- Performing Test GL_HEADER_HAS_GLINT64 -- Performing Test GL_HEADER_HAS_GLINT64 - Failed -- Performing Test GL_HEADER_HAS_GLUINT64 -- Performing Test GL_HEADER_HAS_GLUINT64 - Failed -- 32 bit architecture detected -- Could NOT find Freetype (missing: FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS) -- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR) -- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR JPEG_LIBRARIES) -- Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find GDAL (missing: GDAL_LIBRARY GDAL_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR) -- Trying to find DCMTK expecting DCMTKConfig.cmake -- Trying to find DCMTK expecting DCMTKConfig.cmake - failed -- Trying to find DCMTK relying on FindDCMTK.cmake -- Please set DCMTK_DIR and re-run configure (missing: DCMTK_config_INCLUDE_DIR DCMTK_dcmdata_INCLUDE_DIR DCMTK_dcmimage_INCLUDE_DIR DCMTK_dcmimgle_INCLUDE_DIR DCMTK_dcmjpeg_INCLUDE_DIR DCMTK_dcmjpls_INCLUDE_DIR DCMTK_dcmnet_INCLUDE_DIR DCMTK_dcmpstat_INCLUDE_DIR DCMTK_dcmqrdb_INCLUDE_DIR DCMTK_dcmsign_INCLUDE_DIR DCMTK_dcmsr_INCLUDE_DIR DCMTK_dcmtls_INCLUDE_DIR DCMTK_ofstd_INCLUDE_DIR DCMTK_oflog_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find GStreamer (missing: GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES GSTREAMER_VERSION GSTREAMER_BASE_INCLUDE_DIRS GSTREAMER_BASE_LIBRARIES GSTREAMER_APP_INCLUDE_DIRS GSTREAMER_APP_LIBRARIES GSTREAMER_PBUTILS_INCLUDE_DIRS GSTREAMER_PBUTILS_LIBRARIES) (found version "") -- Could NOT find SDL2 (missing: SDL2_LIBRARY SDL2_INCLUDE_DIR) -- Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR) -- Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR) -- Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR) -- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR) -- g++ version 5.3.0 -- Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS -- Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS - Success -- Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS -- Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS - Failed -- Performing Test _OPENTHREADS_ATOMIC_USE_SUN -- Performing Test _OPENTHREADS_ATOMIC_USE_SUN - Failed -- Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED -- Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED - Success -- Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC -- Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC - Failed -- Configuring done -- Generating done -- Build files have been written to: D:/OSG/build-win32-debug 



nous dit que vous pouvez commencer l'assemblage. Donnez une commande

 D:\OSG\build-win32-debug>mingw32-make -j9 

vous pouvez, comme dans mon exemple, spécifier le nombre de threads d'assemblage si vous avez un processeur multicœur (commutateur -j). Le processus de construction commencera, prenant environ huit minutes sur mon ordinateur



À la fin de l'assemblage, installez la bibliothèque

 D:\OSG\build-win32-debug> mingw32-make install 

après avoir exécuté la commande, nous trouvons la bibliothèque installée sur le chemin que nous avons précédemment défini



Maintenant, construisons la version finale du moteur en créant un autre répertoire de construction

 D:\OSG\build-win32-debug>cd .. D:\OSG> mkdir build-win32-release D:\OSG>cd build-win32-release D:\OSG\build-win32-release> cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=E:\Apps\OSG ../OpenSceneGraph D:\OSG\build-win32-release> mingw32-make -j9 D:\OSG\build-win32-release> mingw32-make install 

4. DĂ©finition des variables d'environnement


L'emplacement des bibliothèques OSG après l'installation peut être quelconque - il est déterminé par les souhaits d'un utilisateur particulier et sa capacité à placer des fichiers sur un ordinateur. Dans le même temps, lors de la mise en place d'un projet spécifique utilisant des données, la bibliothèque nécessite une certaine unification, abstraite de l'emplacement spécifique des bibliothèques.

Créons quelques variables d'environnement système indiquant les chemins d'accès aux bibliothèques, aux fichiers d'en-tête et aux plugins OSG. Dans mon exemple, cela ressemblera à ceci



Il est nécessaire de créer des variables dont les noms sont encerclés en rouge dans la capture d'écran. Après avoir créé les variables, pour qu'elles soient visibles par les outils de développement, en particulier, QtCreator doit au moins se connecter au système (se déconnecter et se connecter en tant qu'utilisateur actuel) ou, éventuellement, redémarrer le système (c'est Windows!)

Après cela, la procédure d'installation d'OSG sur notre ordinateur peut être considérée comme terminée.

5. Écrire Hello World à QtCreator


Nous allons commencer notre connaissance du moteur graphique OpenSceneGraph avec un exemple simple, comme il est de coutume dans la programmation avec un certain "Hello world!"

Avant d'écrire un code, nous configurerons notre projet pour le système de construction qmake, que nous utiliserons tout au long de la série d'articles. À la place du système de fichiers qui nous intéresse, créez la structure de répertoires suivante

 OSG-lessons/ |-data/ |-OSG-lessons/ | |-hello/ |-include/ |-src/ 

Dans le répertoire hello, créez un fichier hello.pro avec le contenu suivant

Texte intégral hello.pro
 TEMPLATE = app TARGET = hello DESTDIR = ../../bin win32 { OSG_LIB_DIRECTORY = $$(OSG_BIN_PATH) OSG_INCLUDE_DIRECTORY = $$(OSG_INCLUDE_PATH) CONFIG(debug, debug|release) { TARGET = $$join(TARGET,,,_d) LIBS += -L$$OSG_LIB_DIRECTORY -losgd LIBS += -L$$OSG_LIB_DIRECTORY -losgViewerd LIBS += -L$$OSG_LIB_DIRECTORY -losgDBd LIBS += -L$$OSG_LIB_DIRECTORY -lOpenThreadsd } else { LIBS += -L$$OSG_LIB_DIRECTORY -losg LIBS += -L$$OSG_LIB_DIRECTORY -losgViewer LIBS += -L$$OSG_LIB_DIRECTORY -losgDB LIBS += -L$$OSG_LIB_DIRECTORY -lOpenThreads } INCLUDEPATH += $$OSG_INCLUDE_DIRECTORY } unix { CONFIG(debug, debug|release) { TARGET = $$join(TARGET,,,_d) LIBS += -losgd LIBS += -losgViewerd LIBS += -losgDBd LIBS += -lOpenThreadsd } else { LIBS += -losg LIBS += -losgViewer LIBS += -losgDB LIBS += -lOpenThreads } } INCLUDEPATH += ./include HEADERS += $$files(./include/*.h) SOURCES += $$files(./src/*.cpp) 

Nous analyserons ces lettres plus en détail.

 TEMPLATE = app TARGET = hello DESTDIR = ../../bin 


Les variables spécifient le modèle de projet (application - application), le nom du fichier exécutable (bonjour) et le répertoire où l'exécutable est placé après l'assemblage.

 win32 { OSG_LIB_DIRECTORY = $$(OSG_BIN_PATH) OSG_INCLUDE_DIRECTORY = $$(OSG_INCLUDE_PATH) CONFIG(debug, debug|release) { TARGET = $$join(TARGET,,,_d) LIBS += -L$$OSG_LIB_DIRECTORY -losgd LIBS += -L$$OSG_LIB_DIRECTORY -losgViewerd LIBS += -L$$OSG_LIB_DIRECTORY -losgDBd LIBS += -L$$OSG_LIB_DIRECTORY -lOpenThreadsd } else { LIBS += -L$$OSG_LIB_DIRECTORY -losg LIBS += -L$$OSG_LIB_DIRECTORY -losgViewer LIBS += -L$$OSG_LIB_DIRECTORY -losgDB LIBS += -L$$OSG_LIB_DIRECTORY -lOpenThreads } INCLUDEPATH += $$OSG_INCLUDE_DIRECTORY } 

En fonction du système d'exploitation sur lequel le projet est assemblé, nous définissons des variables indiquant les chemins d'accès aux répertoires de la bibliothèque et aux fichiers d'en-tête OSG. C'est là que les variables d'environnement OSG_BIN_PATH et OSG_INCLUDE_PATH sont utiles - maintenant peu importe où la bibliothèque OSG est installée. Quiconque souhaite travailler avec ce projet sur son ordinateur écrira simplement les variables d'environnement appropriées dans son système sans modifier le script de génération.

 CONFIG(debug, debug|release) { TARGET = $$join(TARGET,,,_d) LIBS += -L$$OSG_LIB_DIRECTORY -losgd LIBS += -L$$OSG_LIB_DIRECTORY -losgViewerd LIBS += -L$$OSG_LIB_DIRECTORY -losgDBd LIBS += -L$$OSG_LIB_DIRECTORY -lOpenThreadsd } else { LIBS += -L$$OSG_LIB_DIRECTORY -losg LIBS += -L$$OSG_LIB_DIRECTORY -losgViewer LIBS += -L$$OSG_LIB_DIRECTORY -losgDB LIBS += -L$$OSG_LIB_DIRECTORY -lOpenThreads } 

Écrire un script pour construire dans un système d'exploitation de type Unix

 unix { CONFIG(debug, debug|release) { TARGET = $$join(TARGET,,,_d) LIBS += -losgd LIBS += -losgViewerd LIBS += -losgDBd LIBS += -lOpenThreadsd } else { LIBS += -losg LIBS += -losgViewer LIBS += -losgDB LIBS += -lOpenThreads } } 

Ici, nous configurons le nom du fichier exécutable et spécifions les bibliothèques qui doivent être compilées avec notre programme pour diverses options de construction: à la fois le débogage et la version. Les bibliothèques de débogage OSG ont le suffixe "d" après le nom du fichier. Nous ajouterons le suffixe "_d" au fichier exécutable du projet afin de distinguer l'option de débogage de la version finale.

 INCLUDEPATH += $$OSG_INCLUDE_DIRECTORY INCLUDEPATH += ./include HEADERS += $$files(./include/*.h) SOURCES += $$files(./src/*.cpp) 

Et enfin, nous déterminons les chemins de recherche des fichiers d'en-tête et des fichiers inclus dans l'arborescence du projet. Créez un fichier main.h vide dans le répertoire include / et un fichier main.cpp dans le répertoire src /. Nous ouvrons ce projet dans QtCreator et le configurons comme indiqué dans la capture d'écran



Après l'ouverture du projet, nous verrons l'image suivante



Nous allons Ă©crire ce code dans le fichier main.h

 #ifndef MAIN_H #define MAIN_H #include <osgDB/ReadFile> #include <osgViewer/Viewer> #endif 

Ensuite, nous implémentons le corps principal du programme dans le fichier main.cpp

 #include "main.h" int main(int argc, char *argv[]) { (void) argc; (void) argv; osg::ref_ptr<osg::Node> root = osgDB::readNodeFile("../data/cessna.osg"); osgViewer::Viewer viewer; viewer.setSceneData(root.get()); return viewer.run(); } 

Le fichier de modèle d'avion doit être copié dans le répertoire data /. Ce fichier, ainsi qu'une grande partie de ce qui sera utilisé dans cette série d'articles, peut être téléchargé à partir du référentiel OpenSceneGraph-Data

Après avoir compilé et exécuté, nous obtenons quelque chose comme ça



Les deux premières lignes de notre code

 (void) argc; (void) argv; 

marquer les paramètres d'entrée de la fonction main () comme inutilisés afin d'éviter un avertissement du compilateur. Ensuite, le nœud racine de la scène est créé, qui est le modèle de l'avion chargé à partir du fichier cessna.osg

 osg::ref_ptr<osg::Node> root = osgDB::readNodeFile("../data/cessna.osg"); 

Ensuite, une instance de la classe osgViewer :: Viewer est créée - le soi-disant "viewer" - un objet qui contrôle l'affichage de la scène à l'écran. Les données de scène sont transmises au spectateur

 viewer.setSceneData(root.get()); 

et le cycle de rendu de scène commence

 return viewer.run(); 

Ce code le plus simple contient déjà un certain nombre de concepts de base utilisés dans OSG. Mais en parler ira un peu plus tard.

Conclusion


Le code source complet des exemples décrits ci-après peut être obtenu ici . J'espère que cette publication a intéressé les lecteurs, à suivre ...

Source: https://habr.com/ru/post/fr429816/


All Articles