1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| while (running)
{
// On commence à dessiner notre monde
App.BeginOpenGL();
// Initialisation des valeurs d'effacement pour les tampons de couleur et de profondeur
glClearDepth (1.0f);
// Activation de la lecture et de l'écriture dans le tampon de profondeur
glEnable (GL_DEPTH_TEST);
glDepthMask (GL_TRUE);
glEnable (GL_COLOR_MATERIAL);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
GLfloat LampeDiffuse [] = {1.0f, 1.0f, 1.0f};
GLfloat LampeAmbient [] = {0.75f, 0.75f, 0.75f};
GLfloat LampePosition [] = {6.0f, 10.0f, 5.0f, 1.0f};
glLightfv (GL_LIGHT0, GL_DIFFUSE, LampeDiffuse);
glLightfv (GL_LIGHT0, GL_SPECULAR, LampeDiffuse);
glLightfv (GL_LIGHT0, GL_AMBIENT, LampeAmbient);
glLightfv (GL_LIGHT0, GL_POSITION, LampePosition);
// Initialisation du viewport
glViewport (0, 0, 800, 600);
// Initialisation de la matrice modelview à l'identité
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
// Mise en place d'une projection perspective
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60.0, 800.0 / 600.0, 0.1, 1000.0);
Update();
glClearColor(0.0, 0.5, 0.5, 0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
gluLookAt (0.0f, 0.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
for (size_t i = 0 ; i != NUM_CUBES ; ++i)
myCube[i]->Draw();
for (size_t i = 0 ; i != NUM_SPHERES ; ++i)
mySphere[i]->Draw();
// End OpenGL rendering
App.EndOpenGL();
sfString Text("This is a rotating cube");
//Text.SetLeft(230.f);
//Text.SetTop(300.f);
Text.SetColor(sfColor(128, 0, 128));
App.Draw(Text);
App.Display();
sfEvent appEvent;
while (App.GetEvent (appEvent))
{
// Fermeture de la fenêtre
if (appEvent.Type == sfEvent::Close)
{
running = false;
Delete ();
}
// Appuie de la touche Echap
if ((appEvent.Type == sfEvent::KeyPressed) && (appEvent.Key.Code == sfKey::Escape))
{
running = false;
Delete ();
}
if ((appEvent.Type == sfEvent::KeyPressed) && (appEvent.Key.Code == sfKey::Up))
{
trans += 1.0f;
}
if ((appEvent.Type == sfEvent::KeyPressed) && (appEvent.Key.Code == sfKey::Down))
{
trans -= 1.0f;
}
if ((appEvent.Type == sfEvent::KeyPressed) && (appEvent.Key.Code == sfKey::F1))
{
frustum = !frustum;
}
}
} |