Create Helper files
This commit is contained in:
parent
1c0dd4932d
commit
7f31271a8d
36
Helper.cpp
Normal file
36
Helper.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "Helper.h"
|
||||
void drawTexture(SDL_Renderer *renderer, SDL_Texture *texture, int x, int y, int w, int h) {
|
||||
SDL_Rect src;
|
||||
src.x = 0;
|
||||
src.y = 0;
|
||||
SDL_QueryTexture(texture, nullptr, nullptr, &src.w, &src.h);
|
||||
|
||||
SDL_Rect dist;
|
||||
dist.x = x;
|
||||
dist.y = y;
|
||||
dist.w = w;
|
||||
dist.h = h;
|
||||
|
||||
SDL_RenderCopy(renderer, texture, &src, &dist);
|
||||
}
|
||||
|
||||
void drawText(SDL_Renderer *renderer, TTF_Font *font, const std::string text, int x, int y, int w, int h) {
|
||||
SDL_Surface *surface = TTF_RenderText_Solid(font, text.c_str(), {255, 255, 255});
|
||||
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
|
||||
SDL_Rect src;
|
||||
src.x = 0;
|
||||
src.y = 0;
|
||||
SDL_QueryTexture(texture, nullptr, nullptr, &src.w, &src.h);
|
||||
|
||||
SDL_Rect dist;
|
||||
dist.x = x;
|
||||
dist.y = y;
|
||||
dist.w = w;
|
||||
dist.h = h;
|
||||
|
||||
SDL_RenderCopy(renderer, texture, &src, &dist);
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
10
Helper.h
Normal file
10
Helper.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef CPP_LEARNING_HELPER_H
|
||||
#define CPP_LEARNING_HELPER_H
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#include <string>
|
||||
|
||||
void drawTexture(SDL_Renderer *renderer, SDL_Texture *texture, int x, int y, int w, int h);
|
||||
void drawText(SDL_Renderer *renderer, TTF_Font *font, const std::string text, int x, int y, int w, int h);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user