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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "GestionTextures.h"
#include "Main.h"
#define longueurTexture 256
#define largeurTexture 256
GLuint textureSol;
GLuint test;
double angleRotZ = 0;
int menu;
int figure;
static float blanc[] = { 1.0F,1.0F,1.0F,1.0F };
/* Fonction d'initialisation des parametres */
/* OpenGL ne changeant pas au cours de la vie */
/* du programme */
void init(void) {
glClearColor (0.5f, 0.5f, 0.5f, 1.0f);
glShadeModel (GL_SMOOTH);
//const GLfloat shininess[] = { 50.0 };
//glMaterialfv(GL_FRONT,GL_SPECULAR,blanc);
//glMaterialfv(GL_FRONT,GL_SHININESS,shininess);
//glLightfv(GL_LIGHT0,GL_DIFFUSE,rouge);
//glLightfv(GL_LIGHT1,GL_DIFFUSE,jaune);
//glLightfv(GL_LIGHT2,GL_DIFFUSE,bleu);
//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
//glEnable(GL_LIGHT1);
//glEnable(GL_LIGHT2);
//glEnable(GL_LIGHTING);
//glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
//glEnable(GL_NORMALIZE);
//glEnable(GL_AUTO_NORMAL);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
/*
void initlights(void) {
GLfloat pos[] = { 0.0F,0.0F,-1.0F,0.0F };
GLfloat shininess[] = { 50.0F };
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
//glLightfv(GL_LIGHT0,GL_AMBIENT,couleurGrisFonce());
glLightfv(GL_LIGHT0,GL_DIFFUSE,blanc);
glMaterialfv(GL_FRONT,GL_SPECULAR,blanc);
glMaterialfv(GL_FRONT,GL_SHININESS,shininess);
}
*/
/* Scene dessinee */
void scene(void) {
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, textureSol);
glBegin(GL_QUADS);
glTexCoord2i(0,0); glVertex3i(-30,-30,-1);
glTexCoord2i(10,0); glVertex3i(30,-30,-1);
glTexCoord2i(10,10); glVertex3i(30,30,-1);
glTexCoord2i(0,10); glVertex3i(-30,30,-1);
glEnd();
glBindTexture(GL_TEXTURE_2D, test);
glBegin(GL_QUADS);
glColor3ub (255, 255, 255);
//glColor3ub (0, 0, 0); // coloration des face pour mieux se repérer (rouge)
glTexCoord2d(0,1); glVertex3d(1, 1, 1);
glTexCoord2d(0,0); glVertex3d(1, 1, -1);
glTexCoord2d(1,0); glVertex3d(-1, 1, -1);
glTexCoord2d(1,1); glVertex3d(-1, 1, 1);
glEnd();
glBegin(GL_QUADS);
//glColor3ub (255, 255, 255); // vert
glTexCoord2d(0,1); glVertex3d(1, -1, 1);
glTexCoord2d(0,0); glVertex3d(1, -1, -1);
glTexCoord2d(1,0); glVertex3d(1, 1, -1);
glTexCoord2d(1,1); glVertex3d(1, 1, 1);
glEnd();
glBegin(GL_QUADS);
//glColor3ub (0, 255, 255); // bleu
glTexCoord2d(0,1); glVertex3d(-1, -1, 1);
glTexCoord2d(0,0); glVertex3d(-1, -1, -1);
glTexCoord2d(1,0); glVertex3d(1, -1, -1);
glTexCoord2d(1,1); glVertex3d(1, -1, 1);
glEnd();
glBegin(GL_QUADS);
//glColor3ub (255, 0, 0); // bleu clair
glTexCoord2d(0,1); glVertex3d(-1, 1, 1);
glTexCoord2d(0,0); glVertex3d(-1, 1, -1);
glTexCoord2d(1,0); glVertex3d(-1, -1, -1);
glTexCoord2d(1,1); glVertex3d(-1, -1, 1);
glEnd();
glBegin(GL_QUADS);
//glColor3ub(0,255,255); //face cyan
glTexCoord2d(1,1); glVertex3d(1,1,-1);
glTexCoord2d(0,1); glVertex3d(1,-1,-1);
glTexCoord2d(0,0); glVertex3d(-1,-1,-1);
glTexCoord2d(1,0); glVertex3d(-1,1,-1);
glEnd();
glBegin(GL_QUADS);
//glColor3ub(255,0,255); //face magenta
glTexCoord2d(1,1); glVertex3d(1,-1,1);
glTexCoord2d(0,1); glVertex3d(1,1,1);
glTexCoord2d(0,0); glVertex3d(-1,1,1);
glTexCoord2d(1,0); glVertex3d(-1,-1,1);
glEnd();
glDisable (GL_TEXTURE_2D);
glPopMatrix();
//glEnable(GL_AUTO_NORMAL);
//glEnable(GL_NORMALIZE);
//glShadeModel(GL_SMOOTH);
//glEnable(GL_DEPTH_TEST);
//glDepthFunc(GL_LESS);
//initlights();
}
/* Fonction executee lors d'un rafraichissement */
/* de la fenetre de dessin */
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// placement de la camera sur l'axe Z
gluLookAt(3, 4, 2, 0, 0, 0, 0, 0, 1);
glRotated (angleRotZ, 0, 0, 1);
/*
const GLfloat light0_position[] = { 1.0,1.0,1.0,0.0 };
const GLfloat light1_position[] = { -1.0,1.0,1.0,0.0 };
const GLfloat light2_position[] = { 1.0,-1.0,1.0,0.0 };
glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
glLightfv(GL_LIGHT1,GL_POSITION,light1_position);
glLightfv(GL_LIGHT2,GL_POSITION,light2_position);
glPushMatrix();
if (figure == 1) {
glutSolidSphere(0.6, 20, 20);
}
*/
scene();
//glPopMatrix();
glFlush();
glutSwapBuffers();
}
void rubriquesMenu (int rubrique) {
switch (rubrique) {
case 1 : //glutSolidSphere(1.2, 25, 20);
figure = 1;
break;
}
glutPostRedisplay();
}
void
reshape (int x, int y)
{
glViewport(0,0,x,y);
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity() ;
gluPerspective(80.0F,(float) x/y,1.0,40.0) ;
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity() ;
gluLookAt(0.0,0.0,20.0,0.0,0.0,0.0,0.0,1.0,0.0);
}
/* Fonction principale */
void idle(void) {
angleRotZ += 0.5;
glutPostRedisplay() ;
}
int main(int argc,char **argv) {
glutInit(&argc,argv); // initialisation de glut
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); //DEPTH pour gérer la profondeur | Double pour utiliser les double buffering
glutInitWindowSize(850,600);
glutInitWindowPosition(300,200);
glutCreateWindow("Un labyrinthe en OpenGL");
menu = glutCreateMenu(rubriquesMenu);
glutAddMenuEntry("Option 1", 1);
glutAddMenuEntry("Option 2", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
textureSol = chargementImageTexture("Textures/veg008.jpg");
test = chargementImageTexture("Textures/snow008.jpg");
init();
//glutKeyboardFunc(keyboard); // gestion des evenement clavier
//glutSpecialFunc(manipCylindre); // fonction pour la manipulation du cylindre (touches directionnelles)
glutReshapeFunc(reshape); // fonction a exécuter pour la modification de la taille de fenetre d'affichage
glutIdleFunc(idle); // fonction executer si le programme ne fait rien
glutDisplayFunc(display); // spécifié a glut quelle méthode déssine
glutMainLoop(); // boucle infinie (boucle principal d'affichage)
return(0);
} |
Partager