/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Mars 2003 */ /* Texturage des objets GLUt */ #include #include #include #include #include "ModuleCouleurs.h" #include "ModuleMenus.h" #include "ModuleReshape.h" #include "ModuleManipulateur.h" static int obj = 0; static GLbyte *image ; static int w2 ; static int h2 ; GLbyte *makeRasterImage() { GLbyte *image =(GLbyte *) malloc(16*16*3*sizeof(GLbyte)); for ( int i = 0 ; i < 16 ; i++ ) for ( int j = 0 ; j < 16 ; j++ ) { int p = 3*(j+i*16); if ( i%2 ) image[p] = image[p+1] = image[p+2] = ( j%2 ) ? 0xFF : 0x00 ; else switch (j%4) { case 0 : image[p] = image[p+1] =(GLbyte) 0xFF; image[p+2] = 0x00; break; case 1 : image[p] =(GLbyte) 0xFF; image[p+2] = image[p+1]= 0x00; break; case 2 : image[p+1] =(GLbyte) 0xFF; image[p+2] = image[p]= 0x00; break; case 3 : image[p+2] =(GLbyte) 0xFF; image[p] = image[p+1]= 0x00; break; } } return(image); } void myinit(void) { image = makeRasterImage(); glTexImage2D(GL_TEXTURE_2D,0,3,16,16,0,GL_RGB,GL_UNSIGNED_BYTE,image);; glEnable(GL_TEXTURE_2D); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); GLfloat shinines[] = { 50.0 }; GLfloat l_pos[] = { 1.0,1.0,1.0,0.0 }; glClearColor(0.5F,0.5F,1.0F,1.0F) ; glMaterialfv(GL_FRONT,GL_SPECULAR,couleurBlanc()); glMaterialfv(GL_FRONT,GL_SHININESS,shinines); glLightfv(GL_LIGHT0,GL_POSITION,l_pos); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); } void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); glRotatef(45.0F,0.0F,0.0F,1.0F); switch ( obj ) { case 0 : glFrontFace(GL_CCW); glutSolidSphere(2.0,180,180); break; case 1 : glFrontFace(GL_CCW); glutSolidCube(3.0); break; case 2 : glFrontFace(GL_CCW); glutSolidCone(2.0,2.0,100,100); break; case 3 : glFrontFace(GL_CCW); glutSolidTorus(0.5,2.0,100,100); break; case 4 : glFrontFace(GL_CCW); glScalef(2.5F,2.5F,2.5F); glutSolidTetrahedron(); break; case 5 : glFrontFace(GL_CCW); glScalef(2.5F,2.5F,2.5F); glutSolidOctahedron(); break; case 6 : glFrontFace(GL_CCW); glScalef(2.5F,2.5F,2.5F); glutSolidIcosahedron(); break; case 7 : glFrontFace(GL_CCW); glScalef(1.5F,1.5F,1.5F); glutSolidDodecahedron(); break; case 8 : glFrontFace(GL_CW); glutSolidTeapot(2.0); break; } glPopMatrix(); glFlush(); glutSwapBuffers(); } void key(unsigned char key,int x,int y) { if ( keyManipulateur(key,x,y) ) glutPostRedisplay(); else switch ( key ) { case 0x0D : obj = (obj+1) % 9 ; glutPostRedisplay(); break; } } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); glutInitWindowSize(250,250); glutInitWindowPosition(50,50); glutCreateWindow("Texture sur objet GLUt"); myinit(); creationMenuBasique(); setParametresOrthoBasique(-3.5,3.5,-3.5,3.5,-500.0,500.0); setManipulateurDistance(1.0F); glutReshapeFunc(reshapeOrthoBasique); glutKeyboardFunc(key); glutSpecialFunc(specialBasique); glutMotionFunc(motionBasique); glutMouseFunc(sourisBasique); glutDisplayFunc(display); glutMainLoop(); return(0); }