aboutsummaryrefslogtreecommitdiff
path: root/sdl2/render.ha
blob: d60771255598bc6e3028c18fde67bb2a7d80150d (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// TODO: Flesh me out

// A structure representing rendering state. (Opaque)
export type SDL_Renderer = void;

// An efficient driver-specific representation of pixel data. (Opaque)
export type SDL_Texture = void;

// Flags used when creating a rendering context.
export type SDL_RendererFlags = enum u32 {
	NONE = 0,
	SOFTWARE = 0x00000001,
	ACCELERATED = 0x00000002,
	PRESENTVSYNC = 0x00000004,
	TARGETTEXTURE = 0x00000008,
};

@symbol("SDL_CreateWindowAndRenderer") fn _SDL_CreateWindowAndRenderer(
	width: int, height: int, SDL_WindowFlags: SDL_WindowFlags,
	window: nullable **SDL_Window, renderer: nullable **SDL_Renderer) int;

// Create a window and default renderer.
//
// 'width' and 'height' set the width and height of the window, in screen
// coordinates. 'SDL_WindowFlags' configure additional window parameters.
//
// 'window' and 'renderer' are out parameters, or null, which are filled in with
// the created window and renderer respectively.
export fn SDL_CreateWindowAndRenderer(
	width: int,
	height: int,
	SDL_WindowFlags: SDL_WindowFlags,
	window: nullable **SDL_Window,
	renderer: nullable **SDL_Renderer,
) (void | error) = wrapvoid(_SDL_CreateWindowAndRenderer(width, height,
	SDL_WindowFlags, window, renderer));

@symbol("SDL_CreateRenderer") fn _SDL_CreateRenderer(window: *SDL_Window,
	index: int, flags: SDL_RendererFlags) nullable *SDL_Renderer;

// Create a 2D rendering context for a window.
//
// 'window' is the window where rendering is displayed. 'index' is the index of
// the rendering driver to initialize, or -1 to initialize the first one
// supporting the requested flags.
//
// See also: [[create_software_renderer]], [[get_renderer_info]],
// [[SDL_DestroyRenderer]].
export fn SDL_CreateRenderer(
	window: *SDL_Window,
	index: int,
	flags: SDL_RendererFlags,
) (*SDL_Renderer | error) =
	wrapptr(_SDL_CreateRenderer(window, index, flags))?: *SDL_Renderer;

// Destroy the rendering context for a window and free associated textures.
//
// See also: [[SDL_CreateRenderer]].
export @symbol("SDL_DestroyRenderer") fn SDL_DestroyRenderer(renderer: *SDL_Renderer) void;

// Opaque value for the alpha channel (255).
export def ALPHA_OPAQUE: u8 = 255;

@symbol("SDL_SetRenderDrawColor") fn _SDL_SetRenderDrawColor(renderer: *SDL_Renderer,
	r: u8, g: u8, b: u8, a: u8) int;

// Set the color used for drawing operations (Rect, Line and Clear).
//
// 'renderer' is the renderer for which drawing color should be set. 'r', 'g',
// 'b', and 'a' respectively set the red, gree, blue, and alpha channels.
export fn SDL_SetRenderDrawColor(
	renderer: *SDL_Renderer,
	r: u8, g: u8, b: u8, a: u8,
) (void | error) = wrapvoid(_SDL_SetRenderDrawColor(renderer, r, g, b, a));

@symbol("SDL_RenderClear") fn _SDL_RenderClear(renderer: *SDL_Renderer) int;

// Clear the current rendering target with the drawing color
//
// This function clears the entire rendering target, ignoring the viewport and
// the clip rectangle.
export fn SDL_RenderClear(renderer: *SDL_Renderer) (void | error) = {
	return wrapvoid(_SDL_RenderClear(renderer));
};

// Update the screen with rendering performed.
export @symbol("SDL_RenderPresent") fn SDL_RenderPresent(renderer: *SDL_Renderer) void;

// Destroy the specified texture.
export @symbol("SDL_DestroyTexture") fn SDL_DestroyTexture(texture: *SDL_Texture) void;

@symbol("SDL_QueryTexture") fn _SDL_QueryTexture(texture: *SDL_Texture,
	format: nullable *u32, access: nullable *int,
	w: nullable *int, h: nullable *int) int;

// Query the attributes of a texture
export fn SDL_QueryTexture(
	texture: *SDL_Texture,
	format: nullable *u32,
	access: nullable *int,
	w: nullable *int, h: nullable *int,
) (void | error) = {
	return wrapvoid(_SDL_QueryTexture(texture, format, access, w, h));
};

@symbol("SDL_SetTextureColorMod") fn _SDL_SetTextureColorMod(
	texture: *SDL_Texture, r: u8, g: u8, b: u8) int;

// Set an additional color value multiplied into render copy operations.
//
// When this texture is rendered, during the copy operation each source color
// channel is modulated by the appropriate color value according to the
// following formula:
//
// 	srcC = srcC * (color / 255)
//
// Color modulation is not always supported by the renderer; it will return -1
// if color modulation is not supported.
export fn SDL_SetTextureColorMod(
	texture: *SDL_Texture,
	r: u8, g: u8, b: u8,
) (void | error) = {
	return wrapvoid(_SDL_SetTextureColorMod(texture, r, g, b));
};

@symbol("SDL_SetTextureAlphaMod") fn _SDL_SetTextureAlphaMod(texture: *SDL_Texture, a: u8) int;

// Set an additional alpha value multiplied into render copy operations.
//
// When this texture is rendered, during the copy operation the source alpha
// value is modulated by this alpha value according to the following formula:
//
// `srcA = srcA * (alpha / 255)`
//
// Alpha modulation is not always supported by the renderer; it will return an
// error if alpha modulation is not supported.
export fn SDL_SetTextureAlphaMod(texture: *SDL_Texture, a: u8) (void | error) = {
	// TODO: Double check errors
	return wrapvoid(_SDL_SetTextureAlphaMod(texture, a));
};

@symbol("SDL_SetTextureBlendMode") fn _SDL_SetTextureBlendMode(
	texture: *SDL_Texture, mode: SDL_BlendMode) int;

// Set the blend mode for a texture, used by SDL_RenderCopy().
export fn SDL_SetTextureBlendMode(
	texture: *SDL_Texture,
	mode: SDL_BlendMode,
) (void | error) = {
	return wrapvoid(_SDL_SetTextureBlendMode(texture, mode));
};

@symbol("SDL_SetRenderDrawBlendMode") fn _SDL_SetRenderDrawBlendMode(
	renderer: *SDL_Renderer, mode: SDL_BlendMode) int;

// Set the blend mode used for drawing operations (fill and line).
export fn SDL_SetRenderDrawBlendMode(
	renderer: *SDL_Renderer,
	mode: SDL_BlendMode,
) (void | error) = {
	return wrapvoid(_SDL_SetRenderDrawBlendMode(renderer, mode));
};

@symbol("SDL_RenderCopy") fn _SDL_RenderCopy(renderer: *SDL_Renderer,
	texture: *SDL_Texture, srcrect: nullable *SDL_Rect, dstrect: nullable *SDL_Rect) int;

// Copy a portion of the texture to the current rendering target.
export fn SDL_RenderCopy(
	renderer: *SDL_Renderer,
	texture: *SDL_Texture,
	srcrect: nullable *SDL_Rect,
	dstrect: nullable *SDL_Rect,
) (void | error) = {
	return wrapvoid(_SDL_RenderCopy(renderer, texture, srcrect, dstrect));
};

@symbol("SDL_RenderDrawRect") fn _SDL_RenderDrawRect(
	renderer: *SDL_Renderer, rect: const nullable *SDL_Rect) int;

// Draw a rectangle on the current rendering target.
export fn SDL_RenderDrawRect(
	renderer: *SDL_Renderer,
	rect: const nullable *SDL_Rect,
) (void | error) = {
	return wrapvoid(_SDL_RenderDrawRect(renderer, rect));
};

@symbol("SDL_RenderFillRect") fn _SDL_RenderFillRect(
	renderer: *SDL_Renderer, rect: const nullable *SDL_Rect) int;

// Fills a rectangle on the current rendering target.
export fn SDL_RenderFillRect(
	renderer: *SDL_Renderer,
	rect: const nullable *SDL_Rect,
) (void | error) = {
	return wrapvoid(_SDL_RenderFillRect(renderer, rect));
};