Debian Codegraph @

apps/examples/Mentor/CXX/06.2.Simple3DText.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*--------------------------------------------------------------
38 * This is an example from the Inventor Mentor,
39 * chapter 6, example 2.
40 *
41 * This example renders a globe and uses 3D text to label the
42 * continents Africa and Asia.
43 *------------------------------------------------------------*/
44
45 #include <cstdlib>
46 #include <Inventor/Xt/SoXt.h>
47 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
48 #include <Inventor/nodes/SoComplexity.h>
49 #include <Inventor/nodes/SoFont.h>
50 #include <Inventor/nodes/SoGroup.h>
51 #include <Inventor/nodes/SoMaterial.h>
52 #include <Inventor/nodes/SoMaterialBinding.h>
53 #include <Inventor/nodes/SoSeparator.h>
54 #include <Inventor/nodes/SoSphere.h>
55 #include <Inventor/nodes/SoText3.h>
56 #include <Inventor/nodes/SoTexture2.h>
57 #include <Inventor/nodes/SoTransform.h>
58 #include <Inventor/nodes/SoTexture2Transform.h>
59
60 int
61 main(int, char **argv)
62 {
63 Widget myWindow = SoXt::init(argv[0]);
64 if(myWindow == NULL) exit(1);
65
66 SoGroup *root = new SoGroup;
67 root->ref();
68
69 // Choose a font
70 SoFont *myFont = new SoFont;
71 myFont->name.setValue("Times-Roman");
72 myFont->size.setValue(.2);
73 root->addChild(myFont);
74
75 // We'll color the front of the text white, and the sides
76 // dark grey. So use a materialBinding of PER_PART and
77 // two diffuseColor values in the material node.
78 SoMaterial *myMaterial = new SoMaterial;
79 SoMaterialBinding *myBinding = new SoMaterialBinding;
80 myMaterial->diffuseColor.set1Value(0,SbColor(1,1,1));
81 myMaterial->diffuseColor.set1Value(1,SbColor(.1,.1,.1));
82 myBinding->value = SoMaterialBinding::PER_PART;
83 root->addChild(myMaterial);
84 root->addChild(myBinding);
85
86 // Create the globe
87 SoSeparator *sphereSep = new SoSeparator;
88 SoTexture2 *myTexture2 = new SoTexture2;
89 SoComplexity *sphereComplexity = new SoComplexity;
90 sphereComplexity->value = 0.55;
91 root->addChild(sphereSep);
92 sphereSep->addChild(myTexture2);
93 sphereSep->addChild(sphereComplexity);
94 sphereSep->addChild(new SoSphere);
95 myTexture2->filename = "/usr/share/src/Inventor/examples/data/globe.rgb";
96
97 // Add Text3 for AFRICA, transformed to proper location.
98 SoSeparator *africaSep = new SoSeparator;
99 SoTransform *africaTransform = new SoTransform;
100 SoText3 *africaText = new SoText3;
101 africaTransform->rotation.setValue(SbVec3f(0,1,0),.4);
102 africaTransform->translation.setValue(.25,.0,1.25);
103 africaText->parts = SoText3::ALL;
104 africaText->string = "AFRICA";
105 root->addChild(africaSep);
106 africaSep->addChild(africaTransform);
107 africaSep->addChild(africaText);
108
109 // Add Text3 for ASIA, transformed to proper location.
110 SoSeparator *asiaSep = new SoSeparator;
111 SoTransform *asiaTransform = new SoTransform;
112 SoText3 *asiaText = new SoText3;
113 asiaTransform->rotation.setValue(SbVec3f(0,1,0),1.5);
114 asiaTransform->translation.setValue(.8,.6,.5);
115 asiaText->parts = SoText3::ALL;
116 asiaText->string = "ASIA";
117 root->addChild(asiaSep);
118 asiaSep->addChild(asiaTransform);
119 asiaSep->addChild(asiaText);
120
121 SoXtExaminerViewer *myViewer =
122 new SoXtExaminerViewer(myWindow);
123 myViewer->setSceneGraph(root);
124 myViewer->setTitle("3D Text");
125
126 // In Inventor 2.1, if the machine does not have hardware texture
127 // mapping, we must override the default drawStyle to display textures.
128 myViewer->setDrawStyle(SoXtViewer::STILL, SoXtViewer::VIEW_AS_IS);
129
130 myViewer->show();
131 myViewer->viewAll();
132
133 SoXt::show(myWindow);
134 SoXt::mainLoop();
135 }