-
Notifications
You must be signed in to change notification settings - Fork 0
/
Screen.c
74 lines (62 loc) · 2.04 KB
/
Screen.c
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 "Screen.h"
#include <SDL.h>
#include "Game.h"
void InitializeSDL(const ScreenDimensions _screenDimensions)
{
SDL_Init(SDL_INIT_VIDEO);
game_state->window = SDL_CreateWindow(
"CGame",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
_screenDimensions.x,
_screenDimensions.y,
0
);
game_state->renderer = SDL_CreateRenderer(game_state->window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawBlendMode(game_state->renderer, SDL_BLENDMODE_BLEND);
}
void SetRenderColor(const Color _rgb, const uint8_t _alpha)
{
SDL_SetRenderDrawColor(game_state->renderer, _rgb.x, _rgb.y, _rgb.z, _alpha);
}
void ClearScreen()
{
SDL_RenderClear(game_state->renderer);
}
void PrepareScreen()
{
Color clearColor;
clearColor.x = 0;
clearColor.y = 0;
clearColor.z = 0;
SetRenderColor(clearColor, SDL_ALPHA_OPAQUE);
ClearScreen();
SetViewport(game_state->viewport);
}
void SetViewport(const Viewport* _viewport)
{
const SDL_Rect rect = GetViewportSDLRect(_viewport);
SDL_RenderSetViewport(game_state->renderer, &rect);
}
void DrawScreen()
{
SDL_RenderPresent(game_state->renderer);
}
void DrawSprite(const Sprite* _sprite)
{
const SDL_Rect dstRect = SpriteGetDestinationSDLRect(_sprite, game_state->viewport);
const SDL_Rect srcRect = SpriteGetSourceSDLRect(_sprite);
const SDL_Point spriteCenter = SpriteGetCenter(_sprite);
SDL_RenderCopyEx(game_state->renderer, _sprite->texture->sdl_texture, &srcRect, &dstRect, (double)_sprite->rotation_angle, &spriteCenter, _sprite->flip);
}
void DrawSpriteAbsolute(const Sprite* _sprite)
{
const SDL_Rect srcRect = SpriteGetSourceSDLRectAbsolute(_sprite);
const SDL_Point spriteCenter = SpriteGetCenter(_sprite);
SDL_RenderCopyEx(game_state->renderer, _sprite->texture->sdl_texture, NULL, &srcRect, (double)_sprite->rotation_angle, &spriteCenter, _sprite->flip);
}
void DestroyScreen()
{
SDL_DestroyWindow(game_state->window);
SDL_Quit();
}