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
|
int main (int argc, char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA| GLUT_DEPTH );
glutInitWindowSize(W, H);
glutInitWindowPosition(200,100);
glutCreateWindow("Doom-like");
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glClearColor(0,0,0.2,0);
glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
cam.initCam(); // classe cam pour placer la camera
initDraw(); // chargement des sommets listés ds un fichier
glutFullScreen();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutSpecialFunc(clavierDown);
glutSpecialUpFunc(clavierUp);
glutKeyboardFunc(clavier);
glutMouseFunc(mouse);
glutPassiveMotionFunc(bouge);
glutMainLoop();
return 0;
};
// fonction de dessin principale
void display()
{
// le brouillard pour plus tard
// initialisation de la souris
mouse_x = W/2;
mouse_y = H/2;
glutWarpPointer(mouse_x, mouse_y);
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
// calcul de la position de la camera
cam.calculMouvement();
// calcul du point de focus et fait le glutLookAt
cam.fixerCam();
// dessins
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Dessin des axes du repere du monde
glBegin(GL_LINES);
// X
glColor3f(1.0,0.0,0.0);
glVertex3f(0.0,0.0,0.0);
glVertex3f(5.0,0.0,0.0);
// Y
glColor3f(0.0,1.0,0.0);
glVertex3f(0.0,0.0,0.0);
glVertex3f(0.0,5.0,0.0);
// Z
glColor3f(0.0,0.0,1.0);
glVertex3f(0.0,0.0,0.0);
glVertex3f(0.0,0.0,5.0);
glEnd();
// dessin du sol
glColor3f(0.2,0.2,0.2);
dessinSol();
glColor3f(0.4,0.4,0.0);
dessinMur();
// dessin de l'arme
drawArme();
// permutte les tampons d'affichages
glutSwapBuffers();
glutPostRedisplay();
};
/** dessinMur et dessinSol se ressemblent bcps en gros ça donne ça : */
// dessin des murs
void dessinMur()
{
// propriété des murs
float mur_diffuse[4] = {.85,.37,.02,1};
float mur_ambiante[4] = {.2,.2,.2,1};
float mur_speculaire[4] = {.5,.5,.5,1};
float mur_shininess = 40;
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mur_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mur_ambiante);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mur_speculaire);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mur_shininess);
// glBindTexture(GL_TEXTURE_2D,brick_text);
glBegin(GL_QUADS);
for(int i=0; i<mur.nbSom; i+=4)
{
// glTexCoord2i(1,0);
glVertex3f(mur.tab[i].x, mur.tab[i].y, mur.tab[i].z);
// glTexCoord2i(1,1);
glVertex3f(mur.tab[i+1].x, mur.tab[i].y, mur.tab[i+1].z);
// glTexCoord2i(0,1);
glVertex3f(mur.tab[i+2].x, mur.tab[i+2].y,mur.tab[i+2].z);
// glTexCoord2i(0,0);
glVertex3f(mur.tab[i+3].x, mur.tab[i+3].y, mur.tab[i+3].z);
}
glEnd();
glPopMatrix();
}; |
Partager