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 115 116 117 118 119 120 121
   | //dessine une multitexture correctement, en respectant les altitudes
 void dessine_sol(int x, int y){
    multitexture m;
    int i,j;
    float posi,posj;
 
    //on calcule la multitexture correpondante a HEIGHTMAP[x][y]
    m=mt[HEIGHTMAP[x][y]];
 
    glBindTexture(GL_TEXTURE_2D, m.texchrg);//on utilise la texture qui lui est associee
    glPushMatrix();
        glEnable(GL_TEXTURE_2D);
 
        //pour chaque pixel (i,j) de la multitexture:
        for(i=0 ,posi=taille*x;i<SIZE-2;i++,posi+=pas){
            for(j=0, posj=taille*y;j<SIZE-1;j++,posj+=pas){
 
                //on dessine les deux triangles formés par le carre: (i,j),(i,j+1),(i+1,j),(i+1,j+1)
                glBegin(GL_TRIANGLE_STRIP);
                    glTexCoord2f( ((float) j)/SIZE, ((float) i)/SIZE);
 
                        //l'erreur se situe sur cette ligne (glVertex3f)
                        glVertex3f(posi,m.heightmap[i][j]*alt,posj);
 
                    glTexCoord2f( ((float) j+1)/SIZE, ((float) i)/SIZE);
                        glVertex3f(posi,m.heightmap[i][j+1]*alt,posj+pas);
                    glTexCoord2f( ((float) j+1)/SIZE, ((float) i+1)/SIZE);
                        glVertex3f(posi+pas,m.heightmap[i+1][j+1]*alt,posj+pas);
 
                    glTexCoord2f( ((float) j)/SIZE, ((float) i)/SIZE);
                        glVertex3f(posi,m.heightmap[i][j]*alt,posj);
                    glTexCoord2f( ((float) j+1)/SIZE, ((float) i+1)/SIZE);
                        glVertex3f(posi+pas,m.heightmap[i+1][j+1]*alt,posj+pas);
                    glTexCoord2f( ((float) j)/SIZE, ((float) i+1)/SIZE);
                        glVertex3f(posi+pas,m.heightmap[i+1][j]*alt,posj);
                glEnd();
            }
        }
	glDisable(GL_TEXTURE_2D);
    glPopMatrix();
}
 
//Trouve une multitexture dans les environs, la selectionne pour la dessiner
void choisir_texture(){
    int i,j,x,y;
    x=(int)(xcam/taille);
    y=(int)(ycam/taille);
    for(i=x-5;i<=x+5;i++)
        for(j=y-5;j<=y+5;j++)
            if (HEIGHTMAP[i][j] != 0){
                x=i;
                y=j;
 
                 //La deuxième erreur se trouve sur dessine_sol
                dessine_sol(x,y);
                return;
            }
    dessine_sol(x,y);
    return;
}
 
 
/*fonction d'affichage*/
//dessine tous les elements du programme, repositionne la camera
void display(){
    int i,j;
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
/* Rotation du sol autour d'un axe vertical*/
        glRotatef(angleZ,0.0,0.0,1.0);
        /* Position de la camera */
          gluLookAt(xcam, ycam, zcam, xtarget, ytarget, ztarget, 0.0, 0.0, 1.0);
 
//dessin des sols plats
        for (i=-50;i<N+50;i++)
            for (j=-50;j<N+50;j++)
                if(i<0 || j<0 || i>= N || j>=N)
                dessineSolPlat(i,j,mt[HEIGHTMAP[0][0]]);
                else
                   dessineSolPlat(i,j,mt[HEIGHTMAP[i][j]]);
       //La troisème erreur se situe sur choisir_texture         
        choisir_texture();//selection d'une multitexture et dessine celle-ci en fonction de ses altitudes
        glTranslatef(xtarget,ytarget,ztarget);
        glPushMatrix();
            dessineCiel();
 
glPopMatrix();
    glPopMatrix();
    glFlush();
    FPS();
    glutSwapBuffers();
}
 
 
//Fonction Main
//l'erreur est sur le main
int main(int argc, char *argv[]){
 
    /*creation de la fenetre*/
    glutInit(&argc, argv);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(100,100);
    glutCreateWindow("PAYSAGE NATUREL");
 
    /*Fonctions d'initialisation*/
    init_texture();
    initialiser();
 
    /*Fonctions de rappel*/
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutDisplayFunc(display);
    glutMotionFunc(mouseMotion);
    glutKeyboardFunc(keyboard_1);
    glutSpecialFunc(keyboard_2);
    glutReshapeFunc(reshape);
 
    /*lancement de la boucle d'attente*/
// L'erreur est sur glutMainLoop
    glutMainLoop();
    return 0;
} |