static bool run_test(GLbitfield shaders) { const struct grid_info grid = { shaders, get_image_format(GL_R32UI), { W, H, 1, 1 } }; const struct image_info img = image_info_for_grid(grid); GLuint prog = generate_program( grid, GL_VERTEX_SHADER, generate_source(grid, img, GL_VERTEX_SHADER), GL_TESS_CONTROL_SHADER, generate_source(grid, img, GL_TESS_CONTROL_SHADER), GL_TESS_EVALUATION_SHADER, generate_source(grid, img, GL_TESS_EVALUATION_SHADER), GL_GEOMETRY_SHADER, generate_source(grid, img, GL_GEOMETRY_SHADER), GL_FRAGMENT_SHADER, generate_source(grid, img, GL_FRAGMENT_SHADER), GL_COMPUTE_SHADER, generate_source(grid, img, GL_COMPUTE_SHADER)); bool ret = prog && init_fb(grid) && init_images(img) && bind_images(grid, prog) && draw_grid(grid, prog) && check(grid, img); glDeleteProgram(prog); return ret; }
void create_player(t_perso* pl) { pl->x = pl->ix; pl->y = pl->iy; pl->way = Standing; pl->nb_life = 3; pl->dir = LEFT; pl->type = Human; init_images(pl->img); }
/* * Constructor */ graphics::graphics() { try { init_images(true); menu_font.load("Fonts/lazy.ttf", FONT_SIZE); menu_color.r = 0; menu_color.g = 0; menu_color.b = 0; menu_color_selected.r = 255; menu_color_selected.g = 255; menu_color_selected.b = 255; } catch (exception &e) { err_hndl_obj.inform_about_error("graphics default constructor", e); }; }
int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowSize(w, h); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA); if (!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) { printf("comp: requires a frame buffer with destination alpha\n"); exit(1); } glutCreateWindow("comp"); if (argc > 1) init_images(); else init_tris(); glutDisplayFunc(display); glutReshapeFunc(myReshape); glutKeyboardFunc(key); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
int welcome_main() { int i,j; int mx,my; int welcome = true; int option_screen = false; int score_screen = false; int first_run = true; int credits_screen = false; SDL_Rect temp; TTF_Font *MyFont; SDL_Color GREEN = {0,255,0}; SDL_Color WHITE = {255,255,255}; SDL_Surface *message = NULL; int option = -1; init_buttons(); init_images(); draw_image(backk,screen,NULL,0,0); gameLog("Welcome screen initialized..."); //draw_image(message,screen,NULL,0,0); //Mix_PlayMusic(background_music,-1); while(welcome) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEMOTION: for(i=0;i<TOTAL_NO_BUTTON;++i) { handle_mouseover(&button[i],event.motion.x,event.motion.y); } break; case SDL_MOUSEBUTTONDOWN: mx = event.button.x; my = event.button.y; for( i = 0; i < TOTAL_NO_BUTTON; ++i) { if(check_click(button[i],mx,my)==true) { if(sound)Mix_PlayChannel(-1,click_sound,4); animate_button(button[i],i); first_run = true; switch(i) { case 0: option = 1; welcome = false; break; case 1: option_screen = true; break; case 2: score_screen = true; break; case 3: credits_screen = true; break; case 4: option = -1; welcome = false; break; } } } break; case SDL_QUIT: welcome = false; option = -1; break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_p: animate_button(button[0],0); welcome = false; option = 1; break; case SDLK_x: animate_button(button[4],4); welcome = false; option = -1; break; case SDLK_1: if(Mix_PlayingMusic() == 0) { Mix_PlayMusic(background_music,-1); } else { if(Mix_PausedMusic() == 1) { sound = true; Mix_ResumeMusic(); } else { sound = false; Mix_PauseMusic(); } } break; case SDLK_0: Mix_HaltMusic(); break; } } } //---=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- while(option_screen == true) { if(first_run) { draw_image(option_screen_image,screen,NULL,0,0); draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y); first_run = false; } draw_image(sound_icon[sound],screen,NULL,sound_button.dimension.x,sound_button.dimension.y); while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: if(sound)Mix_PlayChannel(-1,click_sound,0); mx = event.button.x; my = event.button.y; if(check_click(sound_button,mx,my) == true) { if(sound == 0) sound = 1; else sound =0; } if(check_click(back_button,mx,my)== true) { draw_image(backk,screen,NULL,0,0); option_screen = false; } } } SDL_Flip(screen); } //========================================================================================== while(score_screen == true) { if(first_run) { draw_image(score_screen_image,screen,NULL,0,0); draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y); show_scores(); first_run = false; } while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: if(sound)Mix_PlayChannel(-1,click_sound,0); mx = event.button.x; my = event.button.y; if(check_click(back_button,mx,my)== true) { draw_image(backk,screen,NULL,0,0); score_screen = false; } } } SDL_Flip(screen); } //========================================================================================== //========================================================================================== while(credits_screen == true) { if(first_run) { temp.x = 0; temp.y = 0; temp.w = 1100; temp.h = 600; clear_image(temp); MyFont = TTF_OpenFont("fonts\\lfont.ttf",32); message = TTF_RenderText_Blended(MyFont,"Developed By:",WHITE); draw_image(message,screen,NULL,100,100); SDL_FreeSurface(message); message = NULL; TTF_CloseFont(MyFont); MyFont = TTF_OpenFont("fonts\\sfont.ttf",20); message = TTF_RenderText_Blended(MyFont,"-> Bishruti Siku",GREEN); draw_image(message,screen,NULL,100,150); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Nitish Dhaubhadel",GREEN); draw_image(message,screen,NULL,100,170); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Iksha Gurung",GREEN); draw_image(message,screen,NULL,100,190); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Pranaya Pradhananga",GREEN); draw_image(message,screen,NULL,100,210); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Sandip Sahani",GREEN); draw_image(message,screen,NULL,100,230); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"Computer Engineering",WHITE); draw_image(message,screen,NULL,100,300); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"Kathmandu University",WHITE); draw_image(message,screen,NULL,100,320); SDL_FreeSurface(message); message = NULL; draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y); first_run = false; } while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: if(sound)Mix_PlayChannel(-1,click_sound,0); mx = event.button.x; my = event.button.y; if(check_click(back_button,mx,my)== true) { draw_image(backk,screen,NULL,0,0); credits_screen = false; } } } SDL_Flip(screen); } //========================================================================================== for(i=0;i<TOTAL_NO_BUTTON;++i) { draw_image(button_image[i][button[i].state],screen,NULL,button[i].dimension.x,button[i].dimension.y); } SDL_Flip(screen); } SDL_FreeSurface(option_screen_image); SDL_FreeSurface(score_screen_image); SDL_FreeSurface(back_button_image); SDL_FreeSurface(sound_icon[0]); SDL_FreeSurface(sound_icon[1]); SDL_FreeSurface(message); message = NULL; SDL_FreeSurface(backk); for(i=0;i<TOTAL_NO_BUTTON;++i) { for(j=0;j<2;++j) { SDL_FreeSurface(button_image[i][j]); } } //TTF_CloseFont(font); gameLog("Welcome screen closed..."); return option; }
static void * noseguy_init (Display *d, Window w) { struct state *st = (struct state *) calloc (1, sizeof(*st)); unsigned long fg, bg, text_fg, text_bg; XWindowAttributes xgwa; Colormap cmap; char *fontname; XGCValues gcvalues; st->dpy = d; st->window = w; st->first_time = 1; fontname = get_string_resource (st->dpy, "font", "Font"); XGetWindowAttributes (st->dpy, st->window, &xgwa); st->Width = xgwa.width + 2; st->Height = xgwa.height + 2; cmap = xgwa.colormap; st->program = get_string_resource (st->dpy, "program", "Program"); st->tc = textclient_open (st->dpy); init_images(st); if (!fontname || !*fontname) fprintf (stderr, "%s: no font specified.\n", progname); st->font = XLoadQueryFont(st->dpy, fontname); if (!st->font) { fprintf (stderr, "%s: could not load font %s.\n", progname, fontname); exit(1); } fg = get_pixel_resource (st->dpy, cmap, "foreground", "Foreground"); bg = get_pixel_resource (st->dpy, cmap, "background", "Background"); text_fg = get_pixel_resource (st->dpy, cmap, "textForeground", "Foreground"); text_bg = get_pixel_resource (st->dpy, cmap, "textBackground", "Background"); /* notice when unspecified */ if (! get_string_resource (st->dpy, "textForeground", "Foreground")) text_fg = bg; if (! get_string_resource (st->dpy, "textBackground", "Background")) text_bg = fg; gcvalues.font = st->font->fid; gcvalues.foreground = fg; gcvalues.background = bg; st->fg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground|GCFont, &gcvalues); gcvalues.foreground = bg; gcvalues.background = fg; st->bg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground|GCFont, &gcvalues); gcvalues.foreground = text_fg; gcvalues.background = text_bg; st->text_fg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground|GCFont, &gcvalues); gcvalues.foreground = text_bg; gcvalues.background = text_fg; st->text_bg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground|GCFont, &gcvalues); st->x = st->Width / 2; st->y = st->Height / 2; st->state = IS_MOVING; st->next_fn = move; st->walk_up = 1; return st; }
int main(int argc, char *argv[]) { int i, iRet = 0; struct pwcmech * pwcmech; // // Signal Handling // sigset_t block_no_signals; sigemptyset(&block_no_signals); struct sigaction pwc_sig_handler; struct sigaction standard_sig_handler; struct sigaction video_io_sig_handler; pwc_sig_handler.sa_flags = 0; pwc_sig_handler.sa_handler = &sig_handler; sigaction(SIGINT, &pwc_sig_handler, &standard_sig_handler); sigaction(SIGTERM, &pwc_sig_handler, &standard_sig_handler); video_io_sig_handler.sa_flags = 0; video_io_sig_handler.sa_handler = &ioctl_callback; sigaction(SIGIO, &video_io_sig_handler, &standard_sig_handler); // // Userspace Driver Interfaces // struct devClass * video_dev; struct images * p_img; // // Buffering Initialization // printf("Allocating buffers..."); frames = alloc_buffers(); if ( frames == NULL ) { printf("failed?!\n"); goto finish; } init_data_buffer(frames); printf("done!\n"); // // Device Initialization // printf("Create camera device..."); pwcmech = pwc_devmech_start(); if ( pwcmech_register_driver(pwcmech) ) { printf("failed?!\n"); goto release_buffers; } printf("done!\n"); printf("Initialize camera device..."); if ( pwcmech_register_handler(pwcmech) ) { perror("Failed opening camera device"); printf("failed?!\n"); goto stop_usb; } printf("done!\n"); printf("Set camera's video mode..."); //if_claim should work seamslessly somehow iRet = usb_if_claim(pwcmech->com, pwcmech->com->standard_descriptors.highspeed.cameraStream.cameraStreamConf); if ( iRet ) { perror("Failed setting camera's video mode"); printf("failed?!\n"); goto close_camera; } iRet = setVideoMode(pwcmech, 9); //still old way, pre-setting instead of from V4L if ( iRet ) { perror("Failed setting camera's video mode"); printf("failed?!\n"); goto close_camera; } set_ctrl0_timeout(pwcmech->com, 1000); setLeds(pwcmech, 0,0); //don't bother with the light iRet = sendVideoCommand(pwcmech, video_mode_string, VIDEO_MODE_STRING_LEN); if ( iRet ) { perror("Failed setting camera's video mode"); printf("failed?!\n"); goto close_camera; } printf("done!\n"); // // Decompression // printf("Initializing decompression system..."); p_img = alloc_images(); if ( p_img == NULL ) { printf("failed?!\n"); goto close_camera; } if ( ( iRet = init_images(p_img) ) ) { printf("failed?!\n"); goto free_p_img; } printf("done!\n"); #ifndef NO_IMG // // Open video pipe // printf("Opening the video pipe (vl4 device emulation)..."); video_dev = alloc_devClass(); if ( video_dev == NULL ) { printf("failed?!\n"); goto free_p_img; } p_img->img_buf = init_devClass(video_dev, argv[1], p_img); if ( p_img->img_buf == NULL ) { perror("Initializing device class failed"); printf("failed?!\n"); printf("Did you input the device path, \"/dev/video0\"?\"\n\n\n"); goto free_video_dev; } printf("done!\n"); #endif // // ISO transfers // printf("Create USB isochronous transfers..."); for (i = 0; i < ISO_BUFFERS_NR; i++) { iRet = assignVideoBuffer(pwcmech, frames->iso_buffer[i], ISO_BUFFER_SIZE); if (iRet) { perror("Failed creating image transfer"); printf("failed?!\n"); goto unregister_buffers; } } printf("done!\n"); // // Threads // printf("Set-up threads..."); int active_threads = 0; pthread_t threads[NUM_THREADS]; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); struct acqArg * acq_arg; acq_arg = malloc(sizeof(struct acqArg)); if ( acq_arg == NULL ) { printf("failed?!\n"); goto close_threads; } acq_arg->abort = &thread_abort; acq_arg->pwcmech = pwcmech; struct imgArg * img_arg; img_arg = malloc(sizeof(struct imgArg)); if ( img_arg == NULL ) { printf("failed?!\n"); goto close_threads; } img_arg->frames = frames; img_arg->p_img = p_img; img_arg->video_pipe = video_dev; img_arg->capture = 0; img_arg->abort = &thread_abort; printf("done!\n"); // // MAIN // printf("Registering callback function for Isochronous transfer..."); setPower(pwcmech, 0); //enable camera (our state machine discovered that this was missing) registerVideoCallback(pwcmech, acquire_frame, pwcmech); if ( acknowledgeVideoCallback(pwcmech) ) goto close_threads; printf("done!\n"); #ifndef NO_COM printf("Creating the data acquisition thread..."); if ( ( iRet = pthread_create(&threads[active_threads], &attr, process_usb, (void *)acq_arg) ) ) { printf("failed?!\n"); goto stop_camera; } active_threads++; printf("done!\n"); #endif #ifndef NO_IMG printf("Creating the image fill thread..."); if ( ( iRet = pthread_create(&threads[active_threads], &attr, fillImageData, (void *)img_arg) ) ) { printf("failed?!\n"); goto stop_camera; } active_threads++; printf("done!\n"); #endif while (!op_abort) { // sigsuspend(&block_no_signals); if ( ioctl_call ) { devClass_ioctl(video_dev, &img_arg->capture); ioctl_call = 0; } } // // ~MAIN // stop_camera: printf("Releasing video callback..."); releaseVideoCallback(pwcmech); printf("done!\n"); printf("Unregistering buffers..."); unassignVideoBuffers(pwcmech); printf("done!\n"); close_threads: printf("Closing all threads..."); thread_abort = 1; for ( i = 0; i < active_threads; i++) pthread_join(threads[i], NULL); free(acq_arg); free(img_arg); pthread_attr_destroy(&attr); printf("done!\n"); unregister_buffers: printf("Unregistering buffers if not done before..."); unassignVideoBuffers(pwcmech); printf("done!\n"); free_video_dev: #ifndef NO_IMG printf("Closing video pipe..."); close_devClass(video_dev); free_devClass(video_dev); printf("done!\n"); #endif free_p_img: printf("Releasing decompression system..."); free_images(p_img); printf("done!\n"); usb_release_interface(pwcmech->com, pwcmech->com->standard_descriptors.highspeed.cameraStream.cameraStreamConf); close_camera: printf("Close camera device..."); pwcmech_deregister_handler(pwcmech); printf("done!\n"); stop_usb: printf("Stopping USB interface..."); pwcmech_deregister_driver(pwcmech); printf("done!\n"); release_buffers: pwc_devmech_stop(pwcmech); //release buffers, they are linked to the camera device //so only release them after releasing the camera printf("Releasing buffers..."); free_buffers(frames); printf("done!\n"); finish: return 0; }
static void * noseguy_init (Display *d, Window w) { struct state *st = (struct state *) calloc (1, sizeof(*st)); unsigned long fg, bg, text_fg, text_bg; XWindowAttributes xgwa; Colormap cmap; char *fontname; XGCValues gcvalues; st->dpy = d; st->window = w; st->first_time = 1; fontname = get_string_resource (st->dpy, "font", "Font"); XGetWindowAttributes (st->dpy, st->window, &xgwa); st->Width = xgwa.width + 2; st->Height = xgwa.height + 2; cmap = xgwa.colormap; st->tc = textclient_open (st->dpy); { int w = 40; int h = 15; textclient_reshape (st->tc, w, h, w, h, /* Passing MAXLINES isn't actually necessary */ 0); } init_images(st); st->xftfont = XftFontOpenXlfd (st->dpy, screen_number (xgwa.screen), fontname); XftColorAllocName (st->dpy, xgwa.visual, xgwa.colormap, get_string_resource (st->dpy, "textForeground", "Foreground"), &st->xftcolor); st->xftdraw = XftDrawCreate (st->dpy, st->window, xgwa.visual, xgwa.colormap); fg = get_pixel_resource (st->dpy, cmap, "foreground", "Foreground"); bg = get_pixel_resource (st->dpy, cmap, "background", "Background"); text_fg = get_pixel_resource (st->dpy, cmap, "textForeground", "Foreground"); text_bg = get_pixel_resource (st->dpy, cmap, "textBackground", "Background"); /* notice when unspecified */ if (! get_string_resource (st->dpy, "textForeground", "Foreground")) text_fg = bg; if (! get_string_resource (st->dpy, "textBackground", "Background")) text_bg = fg; gcvalues.foreground = fg; gcvalues.background = bg; st->fg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcvalues); gcvalues.foreground = bg; gcvalues.background = fg; st->bg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcvalues); gcvalues.foreground = text_fg; gcvalues.background = text_bg; st->text_fg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcvalues); gcvalues.foreground = text_bg; gcvalues.background = text_fg; st->text_bg_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcvalues); st->x = st->Width / 2; st->y = st->Height / 2; st->state = IS_MOVING; st->next_fn = move; st->walk_up = 1; return st; }