Now add some keyboard events in response to Hello World. // need to add more than two libraries: osgGAd.lib, osgd.lib
code show as below:
#include <osgDB / the ReadFile> #include <the osgViewer / Viewer> #include <the osgViewer / ViewerEventHandlers> #include <osgGA / StateSetManipulator> void main () { the osgViewer :: Viewer Viewer; viewer.setSceneData (osgDB :: readNodeFile ( " Glider .osg " )); // add state event viewer.addEventHandler ( new new osgGA :: StateSetManipulator (viewer.getCamera () -> getOrCreateStateSet ())); // window size change event viewer.addEventHandler ( new new osgViewer :: WindowSizeHandler) ; // add some common status settings viewer.addEventHandler(new osgViewer::StatsHandler); viewer.realize(); viewer.run(); }
Then click on the S key frame is displayed, clicking button displays a grid W, F click key to switch between maximizing and minimizing, click on the button will display a light L. (Wherein the lower case letters correspond to keys)
Renderings:
PS:
If you find that the program can not respond to keyboard input, do not worry, the program is no problem, the problem may be an input method.
Reproduced in: https: //www.cnblogs.com/gattaca/p/4521796.html