aboutsummaryrefslogtreecommitdiff
path: root/sdl2/render.ha
blob: d4f0671369465f667db93b2eec57b8ca95b0ed3e (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
// TODO: Flesh me out

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

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

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

// Create a window and default renderer.
//
// 'width' and 'height' set the width and height of the window, in screen
// coordinates. 'window_flags' configure additional window parameters.
//
// 'window' and 'renderer' are out parameters, or null, which are filled in with
// the created window and renderer respectively.
//
// Returns 0 on success, or -1 on error.
export @symbol("SDL_CreateWindowAndRenderer") fn create_window_and_renderer(
	width: int, height: int, window_flags: window_flags,
	window: nullable **window, renderer: nullable **renderer) int;

// 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.
// 
// Returns a valid rendering context, or NULL if there was an error.
// 
// See also: [[create_software_renderer]], [[get_renderer_info]],
// [[destroy_renderer]].
export @symbol("SDL_CreateRenderer") fn create_renderer(window: *window,
	index: int, flags: renderer_flags) nullable *renderer;

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

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

// 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.
// 
// Returns 0 on success, or -1 on error
export @symbol("SDL_SetRenderDrawColor") fn set_render_draw_color(renderer: *renderer,
	r: u8, g: u8, b: u8, a: u8) int;

// Clear the current rendering target with the drawing color
//
// This function clears the entire rendering target, ignoring the viewport and
// the clip rectangle.
//
// Returns 0 on success, or -1 on error
export @symbol("SDL_RenderClear") fn render_clear(renderer: *renderer) int;

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

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

// Query the attributes of a texture
//
// Returns 0 on success, or -1 if the texture is not valid.
export @symbol("SDL_QueryTexture") fn query_texture(texture: *texture,
	format: nullable *u32, access: nullable *int,
	w: nullable *int, h: nullable *int) int;

// Copy a portion of the texture to the current rendering target.
//
// Returns 0 on success, or -1 on error
export @symbol("SDL_RenderCopy") fn render_copy(renderer: *renderer,
	texture: *texture, srcrect: nullable *rect, dstrect: nullable *rect) int;