Debian Codegraph @

apps/examples/Mentor/CXX/06.1.Text.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 1.
40 *
41 * This example renders a globe and uses 2D text to label the
42 * continents Africa and Asia.
43 *------------------------------------------------------------*/
44
45 #include <cstdlib>
46 #include <Inventor/nodes/SoComplexity.h>
47 #include <Inventor/nodes/SoFont.h>
48 #include <Inventor/nodes/SoGroup.h>
49 #include <Inventor/nodes/SoSeparator.h>
50 #include <Inventor/nodes/SoSphere.h>
51 #include <Inventor/nodes/SoText2.h>
52 #include <Inventor/nodes/SoTexture2.h>
53 #include <Inventor/nodes/SoTranslation.h>
54
55 #include <Inventor/nodes/SoTexture2Transform.h>
56
57 #include <Inventor/Xt/SoXt.h>
58 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
59
60 int
61 main(int argc, 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(24.0);
73 root->addChild(myFont);
74
75 // Add the globe, a sphere with a texture map.
76 // Put it within a separator.
77 SoSeparator *sphereSep = new SoSeparator;
78 SoTexture2 *myTexture2 = new SoTexture2;
79 SoComplexity *sphereComplexity = new SoComplexity;
80 sphereComplexity->value = 0.55;
81 root->addChild(sphereSep);
82 sphereSep->addChild(myTexture2);
83 sphereSep->addChild(sphereComplexity);
84 sphereSep->addChild(new SoSphere);
85 myTexture2->filename = "/usr/share/src/Inventor/examples/data/globe.rgb";
86
87 // Add Text2 for AFRICA, translated to proper location.
88 SoSeparator *africaSep = new SoSeparator;
89 SoTranslation *africaTranslate = new SoTranslation;
90 SoText2 *africaText = new SoText2;
91 africaTranslate->translation.setValue(.25,.0,1.25);
92 africaText->string = "AFRICA";
93 root->addChild(africaSep);
94 africaSep->addChild(africaTranslate);
95 africaSep->addChild(africaText);
96
97 // Add Text2 for ASIA, translated to proper location.
98 SoSeparator *asiaSep = new SoSeparator;
99 SoTranslation *asiaTranslate = new SoTranslation;
100 SoText2 *asiaText = new SoText2;
101 asiaTranslate->translation.setValue(.8,.8,0);
102 asiaText->string = "ASIA";
103 root->addChild(asiaSep);
104 asiaSep->addChild(asiaTranslate);
105 asiaSep->addChild(asiaText);
106
107 SoXtExaminerViewer *myViewer =
108 new SoXtExaminerViewer(myWindow);
109 myViewer->setSceneGraph(root);
110 myViewer->setTitle("2D Text");
111
112 // In Inventor 2.1, if the machine does not have hardware texture
113 // mapping, we must override the default drawStyle to display textures.
114 myViewer->setDrawStyle(SoXtViewer::STILL, SoXtViewer::VIEW_AS_IS);
115
116 myViewer->show();
117 myViewer->viewAll();
118
119 SoXt::show(myWindow);
120 SoXt::mainLoop();
121 }