?? texture.c
字號:
glColor3ub(0, 255, 128); if (wrapt == GL_REPEAT) { drawstr(360, 200, "GL_REPEAT"); } else { drawstr(360, 200, "GL_CLAMP"); } glColor3ub(255, 255, 255); glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");"); glColor3ub(0, 255, 128); if (env == GL_MODULATE) { drawstr(360, 220, "GL_MODULATE"); } else if (env == GL_DECAL) { drawstr(360, 220, "GL_DECAL"); } else if (env == GL_BLEND) { drawstr(360, 220, "GL_BLEND"); } else { drawstr(360, 220, "GL_REPLACE"); } glColor3ub(255, 255, 255); glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");"); setfont("helvetica", 18); cell_draw(&bcolor[0]); cell_draw(&bcolor[1]); cell_draw(&bcolor[2]); cell_draw(&bcolor[3]); cell_draw(&ecolor[0]); cell_draw(&ecolor[1]); cell_draw(&ecolor[2]); cell_draw(&ecolor[3]); if (!selection) { glColor3ub(255, 255, 0); drawstr(10, 525, "Click on the arguments and move the mouse to modify values."); } glutSwapBuffers();}voidpolygon_mouse(int x, int y){/* mouse should only hit _one_ of the cells, so adding up all the hits just propagates a single hit. */ selection += cell_hit(&texcoords[0], x, y); selection += cell_hit(&texcoords[1], x, y); selection += cell_hit(&texcoords[2], x, y); selection += cell_hit(&texcoords[3], x, y); selection += cell_hit(&texcoords[4], x, y); selection += cell_hit(&texcoords[5], x, y); selection += cell_hit(&texcoords[6], x, y); selection += cell_hit(&texcoords[7], x, y); selection += cell_hit(&vertices[0], x, y); selection += cell_hit(&vertices[1], x, y); selection += cell_hit(&vertices[2], x, y); selection += cell_hit(&vertices[3], x, y); selection += cell_hit(&vertices[4], x, y); selection += cell_hit(&vertices[5], x, y); selection += cell_hit(&vertices[6], x, y); selection += cell_hit(&vertices[7], x, y); selection += cell_hit(&vertices[8], x, y); selection += cell_hit(&vertices[9], x, y); selection += cell_hit(&vertices[10], x, y); selection += cell_hit(&vertices[11], x, y); selection += cell_hit(&pcolor[0], x, y); selection += cell_hit(&pcolor[1], x, y); selection += cell_hit(&pcolor[2], x, y); selection += cell_hit(&pcolor[3], x, y);}voidmatrix_mouse(int button, int state, int x, int y){ selection = 0; if (state == GLUT_DOWN) { polygon_mouse(x, y); /* mouse should only hit _one_ of the cells, so adding up all the hits just propagates a single hit. */ selection += cell_hit(&translation[0], x, y); selection += cell_hit(&translation[1], x, y); selection += cell_hit(&translation[2], x, y); selection += cell_hit(&rotation[0], x, y); selection += cell_hit(&rotation[1], x, y); selection += cell_hit(&rotation[2], x, y); selection += cell_hit(&rotation[3], x, y); selection += cell_hit(&scale[0], x, y); selection += cell_hit(&scale[1], x, y); selection += cell_hit(&scale[2], x, y); } old_y = y; redisplay_all();}voidparameters_mouse(int button, int state, int x, int y){ selection = 0; if (state == GLUT_DOWN) { polygon_mouse(x, y); selection += cell_hit(&bcolor[0], x, y); selection += cell_hit(&bcolor[1], x, y); selection += cell_hit(&bcolor[2], x, y); selection += cell_hit(&bcolor[3], x, y); selection += cell_hit(&ecolor[0], x, y); selection += cell_hit(&ecolor[1], x, y); selection += cell_hit(&ecolor[2], x, y); selection += cell_hit(&ecolor[3], x, y); if (!selection) { if (y < 145 && y > 125) { if (minfilter == GL_NEAREST) minfilter = GL_LINEAR; else if (minfilter == GL_LINEAR) minfilter = GL_NEAREST_MIPMAP_NEAREST; else if (minfilter == GL_NEAREST_MIPMAP_NEAREST) minfilter = GL_NEAREST_MIPMAP_LINEAR; else if (minfilter == GL_NEAREST_MIPMAP_LINEAR) minfilter = GL_LINEAR_MIPMAP_NEAREST; else if (minfilter == GL_LINEAR_MIPMAP_NEAREST) minfilter = GL_LINEAR_MIPMAP_LINEAR; else minfilter = GL_NEAREST; } else if (y < 165 && y > 145) { if (magfilter == GL_NEAREST) magfilter = GL_LINEAR; else magfilter = GL_NEAREST; } else if (y < 185 && y > 165) { if (wraps == GL_REPEAT) wraps = GL_CLAMP; else wraps = GL_REPEAT; } else if (y < 205 && y > 185) { if (wrapt == GL_REPEAT) wrapt = GL_CLAMP; else wrapt = GL_REPEAT; } else if (y < 225 && y > 205) { if (env == GL_REPLACE_EXT) env = GL_DECAL; else if (env == GL_DECAL) env = GL_BLEND; else if (env == GL_BLEND) env = GL_MODULATE; else env = GL_REPLACE_EXT; } } } glutSetWindow(screen); texenv(); glutSetWindow(world); texenv(); old_y = y; redisplay_all();}voidcommand_motion(int x, int y){ cell_update(&translation[0], old_y-y); cell_update(&translation[1], old_y-y); cell_update(&translation[2], old_y-y); cell_update(&rotation[0], old_y-y); cell_update(&rotation[1], old_y-y); cell_update(&rotation[2], old_y-y); cell_update(&rotation[3], old_y-y); cell_update(&scale[0], old_y-y); cell_update(&scale[1], old_y-y); cell_update(&scale[2], old_y-y); cell_update(&texcoords[0], old_y-y); cell_update(&texcoords[1], old_y-y); cell_update(&texcoords[2], old_y-y); cell_update(&texcoords[3], old_y-y); cell_update(&texcoords[4], old_y-y); cell_update(&texcoords[5], old_y-y); cell_update(&texcoords[6], old_y-y); cell_update(&texcoords[7], old_y-y); cell_update(&vertices[0], old_y-y); cell_update(&vertices[1], old_y-y); cell_update(&vertices[2], old_y-y); cell_update(&vertices[3], old_y-y); cell_update(&vertices[4], old_y-y); cell_update(&vertices[5], old_y-y); cell_update(&vertices[6], old_y-y); cell_update(&vertices[7], old_y-y); cell_update(&vertices[8], old_y-y); cell_update(&vertices[9], old_y-y); cell_update(&vertices[10], old_y-y); cell_update(&vertices[11], old_y-y); cell_update(&pcolor[0], old_y-y); cell_update(&pcolor[1], old_y-y); cell_update(&pcolor[2], old_y-y); cell_update(&pcolor[3], old_y-y); cell_update(&bcolor[0], old_y-y); cell_update(&bcolor[1], old_y-y); cell_update(&bcolor[2], old_y-y); cell_update(&bcolor[3], old_y-y); cell_update(&ecolor[0], old_y-y); cell_update(&ecolor[1], old_y-y); cell_update(&ecolor[2], old_y-y); cell_update(&ecolor[3], old_y-y); glutSetWindow(screen); texenv(); glutSetWindow(world); texenv(); old_y = y; redisplay_all();}voidtimer(int value){ stipple = 0x00ff << value; if (value > 8) stipple += 0x00ff >> (8-(value-8)); value++; if (value >= 16) value = 0; glutSetWindow(world); glutPostRedisplay(); glutTimerFunc(100, timer, value);}voidredisplay_all(void){ glutSetWindow(command); glutPostRedisplay(); glutSetWindow(world); world_reshape(sub_width, sub_height); glutPostRedisplay(); glutSetWindow(screen); screen_reshape(sub_width, sub_height); glutPostRedisplay();}voidmain_keyboard(unsigned char key, int x, int y){ switch (key) { case 'm': glutSetWindow(command); glutMouseFunc(matrix_mouse); glutDisplayFunc(matrix_display); break; case 'p': glutSetWindow(command); glutMouseFunc(parameters_mouse); glutDisplayFunc(parameters_display); break; case 'r': translation[0].value = 0.0; translation[1].value = 0.0; translation[2].value = 0.0; rotation[0].value = 0.0; rotation[1].value = 0.0; rotation[2].value = 0.0; rotation[3].value = 1.0; scale[0].value = 1.0; scale[1].value = 1.0; scale[2].value = 1.0; texcoords[0].value = 0.0; texcoords[1].value = 0.0; texcoords[2].value = 1.0; texcoords[3].value = 0.0; texcoords[4].value = 1.0; texcoords[5].value = 1.0; texcoords[6].value = 0.0; texcoords[7].value = 1.0; vertices[0].value = -1.0; vertices[1].value = -1.0; vertices[2].value = 0.0; vertices[3].value = 1.0; vertices[4].value = -1.0; vertices[5].value = 0.0; vertices[6].value = 1.0; vertices[7].value = 1.0; vertices[8].value = 0.0; vertices[9].value = -1.0; vertices[10].value = 1.0; vertices[11].value = 0.0; pcolor[0].value = 0.6; pcolor[1].value = 0.6; pcolor[2].value = 0.6; pcolor[3].value = 0.6; bcolor[0].value = 1.0; bcolor[1].value = 0.0; bcolor[2].value = 0.0; bcolor[3].value = 1.0; ecolor[0].value = 0.0; ecolor[1].value = 1.0; ecolor[2].value = 0.0; ecolor[3].value = 1.0; minfilter = GL_NEAREST; magfilter = GL_NEAREST; env = GL_MODULATE; wraps = GL_REPEAT; wrapt = GL_REPEAT; break; case 27: exit(0); } glutSetWindow(screen); texenv(); redisplay_all();}voidcommand_menu(int value){ main_keyboard((unsigned char)value, 0, 0);}intmain(int argc, char** argv){ image = glmReadPPM("data/fishermen.ppm", &iwidth, &iheight); if (!image) exit(0); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize((512+GAP*3)*3/2, 512+GAP*3); glutInitWindowPosition(50, 50); glutInit(&argc, argv); window = glutCreateWindow("Texture"); glutReshapeFunc(main_reshape); glutDisplayFunc(main_display); glutKeyboardFunc(main_keyboard); world = glutCreateSubWindow(window, GAP, GAP, 256, 256); glutReshapeFunc(world_reshape); glutDisplayFunc(world_display); glutKeyboardFunc(main_keyboard); glutCreateMenu(world_menu); glutAddMenuEntry("Textures", 0); glutAddMenuEntry("", 0); glutAddMenuEntry("Fishermen", 'f'); glutAddMenuEntry("OpenGL Logo", 'o'); glutAddMenuEntry("Checker", 'c'); glutAddMenuEntry("Marble", 'm'); glutAddMenuEntry("Train", 't'); glutAttachMenu(GLUT_RIGHT_BUTTON); texture(); screen = glutCreateSubWindow(window, GAP+256+GAP, GAP, 256, 256); glutReshapeFunc(screen_reshape); glutDisplayFunc(screen_display); glutKeyboardFunc(main_keyboard); glutMotionFunc(screen_motion); glutMouseFunc(screen_mouse); texture(); command = glutCreateSubWindow(window, GAP+256+GAP, GAP+256+GAP, 256, 256); glutReshapeFunc(command_reshape); glutMotionFunc(command_motion); glutDisplayFunc(parameters_display); glutMouseFunc(parameters_mouse); glutKeyboardFunc(main_keyboard); glutCreateMenu(command_menu); glutAddMenuEntry("Texture", 0); glutAddMenuEntry("", 0); glutAddMenuEntry("Matrix", 'm'); glutAddMenuEntry("Environment/Parameters", 'p'); glutAddMenuEntry("Reset parameters (r)", 'r'); glutAddMenuEntry("", 0); glutAddMenuEntry("Quit", 27); glutAttachMenu(GLUT_RIGHT_BUTTON); redisplay_all(); glutTimerFunc(500, timer, 0); glutMainLoop(); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -