Advertisement
Guest User

Untitled

a guest
Jun 20th, 2014
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. void Game_Window::screenshot(){
  2. //Determine the date and time.
  3. time_t now;
  4. struct tm *tm_now;
  5. char buff[BUFSIZ];
  6. now=time(NULL);
  7. tm_now=localtime(&now);
  8.  
  9. //Store the date and time in buff.
  10. strftime(buff,sizeof buff,"%Y-%m-%d_%H.%M.%S",tm_now);
  11.  
  12. string date=buff;
  13.  
  14. string screenshot_name=engine_interface.get_home_directory()+"screenshots/";
  15. screenshot_name+=date;
  16. screenshot_name+=".png";
  17.  
  18. unsigned char pixel_data[4*REAL_SCREEN_WIDTH*REAL_SCREEN_HEIGHT];
  19.  
  20. if(SDL_RenderReadPixels(renderer,NULL,SDL_PIXELFORMAT_ABGR8888,pixel_data,REAL_SCREEN_WIDTH*4)!=0){
  21. string msg="Error reading renderer pixels: ";
  22. msg+=SDL_GetError();
  23. message_log.update_error_log(msg);
  24. }
  25.  
  26. uint32_t rmask,gmask,bmask,amask;
  27. engine_interface.get_rgba_masks(&rmask,&gmask,&bmask,&amask);
  28.  
  29. SDL_Surface* surface=SDL_CreateRGBSurfaceFrom(pixel_data,REAL_SCREEN_WIDTH,REAL_SCREEN_HEIGHT,32,REAL_SCREEN_WIDTH*4,rmask,gmask,bmask,amask);
  30.  
  31. if(surface==0){
  32. string msg="Error creating surface for screenshot: ";
  33. msg+=SDL_GetError();
  34. message_log.update_error_log(msg);
  35. }
  36.  
  37. IMG_SavePNG(surface,screenshot_name.c_str());
  38.  
  39. SDL_FreeSurface(surface);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement