summaryrefslogtreecommitdiff
path: root/src/renderer.h
blob: 3ac10b8f9e30c7326c1f21d9ae59e6c2603bab05 (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 _RENDERER_H
#define _RENDERER_H

#include "common.h"
#include "physics.h"

extern float r_color_white[4];
extern float r_color_black[4];
extern float r_color_red[4];
extern float r_color_blue[4];

typedef struct r_window_s r_window;
struct r_window_s {
	SDL_Window *window;
	SDL_Renderer *renderer;
	SDL_Texture *font_texture;

	r_window *prev, *next;
};

int r_init(void);
void r_quit(void);

r_window *r_window_create(void);
void r_window_destroy(r_window *rw);

void r_clear(r_window *rw, float *color);
void r_flip(r_window *rw);

void r_clip_enable(r_window *rw, float x, float y, float w, float h);
void r_clip_disable(r_window *rw);
void r_draw_line(r_window *rw, float x0, float y0, float x1, float y1,
                 float *color);
void r_draw_rect(r_window *rw, float x, float y, float w, float h,
                 float *color);

#define TEXT_CENTERX     0x0001
#define TEXT_RIGHTX      0x0002
float r_text_width(float h, char *text);
void r_draw_text(r_window *rw, float x, float y, float h, char *text,
                 float *color, int flags);


#define XSECTION_XY      0x0001
#define XSECTION_XZ      0x0002
#define XSECTION_YZ      0x0004
#define XSECTION_PLANES  (XSECTION_XY|XSECTION_XZ|XSECTION_YZ)
#define XSECTION_E       0x0008
#define XSECTION_H       0x0010
#define XSECTION_EPS     0x0020
#define XSECTION_FIELDS  (XSECTION_E|XSECTION_H|XSECTION_EPS)


typedef struct {
	SDL_Texture *texture;
	float aspect_ratio;

	int last_flags;
	float last_frac;
	int64_t frame_index;
} r_xsection;

void r_xsection_create(r_xsection *xsection);
void r_xsection_destroy(r_xsection *xsection);
int r_xsection_update(r_window *rw, r_xsection *xsection, phy_sim *sim,
                      int flags, float frac);
void r_xsection_draw(r_window *rw, r_xsection *xsection,
                     float x, float y, float w, float h);

#endif // _RENDERER_H