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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include <GL/glut.h>
#include <iostream>
#include <stdlib.h>
const int LARGEUR_FENETRE = 800;
const int HAUTEUR_FENETRE = 600;
const int LARGSOURIS = 20;
const int HAUTSOURIS = 20;
int g_mx=0, g_my=0;
int g_w, g_h;
double g_anglex=0.0f;
//fonctions ci-dessous servent pour afficher le texte
void reshape(GLint w, GLint h)
{
g_w = w;
g_h = h;
glViewport(0, 0, g_w, g_h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65.0, (float)g_w / g_h, 1, 1000);
glMatrixMode(GL_MODELVIEW);
}
void mousemotion(int x, int y)
{
g_mx = x;
g_my = y;
glutPostRedisplay();
}
//fonctions ci-dessous servent pour afficher le texte
void Graphique_SetOrthographicProjection()
{
//Sauvegarde de la matrice MODELVIEW
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Passer dans le mode projection
glMatrixMode(GL_PROJECTION);
//Sauvegarde de la matrice PROJECTION
glPushMatrix();
glLoadIdentity();
// Mettre en place une perspective orthogonale
gluOrtho2D(0,g_w, g_h, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Graphique_ResetPerspectiveProjection()
{
glMatrixMode(GL_PROJECTION);
//On remet la matrice de PROJECTION
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
//On remet la matrice de MODELVIEW
glPopMatrix();
}
void dessine_souris()
{
Graphique_SetOrthographicProjection();
glColor3f(1.0,1.0,1.0);
glBegin(GL_QUADS);
glVertex2i(g_mx, g_my);
glVertex2i(g_mx+LARGSOURIS, g_my);
glVertex2i(g_mx+LARGSOURIS,g_my + HAUTSOURIS);
glVertex2i(g_mx, g_my+HAUTSOURIS);
glEnd();
Graphique_ResetPerspectiveProjection();
}
void display()
{
// Enleve la couleur
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glColor3f(1.0,1.0,1.0);
//Rendu de la scene
glTranslatef(0.0,0.0,-5.0);
glRotatef(g_anglex,1.0,0.0,0.0);
glutWireTeapot(1);
//Rendu de la souris
dessine_souris();
//On tourne un peu
g_anglex += 0.1;
// On echange les tampon
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitWindowSize (LARGEUR_FENETRE,HAUTEUR_FENETRE);
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow ("Exemple souris");
glutDisplayFunc(display);
glutMotionFunc(mousemotion);
glutPassiveMotionFunc(mousemotion);
glutReshapeFunc(reshape);
glutMainLoop();
return EXIT_SUCCESS;
} |
Partager