Guest User

Untitled

a guest
Feb 23rd, 2021
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SDL2/SDL.h>
  2. #include <SDL2/SDL_ttf.h>
  3. #include <stdio.h>
  4.  
  5. TTF_Font* font = 0;
  6.  
  7. void free_font(){
  8. if(font)
  9. TTF_CloseFont(font);
  10. font = 0;
  11. }
  12.  
  13. int main(){
  14. int width = 640;
  15. int height = 480;
  16.  
  17. SDL_Init(SDL_INIT_VIDEO);
  18.  
  19. SDL_Window* window = SDL_CreateWindow("Clicker", SDL_WINDOWPOS_UNDEFINED,
  20. SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
  21. SDL_Renderer* renderer;
  22.  
  23. SDL_Surface* surface;
  24.  
  25. SDL_Texture* message;
  26.  
  27. if (window == NULL) {
  28. printf("Error creating window: %s\n", SDL_GetError());
  29. return 1;
  30. }
  31.  
  32. renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
  33.  
  34. if (renderer == NULL) {
  35. printf("Error creating renderer: %s\n", SDL_GetError());
  36. }
  37. if (TTF_Init() == -1){
  38. printf("Error initializing fonts: %s\n", SDL_GetError());
  39. }
  40.  
  41. free_font();
  42. font = TTF_OpenFont("Sans", 40);
  43.  
  44. SDL_Color white = {255, 255, 255};
  45.  
  46. surface = TTF_RenderText_Solid(font, "text", white);
  47. message = SDL_CreateTextureFromSurface(renderer, surface);
  48.  
  49. SDL_Rect message_rect;
  50. message_rect.x = 0;
  51. message_rect.y = 0;
  52. message_rect.w = 100;
  53. message_rect.h = 100;
  54.  
  55. bool running = true;
  56. while (running)
  57. {
  58. SDL_Event e;
  59. if (SDL_PollEvent(&e)) {
  60. if (e.type == SDL_QUIT) {
  61. running = false;
  62. }
  63. }
  64. SDL_RenderClear(renderer);
  65.  
  66. SDL_RenderCopy(renderer, message, NULL, &message_rect);
  67.  
  68. SDL_RenderPresent(renderer);
  69. }
  70.  
  71. free_font();
  72.  
  73. SDL_DestroyTexture(message);
  74. SDL_FreeSurface(surface);
  75. SDL_DestroyWindow(window);
  76. SDL_DestroyRenderer(renderer);
  77.  
  78. TTF_Quit();
  79. SDL_Quit();
  80. return 0;
  81. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×