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
|
void Moteur3D::afficherScene()
{
dessinerGrille(4);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//Définir la vue de départ
gluLookAt ( 10,10, 10, 0, 1, 0, 0, 1, 0 );
//Changer de buffer
SDL_GL_SwapBuffers();
}
void Moteur3D::dessinerGrille(int largeur)
{
for(int x=-largeur;x<=largeur;x++)
{
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_COLOR);
glBegin(GL_LINES);
glColor4i(255,0,0,0);
glVertex3d(x,0,-largeur);
glVertex3d(x,0,largeur);
glVertex3d(-largeur,0,x);
glVertex3d(largeur,0,x);
glVertex3d(-largeur,x,0);
glVertex3d(largeur,x,0);
glVertex3d(x,-largeur,0);
glVertex3d(x,largeur,0);
glEnd();
//printf("affichage de la grille : %d \n",x);
}
}
void Moteur3D::initialiserAffichage()
{
if(SDL_Init(SDL_INIT_VIDEO)!=0)
{
printf("Initialisation de la vidéo via SDl [ERREUR]\n");
SDL_Quit();
exit(1);
}
else
{
printf("Initialisation de la vidéo via SDl [OK]\n");
}
ecran=SDL_SetVideoMode(resX,resY,nbBitParPixel,SDL_HWSURFACE| /*SDL_FULLSCREEN|*/SDL_OPENGL/*|SDL_NOFRAME*/);
printf("Erreurs SDL : %s\n",SDL_GetError());
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // tell SDL that the GL drawing is going to be double buffered
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24); // size of depth buffer
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); // we aren't going to use the stencil buffer
SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 8); // this and the next three lines set the bits allocated per pixel -
SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 8); // - for the accumulation buffer to 0
SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 8);
SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 8);
if(ecran==NULL)
{
printf("Création de la fenêtre %d x %d x %d [ERREUR]\n",resX,resY,nbBitParPixel);
SDL_Quit();
exit(1);
}
else
{
printf("Création de la fenêtre %d x %d x %d [OK]\n",resX,resY,nbBitParPixel);
}
SDL_WM_SetCaption("Dungeon Hunter","Dungeon Hunter");
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
if ( resY == 0 )
{ //Eviter la division par zéro
resY = 1;
}
gluPerspective ( 45, ( float )resX / resY, 0.1, 10000 );
glMatrixMode ( GL_MODELVIEW );
}
int main(int argc, char *argv[])
{
Moteur3D moteur;
printf("Lancement de Dungeon Hunter\n");
moteur = Moteur3D(640,480,32,100);
moteur.initialiserAffichage();
for(;;)
{
moteur.afficherScene();
}
return 0;
} |
Partager