Ogre1.x study notes 1 - build Ogre project

Ogre1 study notes 1 - build Ogre project


Confucius said: "Run first and then talk."

This article will introduce the general process of building the Ogre project, and the code part adopts Bootstrap.cppthe content in the official one.

This article refers to the official English tutorial Setting up an OGRE project , but uses Makefile to build the Ogre project instead of cmake in the English tutorial.

Copy the code and write Makefile

Bootstrap.cppThe source code of can be found in the Ogre source code, its specific location is in ogre-1.12.6/Samples/Tutorials/Bootstrap.cpp.

When writing Makefile, there are the following points to note:

  1. Several additional library files of Ogre need to be added when linking.
    Here you need to add 4 libraries such as OgreMain, OgreBites, OgreRTShaderSystemand , so you need to add them as parameters.zzip-lOgreMain -lOgreBites -lOgreRTShaderSystem -lzzip
  2. The path that needs to be included zzip.
    zzipIt is a library file generated when compiling and installing the Ogre source code. Its path is ogre-1.12.6/build/Dependencies/lib, so it needs to be added during compilation -L/home/username/Documents/ogre-1.12.6/build/Dependencies/lib. Here /home/username/Documents/is the folder where the Ogre source code is located.
  3. The header file path needs to be added.
    Bootstrap.cppThere are 3 directories where the required header files are located: /usr/include/OGRE/, /usr/include/OGRE/Bites/and , so they need to be added as parameters /usr/include/OGRE/RTShaderSystem/when compiling .-I/usr/include/OGRE/ -I/usr/include/OGRE/Bites/ -I/usr/include/OGRE/RTShaderSystem/
  4. You need to add rpath
    because zzipthe directory where it is located is not a standard location, so you need to add it -rpath, otherwise there will be a problem that the compilation is successful but the runtime reports an error. So it needs to be added as a parameter at compile time -Wl,-rpath /home/username/Documents/ogre-1.12.6/build/Dependencies/lib.

/usr/share/OGRE/In addition, you also need to resources.cfgcopy to the current folder in order to avoid Sinbad.mesherrors not found.

run code

The complete Makefile looks like this:

CXX = g++
CXXFLAGS = -std=c++17 -g -Wall

LIBS = -lOgreMain -lOgreBites -lOgreRTShaderSystem -lzzip 
LIB_PATH = -L/home/username/Documents/ogre-1.12.6/build/Dependencies/lib
RPATH = -Wl,-rpath /home/username/Documents/ogre-1.12.6/build/Dependencies/lib
INCLUDE = -I/usr/include/OGRE/ -I/usr/include/OGRE/Bites/ -I/usr/include/OGRE/RTShaderSystem/

TAR = Bootstrap
EXT = 

$(TAR)$(EXT): $(TAR).cpp
	$(CXX) $< -o $@ $(CXXFLAGS) $(RPATH) $(LIBS) $(LIB_PATH) $(INCLUDE) 
	
clean:
	-rm $(TAR)$(EXT)

At this point, the current folder should look like this:

.
├── Bootstrap.cpp
├── Makefile
└── resources.cfg

Run the code:

make
./Bootstrap

Running result: Press the button
Ogre1 on this screen to exit.Esc

Guess you like

Origin blog.csdn.net/willian113/article/details/106968681