Skip to content
Snippets Groups Projects
Select Git revision
  • 07345ad840a9bcf018f7de33631ab717f8e70301
  • main default
  • qlearn-4
  • qlearning5
  • qlearn5
  • render
  • qlearn
  • ball
  • fire
  • player
10 results

render.c

Blame
  • render.c 5.49 KiB
    #include "render.h"
    
    SDL_Window *window;
    SDL_Renderer *renderer;
    
    TTF_Font *robotoFont;
    SDL_DisplayMode screenDimension;
    
    SDL_Rect buttonRect;
    
    SDL_Surface * grassSurface;
    SDL_Texture * grassTexture;
    
    SDL_Surface * treeSurface;
    SDL_Texture * treeTexture;
    
    SDL_Surface * hoverSurface;
    SDL_Texture * hoverTexture;
    
    SDL_Surface * playerSurface;
    SDL_Texture * playerTexture;
    
    SDL_Surface * backgroundSurface;
    SDL_Texture * backgroundTexture;
    
    SDL_Surface * playButtonSurface;
    SDL_Texture * playButtonTexture;
    
    SDL_Surface * playButtonHoverSurface;
    SDL_Texture * playButtonHoverTexture;
    
    void createWindow(){
    
        if (SDL_Init(SDL_INIT_VIDEO) != 0){
            printf("Couldn't create window.");
            exit(EXIT_FAILURE);
        }
    
        SDL_GetCurrentDisplayMode(0, &screenDimension);
    
        window = SDL_CreateWindow("Game Of Life", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenDimension.w, screenDimension.h, SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP);
    
        if (window == NULL){
            printf("Couldn't create window");
            exit(EXIT_FAILURE);
        }
    
        renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_PRESENTVSYNC);
    
        if (renderer == NULL){
            printf("Couldn't create renderer.");
            exit(EXIT_FAILURE);
        }
    
        if (TTF_Init() == -1)
        {
            exit(EXIT_FAILURE);
        }
    
        robotoFont = TTF_OpenFont("Res/Roboto-Black.ttf", 50);  
    
    }
    
    void drawBackground(){
        SDL_Rect rect = {0, 0, screenDimension.w, screenDimension.h};
        SDL_RenderCopy(renderer, backgroundTexture, NULL, &rect);
    }
    
    void drawPlayButton(){
        int buttonPosX = screenDimension.w/2 - screenDimension.w/12;