Advertisement
j0h

tffFileRead.cpp

j0h
Apr 8th, 2023
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <SDL/SDL.h>
  2. #include <SDL/SDL_ttf.h>
  3. #include "tff.h"
  4.  #include <unistd.h>
  5.  #include <fstream>
  6.  #include <iostream>
  7. #include <string>
  8.  
  9. int main(int argc, char* args[]){
  10.  
  11.     if(SDL_Init(SDL_INIT_EVERYTHING) < 0){
  12.         printf("Failed to initialize SDL!\n");
  13.         return 0;
  14.     }
  15.  
  16.  
  17.     Backbuffer = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
  18.     if(TTF_Init() == -1)
  19.         return 0;
  20.  
  21.     Font = TTF_OpenFont("fonts/Gothikka-bold.ttf", FS());
  22.     if(Font == NULL){
  23.         printf("Failed to load font!\n");
  24.         TTF_CloseFont(Font);
  25.         TTF_Quit();
  26.         SDL_Quit();
  27.  
  28.         return 0;
  29.     }
  30.  
  31.     SDL_WM_SetCaption("Outline Font", NULL);
  32.  
  33.  //   int counter = 1000;
  34.  
  35.     while(ProgramIsRunning()){
  36.         SDL_FillRect(Backbuffer, NULL, 0);
  37.  
  38.    //     counter--;
  39.    //     if(counter < 0){
  40.            // counter = 1000;
  41.    //            TTF_CloseFont(Font);
  42.     //           TTF_Quit();
  43.     //           SDL_Quit();
  44.    //         }
  45.     //    char buffer[64];
  46.    //     const char *x="This program will explode in: %d ";
  47.   //      sprintf(buffer, x , counter);
  48.  //char *R="Raster Fonts Suck";
  49.  //char *W="Outline Fonts FTW";
  50. //    char *text="who knows";
  51. std::string text;
  52.       std::fstream newfile;
  53.          newfile.open("text.txt",std::ios::in);
  54.    
  55.    if (newfile.is_open()){  
  56.       std::string tp;
  57.            int count=0;
  58.       while(getline(newfile, tp)){
  59.           text=tp;
  60.           char* f = const_cast<char*>(text.c_str());
  61.  
  62.           DrawTTFFonts(f,count);
  63.           SDL_Delay(2000);
  64.           SDL_Flip(Backbuffer);
  65.  count++;
  66.       }
  67.               SDL_Delay(2000);
  68.       newfile.close(); //close the file object.
  69.    }
  70. // DrawTTFFonts(text,count);
  71.  
  72.         //DrawOutlineText(Backbuffer, R, 100, 100, Font, 255, 0, 0);
  73.       //  DrawOutlineText(Backbuffer, W, 100,150, Font, 0, 255, 0);
  74.       //  DrawOutlineText(Backbuffer, buffer, 100, 200, Font, 0, 0, 255);
  75.  
  76.        // SDL_Delay(20);
  77.      //   SDL_Flip(Backbuffer);
  78.     }
  79.  
  80.     TTF_CloseFont(Font);
  81.     TTF_Quit();
  82.     SDL_Quit();
  83.  
  84.     return 0;
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement