//
//
//
//
// Lab. Calcolo II - Esempio di codice
//
//
//
//
//
//
//
// Example code: Create one sphere in a 3D GL-based "examiner".
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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 &arg)
{
GlutWindow *main = new SpherodromeWindow(500,500,0,0);
main->open();
return true;
}