| 1 | #!/bin/sh |
| 2 | # autopkgtest check |
| 3 | # (C) 2014 Anton Gladky |
| 4 | # (C) 2020 Leopold Palomo-Avellaneda |
| 5 | |
| 6 | set -e |
| 7 | |
| 8 | WORKDIR=$(mktemp -d) |
| 9 | trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM |
| 10 | cd $WORKDIR |
| 11 | cat <<EOF > demo3.cpp |
| 12 | /**************************************************************************\ |
| 13 | * Copyright (c) Kongsberg Oil & Gas Technologies AS |
| 14 | * All rights reserved. |
| 15 | * |
| 16 | * Redistribution and use in source and binary forms, with or without |
| 17 | * modification, are permitted provided that the following conditions are |
| 18 | * met: |
| 19 | * |
| 20 | * Redistributions of source code must retain the above copyright notice, |
| 21 | * this list of conditions and the following disclaimer. |
| 22 | * |
| 23 | * Redistributions in binary form must reproduce the above copyright |
| 24 | * notice, this list of conditions and the following disclaimer in the |
| 25 | * documentation and/or other materials provided with the distribution. |
| 26 | * |
| 27 | * Neither the name of the copyright holder nor the names of its |
| 28 | * contributors may be used to endorse or promote products derived from |
| 29 | * this software without specific prior written permission. |
| 30 | * |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 36 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 37 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 38 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 39 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 40 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 42 | \**************************************************************************/ |
| 43 | |
| 44 | // glutiv.cpp -- example demonstrating Coin (or Open Inventor) bound |
| 45 | // to the GLUT user interface abstraction. |
| 46 | // |
| 47 | |
| 48 | // If you have Coin and the GLUT library properly installed, you should |
| 49 | // be able to build by simply doing: |
| 50 | // |
| 51 | // $ coin-config --build glutiv glutiv.cpp -lglut |
| 52 | // |
| 53 | // (or -lglut32 if you're on MSWindows with Cygwin). |
| 54 | // |
| 55 | // Note that to compile on Mac OS X, you have to link against the |
| 56 | // GLUT framework, like so: |
| 57 | // |
| 58 | // $ export LDFLAGS="-framework GLUT -lobjc" |
| 59 | // $ coin-config --build-app glutiv glutiv.cpp |
| 60 | |
| 61 | |
| 62 | // ************************************************************************* |
| 63 | |
| 64 | // FIXME: note that there are some limitations to this example: |
| 65 | // |
| 66 | // * The most important one is that events are not translated from |
| 67 | // native X11 events to Coin events (to be sent to the scene |
| 68 | // graph). This means that for instance draggers and manipulators in |
| 69 | // the scene graph will not respond to attempts at interaction. |
| 70 | // |
| 71 | // * The sensor queue processing is just a hack. Don't use this |
| 72 | // in production code. |
| 73 | // |
| 74 | // 20031113 mortene. |
| 75 | |
| 76 | // ************************************************************************* |
| 77 | |
| 78 | #ifdef __APPLE__ |
| 79 | #include <GLUT/glut.h> |
| 80 | #else |
| 81 | #include <GL/glut.h> |
| 82 | #endif |
| 83 | |
| 84 | #include <Inventor/SoDB.h> |
| 85 | #include <Inventor/SoInteraction.h> |
| 86 | #include <Inventor/SoSceneManager.h> |
| 87 | #include <Inventor/nodekits/SoNodeKit.h> |
| 88 | #include <Inventor/nodes/SoCylinder.h> |
| 89 | #include <Inventor/nodes/SoDirectionalLight.h> |
| 90 | #include <Inventor/nodes/SoDrawStyle.h> |
| 91 | #include <Inventor/nodes/SoSeparator.h> |
| 92 | #include <Inventor/nodes/SoMaterial.h> |
| 93 | #include <Inventor/nodes/SoPerspectiveCamera.h> |
| 94 | #include <Inventor/nodes/SoRotor.h> |
| 95 | #include <Inventor/nodes/SoShuttle.h> |
| 96 | #include <Inventor/nodes/SoSphere.h> |
| 97 | #include <Inventor/nodes/SoTransform.h> |
| 98 | |
| 99 | // ************************************************************************* |
| 100 | |
| 101 | const int SCENEWINDOWS = 3; |
| 102 | |
| 103 | SoSceneManager * scenemanager[SCENEWINDOWS]; |
| 104 | int glutwin[SCENEWINDOWS]; |
| 105 | |
| 106 | // ************************************************************************* |
| 107 | |
| 108 | int |
| 109 | winid2idx(const int winid) |
| 110 | { |
| 111 | for (int i=0; i < SCENEWINDOWS; i++) { |
| 112 | if (winid == glutwin[i]) return i; |
| 113 | } |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | // Redraw on scenegraph changes. |
| 118 | void |
| 119 | redraw_cb(void * user, SoSceneManager * manager) |
| 120 | { |
| 121 | unsigned int idx = (uintptr_t)user; |
| 122 | |
| 123 | glutSetWindow(glutwin[idx]); |
| 124 | |
| 125 | glEnable(GL_DEPTH_TEST); |
| 126 | glEnable(GL_LIGHTING); |
| 127 | scenemanager[idx]->render(); |
| 128 | |
| 129 | glutSwapBuffers(); |
| 130 | } |
| 131 | |
| 132 | // Redraw on expose events. |
| 133 | void |
| 134 | expose_cb(void) |
| 135 | { |
| 136 | glEnable(GL_DEPTH_TEST); |
| 137 | glEnable(GL_LIGHTING); |
| 138 | scenemanager[winid2idx(glutGetWindow())]->render(); |
| 139 | |
| 140 | glutSwapBuffers(); |
| 141 | } |
| 142 | |
| 143 | // Reconfigure on changes to window dimensions. |
| 144 | void |
| 145 | reshape_cb(int w, int h) |
| 146 | { |
| 147 | int idx = winid2idx(glutGetWindow()); |
| 148 | |
| 149 | scenemanager[idx]->setWindowSize(SbVec2s(w, h)); |
| 150 | scenemanager[idx]->setSize(SbVec2s(w, h)); |
| 151 | scenemanager[idx]->setViewportRegion(SbViewportRegion(w, h)); |
| 152 | scenemanager[idx]->scheduleRedraw(); |
| 153 | } |
| 154 | |
| 155 | // Process the internal Coin queues when idle. Necessary to get the |
| 156 | // animation to work. |
| 157 | void |
| 158 | idle_cb(void) |
| 159 | { |
| 160 | SoDB::getSensorManager()->processTimerQueue(); |
| 161 | SoDB::getSensorManager()->processDelayQueue(TRUE); |
| 162 | } |
| 163 | |
| 164 | // ************************************************************************* |
| 165 | |
| 166 | // Make the common scenegraph. Just a little silly something to show |
| 167 | // off some geometry nodes and simple animation. |
| 168 | |
| 169 | SoSeparator * |
| 170 | commongraph(void) |
| 171 | { |
| 172 | SoSeparator * root = NULL; |
| 173 | |
| 174 | if (!root) { |
| 175 | root = new SoSeparator; |
| 176 | |
| 177 | { |
| 178 | SoSeparator * cylsep = new SoSeparator; |
| 179 | root->addChild(cylsep); |
| 180 | |
| 181 | SoRotor * rotor = new SoRotor; |
| 182 | rotor->speed.setValue(0.1f); |
| 183 | cylsep->addChild(rotor); |
| 184 | |
| 185 | cylsep->addChild(new SoCylinder); |
| 186 | } |
| 187 | |
| 188 | SoMaterial * material = new SoMaterial; |
| 189 | material->diffuseColor.setValue(0.0f, 0.0f, 0.0f); |
| 190 | root->addChild(material); |
| 191 | |
| 192 | SoSphere * sphere = new SoSphere; |
| 193 | |
| 194 | SoTransform * trans0 = new SoTransform; |
| 195 | trans0->translation.setValue(-0.5f, 0.5f, 1.0f); |
| 196 | trans0->scaleFactor.setValue(0.1f, 0.1f, 0.1f); |
| 197 | root->addChild(trans0); |
| 198 | |
| 199 | root->addChild(sphere); |
| 200 | |
| 201 | SoShuttle * shuttle = new SoShuttle; |
| 202 | shuttle->translation0.setValue(0.0f, 5.0f, 0.0f); |
| 203 | shuttle->translation1.setValue(0.0f, -5.0f, 0.0f); |
| 204 | shuttle->on.setValue(TRUE); |
| 205 | root->addChild(shuttle); |
| 206 | |
| 207 | SoTransform * trans1 = new SoTransform; |
| 208 | trans1->translation.setValue(10.0f, 0.0f, 0.0f); |
| 209 | root->addChild(trans1); |
| 210 | |
| 211 | root->addChild(sphere); |
| 212 | } |
| 213 | |
| 214 | return root; |
| 215 | } |
| 216 | |
| 217 | // ************************************************************************* |
| 218 | |
| 219 | #ifdef _WIN32 |
| 220 | |
| 221 | #include <windows.h> |
| 222 | #include <winbase.h> |
| 223 | |
| 224 | int |
| 225 | WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, |
| 226 | int nCmdShow) |
| 227 | |
| 228 | #else // UNIX |
| 229 | |
| 230 | int |
| 231 | main(int argc, char ** argv) |
| 232 | |
| 233 | #endif |
| 234 | |
| 235 | { |
| 236 | // initialize Coin and glut libraries |
| 237 | |
| 238 | SoDB::init(); |
| 239 | SoNodeKit::init(); |
| 240 | SoInteraction::init(); |
| 241 | |
| 242 | #ifdef _WIN32 |
| 243 | int argc = 1; |
| 244 | char * argv[] = { "glutiv.exe", (char *) NULL }; |
| 245 | glutInit(&argc, argv); |
| 246 | #else |
| 247 | glutInit(&argc, argv); |
| 248 | #endif |
| 249 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); |
| 250 | |
| 251 | // Note: _don't_ use SoGroup, as TGS' Inventor has a bug where |
| 252 | // lightsource contribution will get accumulated over runs. |
| 253 | SoSeparator * root[SCENEWINDOWS]; |
| 254 | |
| 255 | for (unsigned int i=0; i < SCENEWINDOWS; i++) { |
| 256 | // set up individual parts of scenegraph |
| 257 | |
| 258 | root[i] = new SoSeparator; |
| 259 | root[i]->ref(); |
| 260 | SoPerspectiveCamera * camera = new SoPerspectiveCamera; |
| 261 | root[i]->addChild(camera); |
| 262 | root[i]->addChild(new SoDirectionalLight); |
| 263 | SoDrawStyle * drawstyle = new SoDrawStyle; |
| 264 | drawstyle->style.setValue(i % 3); |
| 265 | root[i]->addChild(drawstyle); |
| 266 | root[i]->addChild(commongraph()); |
| 267 | |
| 268 | // initialize scenemanager instance |
| 269 | |
| 270 | scenemanager[i] = new SoSceneManager; |
| 271 | scenemanager[i]->setRenderCallback(redraw_cb, (void *)(intptr_t)i); |
| 272 | scenemanager[i]->setBackgroundColor(SbColor(0.2f, 0.2f, i * 0.2f)); |
| 273 | scenemanager[i]->activate(); |
| 274 | camera->viewAll(root[i], scenemanager[i]->getViewportRegion()); |
| 275 | scenemanager[i]->setSceneGraph(root[i]); |
| 276 | |
| 277 | // glut window initialization |
| 278 | |
| 279 | glutInitWindowSize(512, 400); |
| 280 | SbString title("window "); |
| 281 | title += (char)(i + 0x30); |
| 282 | glutwin[i] = glutCreateWindow(title.getString()); |
| 283 | glutDisplayFunc(expose_cb); |
| 284 | glutReshapeFunc(reshape_cb); |
| 285 | } |
| 286 | |
| 287 | SoDB::setRealTimeInterval(1/120.0); |
| 288 | |
| 289 | // start main loop processing (with an idle callback) |
| 290 | |
| 291 | glutIdleFunc(idle_cb); |
| 292 | //glutMainLoop(); |
| 293 | |
| 294 | // clean up Coin resource use |
| 295 | |
| 296 | for (int j=0; j < SCENEWINDOWS; j++) { |
| 297 | root[j]->unref(); |
| 298 | delete scenemanager[j]; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | // ************************************************************************* |
| 305 | |
| 306 | |
| 307 | EOF |
| 308 | cat <<EOF > CMakeLists.txt |
| 309 | cmake_minimum_required(VERSION 3.7) |
| 310 | PROJECT( demo3 ) |
| 311 | |
| 312 | find_package(Coin REQUIRED CONFIG) |
| 313 | include_directories(\${Coin_INCLUDE_DIR}) |
| 314 | add_definitions(\${Coin_DEFINES}) |
| 315 | |
| 316 | find_package(X11 REQUIRED) |
| 317 | include_directories(\${X11_INCLUDE_DIR}) |
| 318 | |
| 319 | set(OpenGL_GL_PREFERENCE "LEGACY") |
| 320 | find_package(OpenGL REQUIRED) |
| 321 | include_directories(\${OPENGL_INCLUDE_DIR}) |
| 322 | |
| 323 | find_package(GLUT REQUIRED) |
| 324 | INCLUDE_DIRECTORIES(\${GLUT_INCLUDE_DIR}) |
| 325 | |
| 326 | add_executable(demo3 demo3.cpp) |
| 327 | target_link_libraries (demo3 \${Coin_LIBRARIES} \${OPENGL_LIBRARIES} \${X11_LIBRARIES} \${GLUT_LIBRARIES}) |
| 328 | EOF |
| 329 | |
| 330 | cmake . |
| 331 | make |
| 332 | [ -x demo3 ] |
| 333 | echo "build: OK" |
| 334 | touch a |
| 335 | xvfb-run -a -s "-screen 0 640x480x24" --auth-file=a ./demo3 && echo run:OK || echo run:Failed |
| 336 |