Debian Codegraph @

apps/examples/Mentor/CXX/07.3.TextureFunction.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 7, example 3.
40 *
41 * This example illustrates using texture functions to
42 * generate texture coordinates on a sphere.
43 * It draws three texture mapped spheres, each with a
44 * different repeat frequency as defined by the fields of the
45 * SoTextureCoordinatePlane node.
46 *------------------------------------------------------------*/
47
48 #include <cstdlib>
49 #include <Inventor/nodes/SoMaterial.h>
50 #include <Inventor/nodes/SoSeparator.h>
51 #include <Inventor/nodes/SoSphere.h>
52 #include <Inventor/nodes/SoTexture2.h>
53 #include <Inventor/nodes/SoTexture2Transform.h>
54 #include <Inventor/nodes/SoTextureCoordinatePlane.h>
55 #include <Inventor/nodes/SoTranslation.h>
56
57 #include <Inventor/Xt/SoXt.h>
58 #include <Inventor/Xt/viewers/SoXtExaminerViewer.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 SoSeparator *root = new SoSeparator;
67 root->ref();
68
69 // Choose a texture.
70 SoTexture2 *faceTexture = new SoTexture2;
71 root->addChild(faceTexture);
72 faceTexture->filename.setValue("/usr/share/src/Inventor/examples/data/sillyFace.rgb");
73
74 // Make the diffuse color pure white
75 SoMaterial *myMaterial = new SoMaterial;
76 myMaterial->diffuseColor.setValue(1,1,1);
77 root->addChild(myMaterial);
78
79 // This texture2Transform centers the texture about (0,0,0)
80 SoTexture2Transform *myTexXf = new SoTexture2Transform;
81 myTexXf->translation.setValue(.5,.5);
82 root->addChild(myTexXf);
83
84 // Define a texture coordinate plane node. This one will
85 // repeat with a frequency of two times per unit length.
86 // Add a sphere for it to affect.
87 SoTextureCoordinatePlane *texPlane1 = new SoTextureCoordinatePlane;
88 texPlane1->directionS.setValue(SbVec3f(2,0,0));
89 texPlane1->directionT.setValue(SbVec3f(0,2,0));
90 root->addChild(texPlane1);
91 root->addChild(new SoSphere);
92
93 // A translation node for spacing the three spheres.
94 SoTranslation *myTranslation = new SoTranslation;
95 myTranslation->translation.setValue(2.5,0,0);
96
97 // Create a second sphere with a repeat frequency of 1.
98 SoTextureCoordinatePlane *texPlane2 = new SoTextureCoordinatePlane;
99 texPlane2->directionS.setValue(SbVec3f(1,0,0));
100 texPlane2->directionT.setValue(SbVec3f(0,1,0));
101 root->addChild(myTranslation);
102 root->addChild(texPlane2);
103 root->addChild(new SoSphere);
104
105 // The third sphere has a repeat frequency of .5
106 SoTextureCoordinatePlane *texPlane3 = new SoTextureCoordinatePlane;
107 texPlane3->directionS.setValue(SbVec3f(.5,0,0));
108 texPlane3->directionT.setValue(SbVec3f(0,.5,0));
109 root->addChild(myTranslation);
110 root->addChild(texPlane3);
111 root->addChild(new SoSphere);
112
113 SoXtExaminerViewer *myViewer =
114 new SoXtExaminerViewer(myWindow);
115 myViewer->setSceneGraph(root);
116 myViewer->setTitle("Texture Coordinate Plane");
117
118 // In Inventor 2.1, if the machine does not have hardware texture
119 // mapping, we must override the default drawStyle to display textures.
120 myViewer->setDrawStyle(SoXtViewer::STILL, SoXtViewer::VIEW_AS_IS);
121
122 myViewer->show();
123
124 SoXt::show(myWindow);
125 SoXt::mainLoop();
126 }