Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Game_Window::screenshot(){
- //Determine the date and time.
- time_t now;
- struct tm *tm_now;
- char buff[BUFSIZ];
- now=time(NULL);
- tm_now=localtime(&now);
- //Store the date and time in buff.
- strftime(buff,sizeof buff,"%Y-%m-%d_%H.%M.%S",tm_now);
- string date=buff;
- string screenshot_name=engine_interface.get_home_directory()+"screenshots/";
- screenshot_name+=date;
- screenshot_name+=".png";
- unsigned char pixel_data[4*REAL_SCREEN_WIDTH*REAL_SCREEN_HEIGHT];
- if(SDL_RenderReadPixels(renderer,NULL,SDL_PIXELFORMAT_ABGR8888,pixel_data,REAL_SCREEN_WIDTH*4)!=0){
- string msg="Error reading renderer pixels: ";
- msg+=SDL_GetError();
- message_log.update_error_log(msg);
- }
- uint32_t rmask,gmask,bmask,amask;
- engine_interface.get_rgba_masks(&rmask,&gmask,&bmask,&amask);
- SDL_Surface* surface=SDL_CreateRGBSurfaceFrom(pixel_data,REAL_SCREEN_WIDTH,REAL_SCREEN_HEIGHT,32,REAL_SCREEN_WIDTH*4,rmask,gmask,bmask,amask);
- if(surface==0){
- string msg="Error creating surface for screenshot: ";
- msg+=SDL_GetError();
- message_log.update_error_log(msg);
- }
- IMG_SavePNG(surface,screenshot_name.c_str());
- SDL_FreeSurface(surface);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement