Debian Codegraph @

apps/examples/Mentor/CXX/17.1.ColorIndex.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 17, example 1.
40 *
41 * This examples shows how the user can create a custom
42 * X visual for doing color index rendering with
43 * an Inventor Viewer. This shows how to create the right
44 * visual, as well as load the color map with the wanted
45 * colors.
46 *-----------------------------------------------------------*/
47
48 #include <cstdlib>
49 #include <Inventor/SoDB.h>
50 #include <Inventor/SoInput.h>
51 #include <Inventor/nodes/SoNode.h>
52 #include <Inventor/Xt/SoXt.h>
53 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
54 #include <GL/glx.h>
55
56 // window attribute list to create a color index visual.
57 // This will create a double buffered color index window
58 // with the maximum number of bits and a zbuffer.
59 int attribList[] = {
60 GLX_DOUBLEBUFFER,
61 GLX_BUFFER_SIZE, 1,
62 GLX_DEPTH_SIZE, 1,
63 None };
64
65 // list of colors to load in the color map
66 static float colors[3][3] = {{.2, .2, .2}, {.5, 1, .5}, {.5, .5, 1}};
67
68 static char *sceneBuffer = "\
69 #Inventor V2.0 ascii\n\
70 \
71 Separator { \
72 LightModel { model BASE_COLOR } \
73 ColorIndex { index 1 } \
74 Coordinate3 { point [ -1 -1 -1, -1 1 -1, 1 1 1, 1 -1 1] } \
75 FaceSet {} \
76 ColorIndex { index 2 } \
77 Coordinate3 { point [ -1 -1 1, -1 1 1, 1 1 -1, 1 -1 -1] } \
78 FaceSet {} \
79 } ";
80
81 int
82 main(int , char **argv)
83 {
84 // Initialize Inventor and Xt
85 Widget myWindow = SoXt::init(argv[0]);
86
87 // read the scene graph in
88 SoInput in;
89 SoNode *scene;
90 in.setBuffer((void *)sceneBuffer, (size_t) strlen(sceneBuffer));
91 if (! SoDB::read(&in, scene) || scene == NULL) {
92 printf("Couldn't read scene\n");
93 exit(1);
94 }
95
96 // create the color index visual
97 XVisualInfo *vis = glXChooseVisual(XtDisplay(myWindow),
98 XScreenNumberOfScreen(XtScreen(myWindow)), attribList);
99 if (! vis) {
100 printf("Couldn't create visual\n");
101 exit(1);
102 }
103
104 // allocate the viewer, set the scene, the visual and
105 // load the color map with the wanted colors.
106 //
107 // Color 0 will be used for the background (default) while
108 // color 1 and 2 are used by the objects.
109 //
110 SoXtExaminerViewer *myViewer = new SoXtExaminerViewer(myWindow);
111 myViewer->setNormalVisual(vis);
112 myViewer->setColorMap(0, 3, (SbColor *) colors);
113 myViewer->setSceneGraph(scene);
114 myViewer->setTitle("Color Index Mode");
115
116 // Show the viewer and loop forever...
117 myViewer->show();
118 XtRealizeWidget(myWindow);
119 SoXt::mainLoop();
120 }