/* * Called by pthread_create() */ static void * thread_function(void *p) { struct winthread *wt = (struct winthread *) p; draw_loop(wt); return NULL; }
int main(int argc, char **argv) { int num_cal_images = 32; int num_images = 100; init_rng(); cvNamedWindow("shapegen", CV_WINDOW_AUTOSIZE); cvMoveWindow("shapegen", 10, 10); if (generate_cal_image(project_dir, num_cal_images)) { draw_loop(project_dir, num_cal_images, num_images); //draw_loop(NULL, num_cal_images, 20); } return 0; }
VOID updatbox( char *str) { if ( d_display ) { pack(str,0); strcpy(str, (BYTE *)((TEDINFO *)(cpbox[CPDIR].ob_spec))->te_ptext); pack(str,1); strcpy("_", (BYTE *)((TEDINFO *)(cpbox[CPFILE].ob_spec))->te_ptext); wind_update( 1 ); draw_loop( whandle,cpbox,HIDECBOX,MAX_DEPTH,0,0,full.g_w,full.g_h ); wind_update( 0 ); if ( wait_msg( whandle, cpbox ) == WM_CLOSE ) f_cancel = TRUE; } }
int main(void) { PORTA = 0; PORTB = 1; PORTC = 0; PORTD = 0xFF; DDRB = EE_WP | FRAME_INT | KEYS_INT; DDRC = LED_SDI | LED_CLKR | LED_LE | LED_OE_N; DDRD = 0xFF; TCCR0A = (1<<CS12); TWBR = 0xff; TWAR = 0x46 << 1; TWCR = (1 << TWEA) | (1 << TWEN) | (1 << TWINT) | (1 << TWIE); //clear_gain(); sei(); draw_loop(); for(;;); }
int main() { init_display(); if ( glGetError() != 0 ) { printf("display : error\n"); exit(-1); } init_shaders(); if ( glGetError() != 0 ) { printf("shader : error\n"); exit(-1); } init_mesh(); if ( glGetError() != 0 ) { printf("mesh : error\n"); exit(-1); } init_texture(); if ( glGetError() != 0 ) { printf("texture : error\n"); exit(-1); } init_info(); if ( glGetError() != 0 ) { printf("init_info : error\n"); exit(-1); } draw_loop(); return (0); }
int edname(char *src, int kind, int change) { int but; REG OBJECT *obj; obj = get_tree( SAMENAME ); pack(src, 0); strcpy(src, (BYTE *)((TEDINFO *)(obj[FNAME].ob_spec))->te_ptext); strcpy(src, (BYTE *)((TEDINFO *)(obj[EDFNAME].ob_spec))->te_ptext); /* obj[COPY].ob_state = NORMAL; obj[SKIP].ob_state = NORMAL; obj[QUIT].ob_state = NORMAL; */ ((TEDINFO*)(obj[SNAME].ob_spec))->te_ptext = (LONG)get_fstring( ( change ) ? RNAME : NCONFLIC ); /* desk_mice( ARROW ); */ /* fm_draw( SAMENAME, FALSE ); */ switch( but = fmdodraw( SAMENAME, 0 ) ) { case COPY: if (!strcmp((BYTE *)((TEDINFO *)(obj[EDFNAME].ob_spec))->te_ptext, src)) { /* user edit the new name */ strcpy( (BYTE *)((TEDINFO *)(obj[EDFNAME].ob_spec))->te_ptext,src); strcpy( src, (BYTE *)((TEDINFO *)(cpbox[kind].ob_spec))->te_ptext); pack(src,1); backdir(fixdst); strcat(src, fixdst); but = CHECK; } else {/* check if the source and destination are the same */ if (kind == CPDIR) rmstarb(fixsrc); if (strcmp(fixsrc, fixdst))/* they are the same */ but = SKIP; if (kind == CPDIR) strcat(bckslsh, fixsrc); } break; case SKIP: case QUIT: break; } /* desk_mice( HOURGLASS ); */ if ( d_display ) { draw_loop( whandle, cpbox, 0, MAX_DEPTH, 0, 0, full.g_w, full.g_h ); /* fm_draw( CPBOX, FALSE ); */ } /* else namecon = TRUE; */ if (but != CHECK) pack(src, 1); return but; }
int main(int argc, char **argv) { std::string model_filename; if (argc < 2) { model_filename = getBinDir() + BIN2CONFIG + DEFAULT_CONFIG; } else { model_filename = argv[1]; } shm_init(); glfwSetErrorCallback(error_callback); if (!glfwInit()) { return -1; } glfwWindowHint(GLFW_SAMPLES, 4); // TODO how many samples? glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); GLFWwindow *window = glfwCreateWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, "CUAUV Visualizer " VERSION, NULL, NULL); if (!window) { fprintf(stderr, "ERROR: Failed to create window.\n"); return -1; } glfwMakeContextCurrent(window); if (init_engine(true, true)) { fprintf(stderr, "ERROR: Failed to initalize graphics engine.\n"); return -1; } cam.direction = NORTH; cam.up = UP; cam.width = DEFAULT_WIDTH; cam.height = DEFAULT_HEIGHT; cam.fov = 1.0; libconfig::Config config; config.setOptions(libconfig::Setting::OptionAutoConvert); try { config.readFile(model_filename.c_str()); } catch (libconfig::ParseException &pe) { fprintf(stderr, "ERROR parsing config file %s:%d %s\n", pe.getFile(), pe.getLine(), pe.getError()); return -1; } std::unordered_map<std::string, GLuint> texture_map; auto &objects = config.lookup("objects"); for (const auto &object : objects) { std::string name("Poor nameless object"); object.lookupValue("name", name); std::unique_ptr<SceneObject> scene_object; bool is_sub = (object.exists("sub") && ((bool)object.lookup("sub")) == true) || objects.getLength() == 1; if (!object.exists("model")) { scene_object = std::make_unique<SceneObject>(); if (!scene_object) { fprintf(stderr, "ERROR: Could not allocate memory for SceneObject!\n"); continue; } load_axes(scene_object.get()); } else { auto mesh_object = std::make_unique<MeshObject>(); if (!mesh_object) { fprintf(stderr, "ERROR: Could not allocate memory for MeshObject!\n"); continue; } std::string mesh_name = object.lookup("model"); auto get_file_name = [] (const std::string &filename, const char *folder) { if (filename[0] == '/') { return filename; } return getBinDir() + folder + filename; }; if (load_model(get_file_name(mesh_name, BIN2DATA), mesh_object.get())) { fprintf(stderr, "ERROR: failed to make model \"%s\".\n", mesh_name.c_str()); } if (object.exists("texture")) { std::string texture = object.lookup("texture"); if (texture_map.find(texture) == texture_map.end()) { GLuint texture_ind; if (load_texture(get_file_name(texture, BIN2TEXTURES), texture_ind)) { fprintf(stderr, "WARNING: texture \"%s\" failed to load.\n", texture.c_str()); } texture_map[texture] = texture_ind; } mesh_object->set_texture(texture_map[texture]); } if (object.exists("alpha")) { mesh_object->set_alpha(object.lookup("alpha")); } scene_object = std::move(mesh_object); } auto grab_vec = [&object, &name] (const std::string &att_name, glm::vec3 id_v) -> std::function<glm::vec3()> { auto id = [id_v] { return id_v; }; if (object.exists(att_name)) { auto &att = object.lookup(att_name); if (att.getLength() == 3) { glm::vec3 vec(att[0], att[1], att[2]); return [vec] { return vec; }; } std::string att_s = att; if (att_s == "kalman") { return get_sub_position; } else { fprintf(stderr, "ERROR: Invalid %s for object \"%s\".\n", att_name.c_str(), name.c_str()); } } else { return id; } return id; }; auto grab_orientation = [&object, &name] (const std::string &att_prefix) -> std::function<glm::fquat()> { auto id = [] { return quat_from_hpr(0, 0, 0); }; if (object.exists(att_prefix + "_hpr")) { auto &att = object.lookup(att_prefix + "_hpr"); if (att.getLength() == 3) { glm::fquat q = quat_from_hpr(att[0], att[1], att[2]); return [q] { return q; }; } std::string att_s = att; if (att_s == "desires") { return get_desire_quat; } else { fprintf(stderr, "ERROR: Invalid orientation_hpr for object \"%s\".\n", name.c_str()); } } else if (object.exists(att_prefix + "_q")) { std::string att_s = object.lookup(att_prefix + "_q"); if (att_s == "kalman") { return get_sub_quat; } else { fprintf(stderr, "ERROR: Invalid orientation_q for object \"%s\".\n", name.c_str()); } } return id; }; scene_object->get_position = grab_vec("position", glm::vec3(0, 0, 0)); auto orient_f = grab_orientation("orientation"); scene_object->get_orientation = [orient_f] () { return orient_f(); }; auto mesh_f = grab_orientation("mesh_offset"); scene_object->mesh_offset = mesh_f(); scene_object->get_scale = grab_vec("scale", glm::vec3(1, 1, 1)); if (object.exists("exclude_renders")) { auto &excludes = object.lookup("exclude_renders"); for (const auto &render : excludes) { std::unordered_map<std::string, char> value_map = { {"main", RENDER_MAIN}, {"offscreen", RENDER_OFFSCREEN}, {"shadow", RENDER_SHADOW} }; if (value_map.find(render) == value_map.end()) { std::string s; for (const auto &pair : value_map) { s += pair.first + " "; } fprintf(stderr, "WARNING: Invalid exclude_renders for object \"%s\". " "Possible values are: %s\n", name.c_str(), s.c_str()); } else { scene_object->exclude |= value_map[render]; } } } if (object.exists("camera_attachments")) { if (!load_vision_link_lib()) { auto &cams = object.lookup("camera_attachments"); for (const auto &cam : cams) { auto &pos = cam.lookup("pos"); auto &orient = cam.lookup("orientation"); unsigned int width = DEFAULT_WIDTH; unsigned int height = DEFAULT_HEIGHT; float fov = 1.0; cam.lookupValue("width", width); cam.lookupValue("height", height); cam.lookupValue("fov", fov); add_sub_camera(cam.lookup("name"), width, height, fov, glm::vec3(pos[0], pos[1], pos[2]), quat_from_hpr(orient[0], orient[1], orient[2])); } } else { fprintf(stderr, "WARNING: Loading vision link library failed; " "vision output unavailable.\n"); } } if (is_sub) { sub = scene_object.get(); } scene_objects.push_back(std::move(scene_object)); } if (!sub) { fprintf(stderr, "WARNING: no sub designated; sub follow mode will not work.\n"); } add_light(&light1); add_light(&light2); glfwSetFramebufferSizeCallback(window, reshape_callback); glfwSetKeyCallback(window, key_callback); glfwSetCursorPosCallback(window, [] (GLFWwindow *w, double x, double y) { mouse_handlers[mouse_state](w, x, y); }); glClearColor(0.0, 0.0, 0.0, 1.0); glClearDepth(1.0); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); mouse_move_mode_off(window); mouse_handlers[MOUSE] = handle_mouse_move; mouse_handlers[FIXED] = [] (GLFWwindow *w, int x, int y) {}; register_action(GLFW_KEY_M, [window] { if (mouse_state == MOUSE) { mouse_move_mode_off(window); } else { mouse_move_mode_on(window); } }); register_action(GLFW_KEY_F, [] { if (sub) { sub_follow = !sub_follow; if (sub_follow) { cam.up = UP; } } }); register_action(GLFW_KEY_H, [] { heading_lock = !heading_lock; if (heading_lock) { cam_angle = 0.0; } }); register_action(GLFW_KEY_X, toggle_skybox); register_action(GLFW_KEY_Z, toggle_shadows); register_action(GLFW_KEY_V, toggle_offscreen_rendering); register_action(GLFW_KEY_ESCAPE, [window] () { mouse_move_mode_off(window); }); int width, height; glfwGetFramebufferSize(window, &width, &height); reshape_callback(window, width, height); draw_loop(window); glfwDestroyWindow(window); glfwTerminate(); return 0; }