/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Decembre 2005 */ /* Une facette texture avec un damier */ #include #include #include #include #include #include #include "ModuleManipulateur.h" #include "ModuleMenus.h" #include "ModuleReshape.h" static GLbyte *image1 ; static GLbyte *image2 ; static int w2 ; static int h2 ; static int mode = 0; static int deff = 0; static int f1; static int f2; GLbyte *makeImage1() { GLbyte *img =(GLbyte *) calloc(2*2*3,sizeof(GLbyte)); img[2] = img[3] = img[4] = img[6] = img[10] =(GLbyte) 0xFF; return(img); } GLbyte *makeImage2() { GLbyte *img =(GLbyte *) calloc(8*8*3,sizeof(GLbyte)); for ( int l = 0 ; l < 8 ; l++ ) for ( int c = 0 ; c < 8 ; c++ ) if ( (l+c)%2 == 1 ) img[(l*8+c)*3] = img[(l*8+c)*3+1] = img[(l*8+c)*3+2] =(GLbyte) 0xFF; return(img); } void display2() { glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); glRasterPos2i(w2/2-32,h2/2+32); if ( mode ) { glPixelZoom(8.0F,-8.0F); glDrawPixels(8,8,GL_RGB,GL_UNSIGNED_BYTE,image2); } else { glPixelZoom(32.0F,-32.0F); glDrawPixels(2,2,GL_RGB,GL_UNSIGNED_BYTE,image1); } glPopMatrix(); glutSwapBuffers(); } void reshape2(int w,int h) { w2 = w; h2 = h; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,w,0,h,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void display1() { glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); if ( mode ) glTexImage2D(GL_TEXTURE_2D,0,3,8,8,0,GL_RGB,GL_UNSIGNED_BYTE,image2); else glTexImage2D(GL_TEXTURE_2D,0,3,2,2,0,GL_RGB,GL_UNSIGNED_BYTE,image1); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); glBegin(GL_QUADS); glTexCoord2f(0.0F,0.99F); glVertex2f(-1.0F,-0.75F); glTexCoord2f(0.0F,0.0F); glVertex2f(-1.0F,0.75F); glTexCoord2f(( deff == 0 ) ? 1.333333F : 1.0F,0.0F); glVertex2f(1.0F,0.75F); glTexCoord2f(( deff == 0 ) ? 1.333333F : 1.0F,0.99F); glVertex2f(1.0F,-0.75F); glEnd(); glPopMatrix(); glutSwapBuffers(); } void postRedisplay(void) { glutPostWindowRedisplay(f1); glutPostWindowRedisplay(f2); } void key(unsigned char key,int x,int y) { if ( keyManipulateur(key,x,y) ) postRedisplay(); else switch ( key ) { case ' ' : deff = !deff; postRedisplay(); break; case 0x0D : mode = !mode; postRedisplay(); break; } } void myInit1() { image1 = makeImage1(); image2 = makeImage2(); glClearColor(0.75F,0.75F,0.75F,1.0F); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); } void myInit2() { glPixelStorei(GL_UNPACK_ALIGNMENT,1); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } int main(int argc,char **argv) { glutInit(&argc,argv); { glutInitWindowSize(300,250); glutInitWindowPosition(50,50); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); f1 = glutCreateWindow("Rectangle texture"); creationMenuBasique(); myInit1(); setParametresOrthoBasique(-1.5,1.5,-1.5,1.5,-50.0,50.0); setManipulateurDistance(10.0F); glutReshapeFunc(reshapeOrthoBasique); glutDisplayFunc(display1); glutKeyboardFunc(key); glutSpecialFunc(specialBasique); glutMotionFunc(motionBasique); glutMouseFunc(sourisBasique); } { glutInitWindowPosition(450,100); glutInitWindowSize(150,150); f2 = glutCreateWindow("Texture"); creationMenuBasique(); myInit2(); glutKeyboardFunc(key); glutSpecialFunc(specialBasique); glutDisplayFunc(display2); glutReshapeFunc(reshape2); } glutMainLoop(); return(0); }