fixed: compile issue
[opensg.git] / Examples / Tutorial / 04Textures.cpp
bloba42bba7a830e8b602e2f3e89037310fc0c3979cd
1 // all needed include files
2 #ifdef OSG_BUILD_ACTIVE
3 #include <OSGGLUT.h>
4 #include <OSGConfig.h>
5 #include <OSGSimpleGeometry.h>
6 #include <OSGGLUTWindow.h>
7 #include <OSGSimpleSceneManager.h>
9 // these headers are need for textures and images
10 #include <OSGSimpleTexturedMaterial.h>
11 #include <OSGImage.h>
12 #else
13 #include <OpenSG/OSGGLUT.h>
14 #include <OpenSG/OSGConfig.h>
15 #include <OpenSG/OSGSimpleGeometry.h>
16 #include <OpenSG/OSGGLUTWindow.h>
17 #include <OpenSG/OSGSimpleSceneManager.h>
19 // these headers are need for textures and images
20 #include <OpenSG/OSGSimpleTexturedMaterial.h>
21 #include <OpenSG/OSGImage.h>
22 #endif
24 OSG::SimpleSceneManagerRefPtr mgr;
25 OSG::NodeRecPtr scene;
27 int setupGLUT( int *argc, char *argv[] );
29 OSG::NodeRecPtr createScenegraph(void)
31 // the scene must be created here
33 //create the geometry which we will assign a texture to
34 OSG::GeometryRecPtr boxGeo = OSG::makeBoxGeo(10,10,10,1,1,1);
36 //Load the image we want to use as a texture
37 OSG::ImageRecPtr image = OSG::Image::create();
38 image->read("Data/bricks.jpg");
40 //now we create the texture that will hold the image
41 OSG::SimpleTexturedMaterialRecPtr tex =
42 OSG::SimpleTexturedMaterial::create();
44 tex->setImage(image);
46 //now assign the fresh texture to the geometry
47 boxGeo->setMaterial(tex);
49 // Create the node that will hold our geometry
50 OSG::NodeRecPtr n = OSG::Node::create();
51 n->setCore(boxGeo);
53 return OSG::NodeTransitPtr(n);
56 int main(int argc, char **argv)
58 OSG::osgInit(argc,argv);
61 int winid = setupGLUT(&argc, argv);
62 OSG::GLUTWindowRecPtr gwin = OSG::GLUTWindow::create();
63 gwin->setGlutId(winid);
64 gwin->init();
66 scene = createScenegraph();
68 mgr = OSG::SimpleSceneManager::create();
69 mgr->setWindow(gwin );
70 mgr->setRoot (scene);
71 mgr->showAll();
73 OSG::commitChanges();
76 glutMainLoop();
78 return 0;
81 void reshape(int w, int h)
83 mgr->resize(w, h);
84 glutPostRedisplay();
87 void display(void)
89 mgr->redraw();
92 void mouse(int button, int state, int x, int y)
94 if (state)
95 mgr->mouseButtonRelease(button, x, y);
96 else
97 mgr->mouseButtonPress(button, x, y);
99 glutPostRedisplay();
102 void motion(int x, int y)
104 mgr->mouseMove(x, y);
105 glutPostRedisplay();
108 int setupGLUT(int *argc, char *argv[])
110 glutInit(argc, argv);
111 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
113 int winid = glutCreateWindow("OpenSG First Application");
115 glutDisplayFunc(display);
116 glutMouseFunc(mouse);
117 glutMotionFunc(motion);
118 glutReshapeFunc(reshape);
119 glutIdleFunc(display);
121 return winid;