Debian Codegraph @

apps/examples/Mentor/CXX/06.3.Complex3DText.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 3.
40 *
41 * This example renders arguments as text within an
42 * SoXTExaminerViewer. It is a little fancier than 6.2.
43 *------------------------------------------------------------*/
44
45 #include <cstdlib>
46 #include <Inventor/Xt/SoXt.h>
47 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
48 #include <Inventor/nodes/SoFont.h>
49 #include <Inventor/nodes/SoGroup.h>
50 #include <Inventor/nodes/SoLinearProfile.h>
51 #include <Inventor/nodes/SoMaterial.h>
52 #include <Inventor/nodes/SoMaterialBinding.h>
53 #include <Inventor/nodes/SoPerspectiveCamera.h>
54 #include <Inventor/nodes/SoProfileCoordinate2.h>
55 #include <Inventor/nodes/SoText3.h>
56
57 int
58 main(int argc, char **argv)
59 {
60
61 Widget myWindow = SoXt::init(argv[0]);
62 if(myWindow == NULL) exit(1);
63
64 SoGroup *root = new SoGroup;
65 root->ref();
66
67 // Set up camera
68 SoPerspectiveCamera *myCamera = new SoPerspectiveCamera;
69 myCamera->position.setValue(0, -(argc - 1) / 2, 10);
70 myCamera->nearDistance.setValue(5.0);
71 myCamera->farDistance.setValue(15.0);
72 root->addChild(myCamera);
73
74 // Let's make the front of the text white,
75 // and the sides and back shiny yellow
76 SoMaterial *myMaterial = new SoMaterial;
77 SbColor colors[3];
78 // diffuse
79 colors[0].setValue(1, 1, 1);
80 colors[1].setValue(1, 1, 0);
81 colors[2].setValue(1, 1, 0);
82 myMaterial->diffuseColor.setValues(0, 3, colors);
83
84 // specular
85 colors[0].setValue(1, 1, 1);
86 // Note: Inventor 2.1 doesn't support multiple specular colors.
87 /*
88 colors[1].setValue(1, 1, 0);
89 colors[2].setValue(1, 1, 0);
90 myMaterial->specularColor.setValues(0, 3, colors);
91 */
92 myMaterial->specularColor.setValue(colors[0]);
93 myMaterial->shininess.setValue(.1);
94 root->addChild(myMaterial);
95
96 // Choose a font likely to exist.
97 SoFont *myFont = new SoFont;
98 myFont->name.setValue("Times-Roman");
99 root->addChild(myFont);
100
101 // Specify a beveled cross-section for the text
102 SoProfileCoordinate2 *myProfileCoords =
103 new SoProfileCoordinate2;
104 SbVec2f coords[4];
105 coords[0].setValue( .00, .00);
106 coords[1].setValue( .25, .25);
107 coords[2].setValue(1.25, .25);
108 coords[3].setValue(1.50, .00);
109 myProfileCoords->point.setValues(0, 4, coords);
110 root->addChild(myProfileCoords);
111
112 SoLinearProfile *myLinearProfile = new SoLinearProfile;
113 int32_t index[4] ;
114 index[0] = 0;
115 index[1] = 1;
116 index[2] = 2;
117 index[3] = 3;
118 myLinearProfile->index.setValues(0, 4, index);
119 root->addChild(myLinearProfile);
120
121 // Set the material binding to PER_PART
122 SoMaterialBinding *myMaterialBinding = new SoMaterialBinding;
123 myMaterialBinding->
124 value.setValue(SoMaterialBinding::PER_PART);
125 root->addChild(myMaterialBinding);
126
127 // Add the text
128 SoText3 *myText3 = new SoText3;
129 myText3->string.setValue("Beveled Text");
130 myText3->justification.setValue(SoText3::CENTER);
131 myText3->parts.setValue(SoText3::ALL);
132
133 root->addChild(myText3);
134
135 SoXtExaminerViewer *myViewer =
136 new SoXtExaminerViewer(myWindow);
137 myViewer->setSceneGraph(root);
138 myViewer->setTitle("Complex 3D Text");
139 myViewer->show();
140 myViewer->viewAll();
141
142 SoXt::show(myWindow);
143 SoXt::mainLoop();
144 }