Ticket #26267: RedCone.cpp

File RedCone.cpp, 1.5 KB (added by davidh@…, 14 years ago)

source from http://www-evasion.imag.fr/Membres/Francois.Faure/doc/inventorMentor/sgi_html/ch02.html#id64431

Line 
1// sample source found at http://www-evasion.imag.fr/Membres/Francois.Faure/doc/inventorMentor/sgi_html/ch02.html#id64431
2#include <Inventor/Xt/SoXt.h>
3#include <Inventor/Xt/SoXtRenderArea.h>
4#include <Inventor/nodes/SoCone.h>
5#include <Inventor/nodes/SoDirectionalLight.h>
6#include <Inventor/nodes/SoMaterial.h>
7#include <Inventor/nodes/SoPerspectiveCamera.h>
8#include <Inventor/nodes/SoSeparator.h>
9
10main(int , char **argv)
11{
12   // Initialize Inventor. This returns a main window to use.
13   // If unsuccessful, exit.
14   Widget myWindow = SoXt::init(argv[0]); // pass the app name
15   if (myWindow == NULL) exit(1);
16
17   // Make a scene containing a red cone
18   SoSeparator *root = new SoSeparator;
19   SoPerspectiveCamera *myCamera = new SoPerspectiveCamera;
20   SoMaterial *myMaterial = new SoMaterial;
21   root->ref();
22   root->addChild(myCamera);
23   root->addChild(new SoDirectionalLight);
24   myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0);   // Red
25   root->addChild(myMaterial);
26   root->addChild(new SoCone);
27
28   // Create a renderArea in which to see our scene graph.
29   // The render area will appear within the main window.
30   SoXtRenderArea *myRenderArea = new SoXtRenderArea(myWindow);
31
32   // Make myCamera see everything.
33   myCamera->viewAll(root, myRenderArea->getViewportRegion());
34
35   // Put our scene in myRenderArea, change the title
36   myRenderArea->setSceneGraph(root);
37   myRenderArea->setTitle("Hello Cone");
38   myRenderArea->show();
39
40   SoXt::show(myWindow);  // Display main window
41   SoXt::mainLoop();      // Main Inventor event loop
42}