OpenSceneGraph开发环境

yay -S openscenegraph

 CMakeLists.txt

cmake_minimum_required(VERSION 3.17)
project(untitled8)

set(CMAKE_CXX_STANDARD 98)

set(OSG_FILE_PATH ${CMAKE_SOURCE_DIR})
#set(ENV{OSG_FILE_PATH} ${OSG_FILE_PATH})

find_package(OpenSceneGraph COMPONENTS osgUtil osgDB osgViewer osg)
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})

message("===============================================")
message(${OPENSCENEGRAPH_INCLUDE_DIRS})
message(${OPENSCENEGRAPH_LIBRARIES})
message(${CMAKE_CURRENT_BINARY_DIR})
#message($ENV{OSG_FILE_PATH})

#获取cow.osg文件
#wget https://raw.githubusercontent.com/openscenegraph/OpenSceneGraph-Data/6ac81babef49afffc1307cac130d796f56e14ba5/cow.osg
file(COPY ${OSG_FILE_PATH}/cow.osg DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${OPENSCENEGRAPH_LIBRARIES})

main.cpp

#include <iostream>

#include <osgViewer/Viewer>

#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>

#include <osgDB/ReadFile>
#include <osgDB/WriteFile>

#include <osgUtil/Optimizer>


int main() {
    std::cout << "Hello, World!"  << std::endl;

    osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();

    osg::ref_ptr<osg::Group> root = new osg::Group();

    osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("cow.osg");

    root->addChild(node.get());

    osgUtil::Optimizer opt;
    opt.optimize(root.get());

viewer->setUpViewInWindow(50, 50, 800, 600); viewer->setSceneData(root.get()); viewer->realize(); viewer->run(); return 0; }

 目录结构

$ tree .
.
├── cmake-build-debug
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   │   ├── 3.17.3
│   │   │   ├── CMakeCCompiler.cmake
│   │   │   ├── CMakeCXXCompiler.cmake
│   │   │   ├── CMakeDetermineCompilerABI_C.bin
│   │   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   │   ├── CMakeSystem.cmake
│   │   │   ├── CompilerIdC
│   │   │   │   ├── a.out
│   │   │   │   ├── CMakeCCompilerId.c
│   │   │   │   └── tmp
│   │   │   └── CompilerIdCXX
│   │   │       ├── a.out
│   │   │       ├── CMakeCXXCompilerId.cpp
│   │   │       └── tmp
│   │   ├── clion-environment.txt
│   │   ├── clion-log.txt
│   │   ├── cmake.check_cache
│   │   ├── CMakeDirectoryInformation.cmake
│   │   ├── CMakeOutput.log
│   │   ├── CMakeTmp
│   │   ├── Makefile2
│   │   ├── Makefile.cmake
│   │   ├── progress.marks
│   │   ├── TargetDirectories.txt
│   │   └── untitled8.dir
│   │       ├── build.make
│   │       ├── cmake_clean.cmake
│   │       ├── CXX.includecache
│   │       ├── DependInfo.cmake
│   │       ├── depend.internal
│   │       ├── depend.make
│   │       ├── flags.make
│   │       ├── link.txt
│   │       ├── main.cpp.o
│   │       └── progress.make
│   ├── cmake_install.cmake
│   ├── cow.osg
│   ├── Makefile
│   ├── untitled8
│   └── untitled8.cbp
├── CMakeLists.txt
├── cow.osg
└── main.cpp

9 directories, 37 files

 

posted @ 2021-08-25 15:53  zjsxwc  阅读(190)  评论(0)    收藏  举报