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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
#include "define.h"
#include "model.h"
#include "sdlglutils.h"
#include "class.h"
bool debug = true;
GLuint modelTexture, solTexture; // Texture des models de la scene
GLuint idBarreOutil, idBarrePerso;//, idInventaire
int x,y,z=-5,filt,tex=1,zbuff=1,fog,rot;
int cube1FaceTexture[6] = {3, 2, 3, 2, 1, 1}; // Tab de choix de texture pour une face
int cube2FaceTexture[6] = {1, 1, 1, 1, 1, 1};
int pyramide1FaceTexture[6] = {4, 4, 4, 4, 4, 0};
float fogcolor[4] = {0.5f,0.5f,0.5f,1};
bool afficherFenetre1 = false, afficherFenetre2 = false;
// polices
C_police* arial_16;
C_police* arial_12;
C_fenetre* fenetre1;
C_fenetre* fenetre2;
void DessinerSol();
int main(int argc, char *argv[])
{
SDL_Event event;
SDL_Color couleurTexte = {0, 0, 0}, couleurFond = {155, 155, 155};
C_model *Pmodel[3];
GLuint fenetre1Texture;
GLuint fenetre2Texture;
bool afficheFenetre1 = false;
bool afficheFenetre2 = false;
//void DessinerMenu(GLunint *textGL[], GLunint *menuFondGL, SDL_Rect *positionTexte[]);
if(TTF_Init() == -1)
{
fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
if (SDL_Init(SDL_INIT_VIDEO) == -1) // Initialisation de la SDL avec gestion d'echec
{
fprintf(stderr, "Erreur d'initialisation de la SDL");
exit(EXIT_FAILURE);
}
atexit(SDL_Quit);
SDL_WM_SetCaption("SDL GL Application", NULL);
SDL_SetVideoMode( LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_OPENGL | SDL_FULLSCREEN);
arial_16 = new C_police(ARIAL, 16);
arial_12 = new C_police(ARIAL, 12);
// Données pour "fenetre1"
string nomFenetre1 = "Fenetre1";
int nbreLigneFenetre1 = 4;
string tabTexteFenetre1[] = { "TITRE 1",
"Sous-titre 1",
"blablabla",
"mais tu sais dire que bla" };
int tabXFenetre1[] = {115, 115, 270, 270};
int tabYFenetre1[] = {462, 446, 123, 123};
C_police *tabPoliceFenetre1[] = { arial_16, arial_16, arial_12, arial_12};
// Données pour "fenetre2"
string nomFenetre2 = "Fenetre2";
int nbreLigneFenetre2 = 6;
string tabTexteFenetre2[] = { "TITRE 2",
"Sous-titre 2",
"riri", "fifi", "loulou",
"et le reste de la bande"};
int tabXFenetre2[] = {115, 115, 270, 270, 270, 270};
int tabYFenetre2[] = {462, 446, 364, 348, 332, 316};
C_police *tabPoliceFenetre2[] = { arial_16, arial_16, arial_12, arial_12,
arial_12, arial_12 };
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective(70,(double)LARGEUR_FENETRE/HAUTEUR_FENETRE,1,1000);
glEnable(GL_DEPTH_TEST); // Active le Z_Buffer
glEnable(GL_TEXTURE_2D);
// Chargement des textures de models
modelTexture = loadTexture("images/maTexture.jpg",0);
solTexture = loadTexture("images/herbe.jpg",0);
// Chargement des textures d'interface
fenetre1Texture = loadTexture("images/fenetre1.png",0);
fenetre2Texture = loadTexture("images/fenetre2.png",0);
// Initialisation fenetres 1 et 2
fenetre1 = new C_fenetre( nomFenetre1, fenetre1Texture, 0.9f,
tabTexteFenetre1, nbreLigneFenetre1, 0, 0,
tabPoliceFenetre1, tabXFenetre1, tabYFenetre1);
fenetre2 = new C_fenetre( nomFenetre2, fenetre2Texture, 0.9f,
tabTexteFenetre2, nbreLigneFenetre2, 0, 0,
tabPoliceFenetre2, tabXFenetre2, tabYFenetre2);
// boucle infinie
for (;;)
{
// Boucle d'evenement
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
exit(0);
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_c:
afficherFenetre1 = !afficherFenetre1;
if (afficherFenetre2) afficherFenetre2 = 0;
break;
case SDLK_v:
afficherFenetre2 = !afficherFenetre2;
if (afficherFenetre1) afficherFenetre1 = 0;
break;
case SDLK_ESCAPE:
exit(0);
break;
default :
break;
}
break;
}
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Reinitialise Pixel_Buffer et Z_buffer
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
gluLookAt(0,-50,20,0,0,0,0,0,1);
// Affichage de tous les elements
DessinerSol();
//DessinerObjets(Pmodel);
if (afficherFenetre1)
{
fenetre1->_afficheFenetre();
}
if (afficherFenetre2)
{
fenetre2->_afficheFenetre();
}
// Mise à jour affichage
glFlush();
SDL_GL_SwapBuffers();
}
}
fenetre1->~C_fenetre();
fenetre2->~C_fenetre();
arial_16->~C_police();
arial_12->~C_police();
glDeleteTextures(1, &modelTexture);
glDeleteTextures(1, &solTexture);
glDeleteTextures(1, &fenetre1Texture);
glDeleteTextures(1, &fenetre2Texture);
TTF_Quit();
SDL_Quit();
return 0;
}
void DessinerSol()
{
// SOL
glBindTexture(GL_TEXTURE_2D, solTexture); // Appel de la texture pour le sol
glBegin(GL_QUADS);
glTexCoord2i(0,0);
glVertex3i(LARGEUR_TERRAIN/-2,PROFONDEUR_TERRAIN/-2,-1);
glTexCoord2i(LARGEUR_TERRAIN,0);
glVertex3i(LARGEUR_TERRAIN/2,PROFONDEUR_TERRAIN/-2,-1);
glTexCoord2i(LARGEUR_TERRAIN,PROFONDEUR_TERRAIN);
glVertex3i(LARGEUR_TERRAIN/2,PROFONDEUR_TERRAIN/2,-1);
glTexCoord2i(0,PROFONDEUR_TERRAIN);
glVertex3i(LARGEUR_TERRAIN/-2,PROFONDEUR_TERRAIN/2,-1);
glEnd();
if (debug) fprintf(stderr,"affichage sol : ok\n");
} |