-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdlGraphics.cpp
74 lines (62 loc) · 1.95 KB
/
sdlGraphics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "sdlGraphics.h"
const int SCREEN_WIDTH = 854;
const int SCREEN_HEIGHT = 480;
const char* WINDOW_TITLE = "Baldr";
int currentMVolume = 70;
int currentSVolume = 70;
string difficultySetting = "normal";
SDL_Window* window;
SDL_Renderer* renderer;
//Mix_Music* gMusic = NULL;
Mix_Chunk* gSelect = NULL;
SDLGraphics::SDLGraphics(int screenWidth, int screenHeight, const char* windowTitle)
{
SDL_Init (SDL_INIT_EVERYTHING);
window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenWidth, screenHeight, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096);
TTF_Init();
}
SDLGraphics::~SDLGraphics()
{
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
Mix_Quit();
IMG_Quit();
SDL_Quit();
}
//void SDLGraphics::closeTexture(SDL_Texture* textureName)
//{
// SDL_DestroyTexture(textureName);
//}
void SDLGraphics::beginScene()
{
SDL_RenderClear(renderer);
}
void SDLGraphics::endScene()
{
SDL_RenderClear(renderer);
}
SDL_Texture* loadTexture(const string &str)
{
SDL_Surface* surface = IMG_Load(str.c_str());
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
return texture;
}
SDL_Texture* renderText(const string &message, const string &fontFile, SDL_Color color, int fontSize, SDL_Renderer* renderer)
{
TTF_Font* font = TTF_OpenFont(fontFile.c_str(), fontSize);
SDL_Surface* surf = TTF_RenderText_Blended(font, message.c_str(), color);
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surf);
SDL_FreeSurface(surf);
TTF_CloseFont(font);
return texture;
}
SDL_Texture* textureWindow()
{
SDL_Surface* surface = SDL_GetWindowSurface(window);
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
return texture;
}