In previous post I installed the OpenNI SDK and tested some of its samples . I am trying to study something from the sample code and what I've chosen now is the NiSimpleViewer example (which can be found in openni/Samples/NiSimpleViewer).
To avoid messing up the original sample code, I copied the whole directory of NiSimpleViewer and renamed it to mySimpleViewer.
The first work was to compile the source code. Of course the samples included makefiles but they were used for more general and more complicated cases. What I needed was just a simple and self-contained makefile. My first attempt was to simplify the makefile, but unfortunately it's too complicate for me to understand or even to modify it. So I wrote a simple one as the follows (I knew it's unnecessary to do so for such a simple case, but I just wanted to do a bit of exercise on writing makefiles.) :
CC = g++ CFLAGS = -g -Wall LDFLAGS = -lglut -lOpenNI -I /usr/include/ni EXECUTABLE = mySimpleViewer SOURCES = $(EXECUTABLE).cpp OBJECTS = $(EXECUTABLE).o all: $(CC) $(CFLAGS) -o $(EXECUTABLE) $(SOURCES) $(LDFLAGS)
After running mySimpleViewer, the program complained that the file SamplesConfig.xml cannot be found. I checked the source code as well as the files in related directories and found the path should be changed from
../Config/SamplesConfig.xmlIn fact the relative path for the source code to find the xml file is ``../Config'' but not ``../../Config''. This was because the original Makefile putted the binaries in openni/Samples/Bin/Release/ which was one more directory deeper than my test example (thanks to my colleague's reminder).
Also, I modified some #define macros to const type. Based on my knowledge, this would be more ``c++ style''.
const XnChar* SAMPLE_XML_PATH = "../Config/SamplesConfig.xml"; const int GL_WIN_SIZE_X = 1280; const int GL_WIN_SIZE_Y = 1024; const unsigned int DISPLAY_MODE_OVERLAY = 1; const unsigned int DISPLAY_MODE_DEPTH = 2; const unsigned int DISPLAY_MODE_IMAGE = 3; const unsigned int DEFAULT_DISPLAY_MODE = DISPLAY_MODE_DEPTH;---
 Test Kinect in Ubuntu 12.04