image28

Play.c

Jul 21st, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | None | 0 0
  1. // TCap v0.1
  2. // (C) Thomas Hargrove
  3. // http://toonarchive.com/tcap
  4.  
  5. /***************************************************************************
  6.  *                                                                         *
  7.  *   This program is free software; you can redistribute it and/or modify  *
  8.  *   it under the terms of the GNU General Public License as published by  *
  9.  *   the Free Software Foundation; either version 2 of the License, or     *
  10.  *   (at your option) any later version.                                   *
  11.  *                                                                         *
  12.  ***************************************************************************/
  13.  
  14. #include <unistd.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <sys/ioctl.h>
  18. #include <sys/mman.h>
  19. #include <errno.h>
  20.  
  21. #include "SDL/SDL.h"
  22.  
  23. //#define   WIDTH 960
  24. //#define   HEIGHT 720
  25. #define     p(x) printf("%s",x);
  26. static char     *map;
  27.  
  28. SDL_Surface *screen;
  29. SDL_Surface *offscreen;
  30. SDL_Event event;
  31.  
  32. /* Copies map to screen, then updates the screen */
  33. void copytoscreen(char* tmap) {
  34.     offscreen = SDL_CreateRGBSurfaceFrom((void *) tmap, WIDTH, HEIGHT, 24, WIDTH*3, 0xFF0000, 0x00FF00, 0x0000FF, 0x000000);
  35.     SDL_BlitSurface(offscreen, NULL, screen, NULL);
  36.     SDL_UpdateRect(screen, 0, 0, 0, 0);
  37.     SDL_FreeSurface(offscreen);
  38. }
  39.  
  40.  
  41. int main(int argc, char *argv[])
  42. {
  43.    int done = 0;
  44.    FILE *video;
  45.    if (argv[1] == NULL) { argv[1] = "output"; }
  46.    if ((video=fopen(argv[1],"r")) == NULL)  printf("File did not open"); exit;
  47.  
  48.    // --------------------------------------------------------------------------
  49.    // Set up out video output
  50.    // --------------------------------------------------------------------------
  51.  
  52.    SDL_Init(SDL_INIT_VIDEO);
  53.    screen = SDL_SetVideoMode(WIDTH, HEIGHT, 16, SDL_SWSURFACE);
  54.    if ( screen == NULL ) {
  55.     printf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
  56.     SDL_GetError());
  57.     exit(1);
  58.    }
  59.    SDL_WM_SetCaption("", NULL);
  60.  
  61.    map=malloc(WIDTH*HEIGHT*3);
  62.  
  63.    while ( ! done ) {
  64.     while (SDL_PollEvent(&event))
  65.     {
  66.        switch(event.type)
  67.        {
  68.           case SDL_KEYDOWN: done =1; break;
  69.           case SDL_QUIT: done = 1; break;
  70.        }
  71.     }
  72.     // read each frame from file
  73.     if ( ! feof(video) )
  74.     {
  75.     fread(map, WIDTH*HEIGHT*3, 1, video);
  76.     copytoscreen(map);
  77.     }else{
  78.         done=1;
  79.     }
  80.    }
  81.  
  82.    // Return screen to text mode.
  83.  
  84.    fclose(video);
  85.    SDL_Quit();
  86.  
  87.    return EXIT_SUCCESS;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment