/* construcorul clasei 'Rubik' care creeaza un nou cub rubik */ Rubik::Rubik() { cs = new CoordinateSystem3d(); WorldDrawer3d::cs_used.push_back(cs); layers.resize(MOVING_LAYERS); faces.resize(MOVING_LAYERS); rubik.resize(3*MOVING_LAYERS); colors.resize(6); set_points(); set_topology(); set_layers(); draw_faces(); int count = 0; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { for (int k = -1; k <= 1; k++) { Object3d *o; o = new Object3d(points, topology); o->setcolor(0,0,0); o->color = -1; rubik[count].push_back(o); for (int l = 0; l < rubik[count].size(); l++) { rubik[count][l]->translate(4.5*i, 4.5*j, 4.5*k); cs->objectAdd(rubik[count][l]); } count++; } } } }
enum piglit_result piglit_display(void) { bool pass = true; GLuint tex; int i; tex = create_texture(); clear_texture(tex); glBindTexture(GL_TEXTURE_CUBE_MAP, tex); draw_faces(); glBindTexture(GL_TEXTURE_CUBE_MAP, 0); glDeleteTextures(1, &tex); for (i = 0; i < 6; i++) pass &= piglit_probe_pixel_rgb(i, 0, faces[i].color); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
void generate( int polygons ) { double knob_value; vary_node *knobs; vary_node vn; char frame_name[128]; if (first_pass()) { knobs = second_pass(); } else { num_frames = 1; } // Default values char color_type = PNG_RGB, shading = GOROUD; int width = 1000, height = 1000, segments = 20; screen s = make_screen(width, height); vertex_list vlist = new_vlist(100); face_list flist = new_flist(100); edge_list elist = new_elist(100); stack coord_systems = new_stack(5); vector center = new_vector(0, 0, 0); vector eye = new_vector(0, 0, 200); double distance = 200; vertex text0, text1; text0.x = -100; text0.y = 0; text0.z = 0; text1.x = 100; text1.y = 0; text1.z = 0; text0.nx = text1.x - text0.x; text0.ny = text1.y - text0.y; text0.nz = text1.z - text0.z; text1.nx = text0.nx * text0.nx + text0.ny * text0.ny + text0.nz * text0.nz; text0.color = rgb(255, 255, 255); text0.shine = 3; text1.color = rgb(255, 0, 255); text1.shine = 3; uint32_t amb_color = rgb(255, 255, 255), light_color = rgb(0, 255, 255), wire_color = rgb(255, 255, 255); vector light_source = new_vector(0, 100, 200); double amb_ref_constant = 0.1, diff_ref_constant = 1, spec_ref_constant = 1; int frame, i, j; double temp; for (frame = 0; frame < num_frames; frame++) { if (num_frames > 1) { for (vn = knobs[frame]; vn != NULL; vn = vn->next) { set_value(lookup_symbol(vn->name), vn->value); } } for (i = 0; i < lastop; i++) { switch (op[i].opcode) { case TEXTURE: text0.x = op[lastop].op.texture.d0[0]; text0.y = op[lastop].op.texture.d0[1]; text0.z = op[lastop].op.texture.d0[2]; text1.x = op[lastop].op.texture.d1[0]; text1.y = op[lastop].op.texture.d1[1]; text1.z = op[lastop].op.texture.d1[2]; text0.nx = text1.x - text0.x; text0.ny = text1.y - text0.y; text0.nz = text1.z - text0.z; text1.nx = text0.nx * text0.nx + text0.ny * text0.ny + text0.nz * text0.nz; text0.color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[2])) ); text0.shine = op[lastop].op.texture.d2[3]; text1.color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[2])) ); text1.shine = op[lastop].op.texture.d3[3]; break; case CAMERA: eye.x = op[lastop].op.camera.eye[0]; eye.y = op[lastop].op.camera.eye[1]; eye.z = op[lastop].op.camera.eye[2]; center.x = eye.x + op[lastop].op.camera.aim[0]; center.y = eye.y + op[lastop].op.camera.aim[1]; center.z = eye.z + op[lastop].op.camera.aim[2]; break; case FOCAL: distance = op[lastop].op.focal.value; break; case AMBIENT: amb_color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[2])) ); break; case LIGHT: light_color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.light.c[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.light.c[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.light.c[2])) ); light_source = new_vector( op[lastop].op.light.l[0], op[lastop].op.light.l[1], op[lastop].op.light.l[2] ); break; case SHADING: if (strcmp(op[i].op.shading.p->name, "GOROUD") == 0) { shading = GOROUD; } else { shading = WIRE; } break; case SPHERE: add_sphere( vlist, elist, flist, op[i].op.sphere.d[0], op[i].op.sphere.d[1], op[i].op.sphere.d[2], op[i].op.sphere.r, segments, text0, text1 ); transform(vlist, peek(coord_systems)); if (shading == GOROUD) { draw_faces( s, vlist, flist, center, eye, distance, amb_color, light_color, light_source, amb_ref_constant, diff_ref_constant, spec_ref_constant ); } else { draw_edges( s, vlist, elist, center, eye, distance, wire_color ); } clear_vlist(vlist); clear_elist(elist); clear_flist(flist); break; case BOX: add_box( vlist, elist, flist, op[i].op.box.d0[0], op[i].op.box.d0[1], op[i].op.box.d0[2], op[i].op.box.d1[0], op[i].op.box.d1[1], op[i].op.box.d1[2], text0, text1 ); transform(vlist, peek(coord_systems)); if (shading == GOROUD) { draw_faces( s, vlist, flist, center, eye, distance, amb_color, light_color, light_source, amb_ref_constant, diff_ref_constant, spec_ref_constant ); } else { draw_edges( s, vlist, elist, center, eye, distance, wire_color ); } clear_vlist(vlist); clear_elist(elist); clear_flist(flist); break; case LINE: add_line( vlist, elist, op[i].op.line.p0[0], op[i].op.line.p0[1], op[i].op.line.p0[2], op[i].op.line.p1[0], op[i].op.line.p1[1], op[i].op.line.p1[2], text0, text1 ); transform(vlist, peek(coord_systems)); draw_edges(s, vlist, elist, center, eye, distance, wire_color); clear_vlist(vlist); clear_elist(elist); break; case MOVE: if (op[i].op.move.p == NULL){ knob_value = 1; } else { knob_value = op[i].op.move.p->s.value; } translate( op[i].op.move.d[0] * knob_value, op[i].op.move.d[1] * knob_value, op[i].op.move.d[2] * knob_value, peek(coord_systems) ); break; case SCALE: if (op[i].op.scale.p == NULL){ knob_value = 1; } else { knob_value = op[i].op.scale.p->s.value; } scale( op[i].op.scale.d[0] * knob_value, op[i].op.scale.d[1] * knob_value, op[i].op.scale.d[2] * knob_value, peek(coord_systems) ); break; case ROTATE: if (op[i].op.rotate.p == NULL){ knob_value = 1; } else { knob_value = op[i].op.rotate.p->s.value; } temp = op[i].op.rotate.axis; if (temp == 0) { rotate_x( op[i].op.rotate.degrees * knob_value, peek(coord_systems) ); } else if (temp == 1) { rotate_y( op[i].op.rotate.degrees * knob_value, peek(coord_systems) ); } else { rotate_z( op[i].op.rotate.degrees * knob_value, peek(coord_systems) ); } break; case SET: set_value( lookup_symbol(op[i].op.set.p->name), op[i].op.set.val ); break; case SETKNOBS: for (j = 0; j < lastsym; j++) { set_value(&symtab[j], op[j].op.setknobs.value); } break; case PUSH: push(coord_systems); break; case POP: pop(coord_systems); break; case SAVE: make_png(op[i].op.save.p->name, s, color_type); break; case DISPLAY: display_png(s, color_type); break; } } if (num_frames > 1){ sprintf(frame_name, "anim/%s%03d.png", name, frame); make_png(frame_name, s, color_type); clear_screen(s); clear_stack(coord_systems); } } free_screen(s); free_vlist(vlist); free_flist(flist); free_elist(elist); free(coord_systems); }
ENTRYPOINT void init_cube (ModeInfo *mi) { cube_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; if (!bps) { bps = (cube_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (cube_configuration)); if (!bps) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } # ifdef HAVE_JWZGLES dbuf_p = True; # endif bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); if (MI_COUNT(mi) <= 0) MI_COUNT(mi) = 1; bp->trackball = gltrackball_init (); bp->subcubes = (subcube *) calloc (MI_COUNT(mi), sizeof(subcube)); for (i = 0; i < MI_COUNT(mi); i++) { double wander_speed, spin_speed, spin_accel; if (i == 0) { wander_speed = 0.05 * speed; spin_speed = 10.0 * speed; spin_accel = 4.0 * speed; } else { wander_speed = 0; spin_speed = 4.0 * speed; spin_accel = 2.0 * speed; } bp->subcubes[i].rot = make_rotator (do_spin ? spin_speed : 0, do_spin ? spin_speed : 0, do_spin ? spin_speed : 0, spin_accel, do_wander ? wander_speed : 0, True); } bp->colors = 0; new_cube_colors (mi); reshape_cube (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); if (!wire) { GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0}; GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); } bp->cube_list = glGenLists (1); glNewList (bp->cube_list, GL_COMPILE); draw_faces (mi); glEndList (); glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }