aboutsummaryrefslogtreecommitdiff
path: root/graphics/graphics.h
blob: 6b36cbd2589ff6b03613096f03b4dbd0389d699a (plain)
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
#ifndef GRAPHICS_H
#define GRAPHICS_H

#include <vector>
#include <string>

#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>

#include "../game/gst.h"
#include "../game/view.h"
#include "cam.h"

#include <string>


class Graphics_sdl_text {
    public:
    Graphics_sdl_text();
    int get_text_width (char str[]);
    void render_text (std::string str, vec2 off);
    SDL_Renderer* gRenderer;
    SDL_Texture *tex;
    int char_width[128];
};

class Graphics_sdl {
    public:
    Graphics_sdl (int resx, int resy);
    ~Graphics_sdl ();
    SDL_Renderer* get_renderer ();
    void load_sheet ();
    void present ();
    void render_sprite (
        int x, int y, int w, int h, 
        int u, int v, int s, int t);
    void render_rect (
        int r, int g, int b, int a,
        int x, int y, int w, int h);
    void render_sprite (
        int x, int y, int w, int h, 
        int u, int v, int s, int t,
        int r, int g, int b);
    
    Graphics_sdl_text txt;
    
    private:
    SDL_Window* window = NULL;
	SDL_Surface* screenSurface = NULL;
    SDL_Renderer* rend = NULL;
    SDL_Texture* txsprites = NULL;
};


class Graphics {
    public:
    Graphics (int resx, int resy) 
        : resx(resx), resy(resy), backend(resx, resy) {}
    ~Graphics ();
    
    Graphics_sdl backend;

    int resx, resy;
    Cam cam;
    
    void render (Gst &gst, View &view);
    void present ();
};

#endif