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
|
#include<windows.h>
#include<GL/gl.h> //OPENGL graphismes
#include<GL/glu.h>
#include<GL/glut.h>
#include<AL/al.h> //OPENAL son
#include<AL/alc.h>
#include<AL/alut.h>
#include<IL/il.h> // chargement des images jpg,bmp,etc...
#include<IL/ilu.h>
#include<IL/ilut.h>
////////////////////////////////////
// STRUCTURE ROUTINES SON
////////////////////////////////////
struct SOUND
{
private:
ALuint Buffer;
ALuint Source;
ALfloat SourcePos[3] ;
ALfloat SourceVel[3] ;
ALfloat ListenerPos[3];
ALfloat ListenerVel[3] ;
ALfloat ListenerOri[6] ;
public :
void load(char *nomfichier)
{
ALenum format;
ALsizei size;
ALvoid* data;
ALsizei freq;
ALboolean loop;
alGenBuffers(1, &Buffer);
alutLoadWAVFile(nomfichier, &format, &data, &size, &freq, &loop);
alBufferData(Buffer, format, data, size, freq);
alutUnloadWAV(format, data, size, freq);
alGenSources(1, &Source);
alSourcei (Source, AL_BUFFER, Buffer );
alSourcef (Source, AL_PITCH, 1.0 );
alSourcef (Source, AL_GAIN, 1.0 );
alSourcefv(Source, AL_POSITION, SourcePos);
alSourcefv(Source, AL_VELOCITY, SourceVel);
alSourcei (Source, AL_LOOPING, loop );
alListenerfv(AL_POSITION, ListenerPos);
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);
}
void erase()
{ alDeleteBuffers(1, &Buffer);
alDeleteSources(1, &Source);
}
void on(){alSourcePlay(Source); }
void off(){alSourceStop(Source); }
void wait(){alSourcePause(Source); }
};
/////////////////////////////////////////////
// STRUCTURE CHARGEMENT IMAGES JPG, BMP,...//
/////////////////////////////////////////////
struct IMAGE
{
unsigned char *adress;
int w,h,format,bpp ;
float x,y ;
ILuint n;
//chagrment d une image, adresse *image
void load(char *nom)
{
ilGenImages(1,&n);
ilBindImage(n);
ilLoadImage(nom);
ilConvertImage(IL_RGB,IL_UNSIGNED_BYTE);
iluFlipImage();
w=ilGetInteger(IL_IMAGE_WIDTH); //largeur
h=ilGetInteger(IL_IMAGE_HEIGHT);//hauteur
format=ilGetInteger(IL_IMAGE_FORMAT);//RGB ...
bpp=ilGetInteger(IL_IMAGE_BPP); //24 bits
adress=ilGetData(); //adresse de l image
}
void on(float xx, float yy)
{ glRasterPos2f(xx,yy);
glDrawPixels(w,h,format,GL_UNSIGNED_BYTE,adress);
x=xx;y=yy;
}
void on()
{ glRasterPos2f(x,y);
glDrawPixels(w,h,format,GL_UNSIGNED_BYTE,adress);
}
void flip() {ilBindImage(n);iluFlipImage();} // image a l envers
void destroy() {ilDeleteImages(1,&n);}
};
/////////////////////////////////////////////
// DECLARATIONS VARIABLES
/////////////////////////////////////////////
struct IMAGE montagne;
struct SOUND essai_son;
unsigned char tch1 ; int tch2; //clavier
int mouse_button,mouse_x,mouse_y; //souris
float colonne;
//////////////////////////////////////////
// DECLARATIONS ROUTINES
//////////////////////////////////////////
void ini_simple(int argvc, char *argv[], char *envp[]);
void affichage();
void mouse(int boutton,int etat,int x, int y);
void keyboard(unsigned char key,int x, int y);
void keyboard(int key,int x,int y);
////////////////////////////////////////////////
// ROUTINES
///////////////////////////////////////////////
void mouse(int button,int etat,int x, int y)
{ //if(button==GLUT_LEFT_BUTTON) ;
//if(button==GLUT_RIGHT_BUTTON) exit(0) ;
//if(button==GLUT_MIDDLE_BUTTON) ;
mouse_button=button;
mouse_x=x;
mouse_y=y;
}
void keyboard(unsigned char key,int x, int y)
{ if(key==27) exit(0); // code ascii ESC
tch1=key ;
}
void keyboard(int key,int x,int y)
{
if(key==GLUT_KEY_RIGHT);
if(key==GLUT_KEY_LEFT);
if(key==GLUT_KEY_DOWN);
if(key==GLUT_KEY_UP);
tch2=key;
}
void changesize(int w, int h){}
////////////////////////////////////////////////
////// MAIN() //////////////////////////////////
////////////////////////////////////////////////
int main(int argvc, char *argv[], char *envp[])
{// initialisation systeme
alutInit(NULL, 0); // son
ilInit();// chargement images
glutInit(&argvc, argv); //GLUT
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);/* affichage couleur */
glutInitWindowSize(1200, 800); /* taille initiale fenetre graphique */
glutInitWindowPosition(200,200); /* position initiale */
glutCreateWindow("window"); /* creation de la fenetre graphique */
montagne.load("image.jpg");
glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
glutKeyboardFunc(keyboard); /* gestion du clavier */
glutSpecialFunc(keyboard);
glutMouseFunc(mouse); /* fonction souris */
glutDisplayFunc(affichage); /* fonction d'affichage */
//glutReshapeFunc(changesize); /* fonction de refenetrage */
//glutIdleFunc(program);
glutMainLoop();
}
void affichage()
{ glClear(GL_COLOR_BUFFER_BIT);
montagne.on(colonne,-1);
glutSwapBuffers();
colonne=colonne+0.1;
if (colonne>1) colonne=-1;
} |
Partager