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
| void display(void)
{
actualiseCase(mapLabyrinthe, &caseX, &caseY);
//printf("%d %d %f %f %d\n", caseX, caseY, pos[0], pos[2], *getPixel(mapLabyrinthe, caseX, caseY));
//printf("%f %f %f %f\n", lastx, lasty, xrot, yrot);
//lastx = (int) lastx % 360;
//lasty = (int) lasty % 360;
//glutWarpPointer((int) lastx, (int) lasty);
// Effacement des tampons de couleur et de profondeur
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Sauvegarde de la matrice de transformations
glPushMatrix();
if(skeys[GLUT_KEY_UP])
{
if(*getPixel(mapLabyrinthe, caseX, caseY) == 0)
{
pos[0] = tmpPosition[0];
pos[2] = tmpPosition[2];
return;
}
tmpPosition[0] = pos[0];
tmpPosition[2] = pos[2];
pos[0] += sin(yrot * PIOVER180) * MOVE_STEP;
pos[2] -= cos(yrot * PIOVER180) * MOVE_STEP;
}
else if(skeys[GLUT_KEY_DOWN])
{
if(*getPixel(mapLabyrinthe, caseX, caseY) == 0)
{
pos[0] = tmpPosition[0];
pos[2] = tmpPosition[2];
return;
}
tmpPosition[0] = pos[0];
tmpPosition[2] = pos[2];
pos[0] -= sin(yrot * PIOVER180) * MOVE_STEP;
pos[2] += cos(yrot * PIOVER180) * MOVE_STEP;
}
if(skeys[GLUT_KEY_LEFT])
{
if(*getPixel(mapLabyrinthe, caseX, caseY) == 0)
{
pos[0] = tmpPosition[0];
pos[2] = tmpPosition[2];
return;
}
tmpPosition[0] = pos[0];
tmpPosition[2] = pos[2];
pos[0] -= cos(yrot * PIOVER180) * MOVE_STEP;
pos[2] -= sin(yrot * PIOVER180) * MOVE_STEP;
}
else if(skeys[GLUT_KEY_RIGHT])
{
if(*getPixel(mapLabyrinthe, caseX, caseY) == 0)
{
pos[0] = tmpPosition[0];
pos[2] = tmpPosition[2];
return;
}
tmpPosition[0] = pos[0];
tmpPosition[2] = pos[2];
pos[0] += cos(yrot * PIOVER180) * MOVE_STEP;
pos[2] += sin(yrot * PIOVER180) * MOVE_STEP;
}
// Transformations pour positionner le point de vue du joueur
mouseMovement(lastx, lasty);
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
glTranslated(-pos[0],-pos[1],-pos[2]);
int i, j, pixel;
// Dessin de la scene
for(i = 0; i < mapLabyrinthe->h; i++)
{
for(j = 0; j < mapLabyrinthe->w; j++)
{
pixel = *getPixel(mapLabyrinthe, i, j);
if(pixel != 0)
drawTestScene(i, j, (mapLabyrinthe->rapport) / 2, -((mapLabyrinthe->rapport) / 4));
}
}
// Activer affichage 2D
begin2D();
// Adapter la barre de stats
glPixelZoom((float) DEFAULT_WINDOW_WIDTH / (float) statsLabyrinthe->w, 1.0f);
// Dessin de la barre de stats
glDrawPixels(statsLabyrinthe->w, statsLabyrinthe->h, GL_RGB, GL_UNSIGNED_BYTE, statsLabyrinthe->data);
// Dessin du texte a l'écran
renderString(20.0f, 20.0f, GLUT_BITMAP_HELVETICA_18, "100%", 255.0f, 0.0f, 0.0f, 1.0f);
// Désactivation affichage 2D
end2D();
// Restauration de la matrice de transformations
glPopMatrix();
// Affichage du contenu du tampon de couleur
glutSwapBuffers( );
// On force manuellement un evenement affichage
glutPostRedisplay();
}
void reshape(int w, int h)
{
windowWidth = w;
windowHeight = h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.05f, 0.05f, -0.05f, 0.05f, 0.05f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void begin2D()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, DEFAULT_WINDOW_WIDTH, 0, DEFAULT_WINDOW_HEIGHT, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void end2D()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
void renderString(float x, float y, void* font, char* text, float r, float g, float b, float a)
{
if(!text || !strlen(text))
return;
bool blending = false;
if(glIsEnabled(GL_BLEND))
blending = true;
glEnable(GL_BLEND);
glColor4f(r, g, b, a);
glRasterPos2f(x, y);
while(*text)
{
glutBitmapCharacter(font, *text);
text++;
}
if(!blending)
glDisable(GL_BLEND);
} |
Partager