// // // // // Lab. Calcolo II - Esempio di codice // // // // // // // // Example code: Create one sphere in a 3D GL-based "examiner". #include <glutm/master.h> #include <glutm/main.h> #include <glutm/winexam.h> #include <glutm/shape.h> #include <glt/gl.h> #include <glt/error.h> #include <glt/light.h> #include <glt/lightm.h> #include <glt/material.h> #include <glt/color.h> #include <glt/rgb.h> #include <iostream> #include <cmath> class SpherodromeWindow : public GlutWindowExaminer { public: SpherodromeWindow ( int width = widthDefault, int height = heightDefault, int x = xDefault, int y = yDefault ); ~SpherodromeWindow(); void OnOpen(); void OnClose(); void OnDisplay(); private: GlutSphere m_test_sphere; }; // Note: Certain versions of freeglut render object depth incorrectly // if no depth buffering (GLUT_DEPTH) is selected. SpherodromeWindow::SpherodromeWindow(int width,int height,int x,int y) : GlutWindowExaminer("The Spherodrome (TM)",width,height,x,y,GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA), m_test_sphere(true,0.2,10,10) { m_test_sphere.color() = red; m_test_sphere.position(Vector(0,0,0),m_test_sphere.radius()); } SpherodromeWindow::~SpherodromeWindow() { } void SpherodromeWindow::OnOpen() { glEnable(GL_NORMALIZE); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glDisable(GL_DITHER); glCullFace(GL_BACK); glClearDepth(1.0); glDepthRange(0.0,1.0); glLoadIdentity(); GLERROR; black.glClearColor(); GltLight light0(GL_LIGHT0); light0.ambient() = GltColor(0.1, 0.1, 0.1, 1.0); light0.specular() = GltColor(0.5, 0.5, 0.5, 0.0); light0.position() = Vector(0, 0, 0.8); light0.enabled() = true; light0.set(); rubyMaterial.set(); GltLightModel lightModel; lightModel.setAmbient(0.0, 0.0, 0.0, 0.0); lightModel.setLocalViewer(GL_FALSE); lightModel.setTwoSide(GL_TRUE); GLERROR; glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH); postRedisplay(); } void SpherodromeWindow::OnClose() { } void SpherodromeWindow::OnDisplay() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_test_sphere.draw(); } bool GlutMain(const std::vector<std::string> &arg) { GlutWindow *main = new SpherodromeWindow(500,500,0,0); main->open(); return true; }