// FILE: tex_lightdemo_modulate.cpp #include #include #include //Info needed for the images: GLubyte myImage256[256][256][4]; GLuint texName[2]; long depth=0; //used for level of recursion bool wire=true; bool smooth=true; bool image = false; // The vertices of the square: float s1[3] = {-1.0, -1.0, 0.0}; float s2[3] = {1.0, -1.0, 0.0}; float s3[3] = {1.0, 1.0, 0.0}; float s4[3] = {-1.0, 1.0, 0.0}; // The face normal: float norm[3] = {0.0, 0.0, 1.0}; //GLOBAL VARIABLES FOR LIGHT0: GLfloat diff_red, diff_green, diff_blue; //diffuse void loadImages(); void image_on_wall(); void init(); void display(); void normalize(float v[3]); void drawtriangle(float v1[3], float v2[3], float v3[3]); void subdivide(float v1[3], float v2[3], float v3[3], long depth); void drawsurface(); void reshape (int w, int h); void keyboard(unsigned char key, int x, int y); void mykeys(int key, int x, int y); int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (450, 450); glutInitWindowPosition (10, 10); glutCreateWindow (argv[0]); init (); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutSpecialFunc(mykeys); glutMainLoop(); return 0; } void init() { glClearColor (0.0, 0.0, 0.0, 0.0); //Define the material: GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_diffuse[] = {1.0, 1.0, 1.0, 1.0}; GLfloat mat_shininess[] = { 100.0 }; glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); //light diff_red = 1.0; diff_green = 1.0; diff_blue = 1.0; //Global Ambient Light: GLfloat lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); //override default loadImages(); // cout<<"image loaded"< 8) depth = 8; glutPostRedisplay(); break; } } void mykeys(int key, int x, int y) { switch(key){ case GLUT_KEY_LEFT: smooth = false; glutPostRedisplay(); break; case GLUT_KEY_RIGHT: smooth = true; glutPostRedisplay(); break; case GLUT_KEY_DOWN: wire = false; glutPostRedisplay(); break; case GLUT_KEY_UP: wire = true; glutPostRedisplay(); break; case GLUT_KEY_HOME: wire = true; smooth = false; depth = 0; glutPostRedisplay(); break; default: break; } } void loadImages() { int i, j, c; ifstream infile; // infile.open("sunrise_256.ppm"); infile.open("wood_256x256.ppm"); for (j = 0; j < 256; j++) { for (i = 0; i < 256; i++) { infile>>c; myImage256[i][j][0] = (GLubyte) c; infile>>c; myImage256[i][j][1] = (GLubyte) c; infile>>c; myImage256[i][j][2] = (GLubyte) c; myImage256[i][j][3] = (GLubyte) 255; } } infile.close(); }