/* Name: Main.cpp Copyright: Author: Alucards Date: 03/11/04 15:57 Description: OpenGL Template */ //#include //#include #include #include #include "loader.h" #include "loaderBMP.h" using namespace std; GLuint g_ID_texture_bmp[6],g_ID_texture_jpg[6]; int filtering = 0,typetexture = 0; int nbfilter; float xrot,yrot,zrot; void reshape(int w, int h){ glViewport(0,0,(GLsizei) w,(GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(GLfloat) w/(GLfloat)h,0.01,100.0); glMatrixMode(GL_MODELVIEW); } void Init() { nbfilter = 4; glClearColor(0.3, 0.2, 0.7, 0.0); glEnable(GL_COLOR); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); static Loader* loader = (Loader*)LoaderBMP::GetInstance();//creation et init du loader // Charge une texture au format BMP loader = loader->Load("data/unejourneeenenfer.bmp"); if ( loader->IsLoaded()) { //on cree 6 textures glGenTextures(nbfilter, &g_ID_texture_bmp[0]); for(int i = 0; i < nbfilter; i++) { //on recupere les textures chargees de notre loader g_ID_texture_bmp[i] = loader->texID[i]; } } // Charge une texture au format JPG loader = loader->Load("data/Sol.jpg"); if ( loader->IsLoaded()) { //on cree 6 textures glGenTextures(nbfilter, &g_ID_texture_jpg[0]); for(int i = 0; i < nbfilter; i++) { //on recupere les textures chargees de notre loader g_ID_texture_jpg[i] = loader->texID[i]; } } } void keys(int key,int x,int y){ switch(key) { case GLUT_KEY_PAGE_UP : if (filtering>nbfilter-1)filtering=0; break; case GLUT_KEY_PAGE_DOWN : typetexture+=1; if (typetexture>2)typetexture=0; break; } glutPostRedisplay(); } void idleFunc(){ xrot+=0.3f; // X Axis Rotation yrot+=0.2f; // Y Axis Rotation zrot+=0.4f; //Z glutPostRedisplay(); } void display (){ cout<<"la"; glClear (GL_COLOR_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glTranslatef(0.0f,0.0f,-5.0f); // Move Into The Screen 5 Units glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis glRotatef(zrot,0.0f,0.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); switch(typetexture) { case 0: glBindTexture(GL_TEXTURE_2D, g_ID_texture_bmp[filtering]); break; default: glBindTexture(GL_TEXTURE_2D, g_ID_texture_jpg[filtering]); break; } glBegin(GL_QUADS); // Front Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad // Back Face glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad // Top Face glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad // Bottom Face glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad // Right face glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad // Left Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glutPostRedisplay(); glutSwapBuffers(); glEnd(); } int main(int argc, char**argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(250,250); glutInitWindowPosition(100,100); glutCreateWindow("Moulins"); Init(); glutDisplayFunc(display); glutSpecialFunc(keys); glutIdleFunc(idleFunc); glutReshapeFunc(reshape); glutMainLoop(); return 0; }