Select Git revision
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;