Skip to content

Commit baba3aa

Browse files
update graphics cheatsheet
1 parent 66ef64a commit baba3aa

File tree

1 file changed

+110
-80
lines changed

1 file changed

+110
-80
lines changed

doc/cheatsheets/cheatsheet_graphics.h

+110-80
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,137 @@
1-
/************************************************************/ /**
1+
/*************************************************************************
22
*
3-
* @file: cheatsheet_graphics.h
4-
* @author: Martin Fouilleul
5-
* @date: 05/09/2023
3+
* Orca
4+
* Copyright 2023 Martin Fouilleul and the Orca project contributors
5+
* See LICENSE.txt for licensing information
66
*
7-
*****************************************************************/
7+
**************************************************************************/
88

99
//------------------------------------------------------------------------------------------
10-
// graphics surface
10+
//graphics surface
1111
//------------------------------------------------------------------------------------------
1212
oc_surface oc_surface_nil(void);
1313
bool oc_surface_is_nil(oc_surface surface);
14-
oc_surface oc_surface_canvas();
15-
oc_surface oc_surface_gles();
16-
void oc_surface_destroy(oc_surface surface);
1714

18-
void oc_surface_select(oc_surface surface);
19-
void oc_surface_deselect(void);
20-
void oc_surface_present(oc_surface surface);
15+
void oc_surface_destroy(oc_surface surface);
2116

2217
oc_vec2 oc_surface_get_size(oc_surface surface);
2318
oc_vec2 oc_surface_contents_scaling(oc_surface surface);
2419
void oc_surface_bring_to_front(oc_surface surface);
2520
void oc_surface_send_to_back(oc_surface surface);
21+
bool oc_surface_get_hidden(oc_surface surface);
22+
void oc_surface_set_hidden(oc_surface surface, bool hidden);
23+
24+
oc_surface oc_gles_surface_create(void);
25+
void oc_gles_surface_make_current(oc_surface surface);
26+
void oc_gles_surface_swap_interval(oc_surface surface, int interval);
27+
void oc_gles_surface_swap_buffers(oc_surface surface);
28+
29+
//------------------------------------------------------------------------------------------
30+
//color helpers
31+
//------------------------------------------------------------------------------------------
32+
oc_color oc_color_rgba(f32 r, f32 g, f32 b, f32 a);
33+
oc_color oc_color_srgba(f32 r, f32 g, f32 b, f32 a);
34+
oc_color oc_color_convert(oc_color color, oc_color_space colorSpace);
35+
36+
//------------------------------------------------------------------------------------------
37+
//canvas renderer
38+
//------------------------------------------------------------------------------------------
39+
oc_canvas_renderer oc_canvas_renderer_nil(void);
40+
bool oc_canvas_renderer_is_nil(oc_canvas_renderer renderer);
41+
42+
oc_canvas_renderer oc_canvas_renderer_create(void);
43+
void oc_canvas_renderer_destroy(oc_canvas_renderer renderer);
44+
45+
void oc_canvas_render(oc_canvas_renderer renderer, oc_canvas_context context, oc_surface surface);
46+
void oc_canvas_present(oc_canvas_renderer renderer, oc_surface surface);
47+
48+
//------------------------------------------------------------------------------------------
49+
//canvas surface
50+
//------------------------------------------------------------------------------------------
51+
oc_surface oc_canvas_surface_create(oc_canvas_renderer renderer);
52+
void oc_canvas_surface_swap_interval(oc_surface surface, int swap);
53+
54+
//------------------------------------------------------------------------------------------
55+
//canvas context
56+
//------------------------------------------------------------------------------------------
57+
oc_canvas_context oc_canvas_context_nil(void);
58+
bool oc_canvas_context_is_nil(oc_canvas_context context);
59+
60+
oc_canvas_context oc_canvas_context_create(void);
61+
void oc_canvas_context_destroy(oc_canvas_context context);
62+
oc_canvas_context oc_canvas_context_select(oc_canvas_context context);
63+
64+
void oc_canvas_context_set_msaa_sample_count(oc_canvas_context context, u32 sampleCount);
65+
66+
//------------------------------------------------------------------------------------------
67+
//fonts
68+
//------------------------------------------------------------------------------------------
69+
oc_font oc_font_nil(void);
70+
bool oc_font_is_nil(oc_font font);
71+
72+
oc_font oc_font_create_from_memory(oc_str8 mem, u32 rangeCount, oc_unicode_range* ranges);
73+
oc_font oc_font_create_from_file(oc_file file, u32 rangeCount, oc_unicode_range* ranges);
74+
oc_font oc_font_create_from_path(oc_str8 path, u32 rangeCount, oc_unicode_range* ranges);
75+
76+
void oc_font_destroy(oc_font font);
77+
78+
oc_str32 oc_font_get_glyph_indices(oc_font font, oc_str32 codePoints, oc_str32 backing);
79+
oc_str32 oc_font_push_glyph_indices(oc_arena* arena, oc_font font, oc_str32 codePoints);
80+
u32 oc_font_get_glyph_index(oc_font font, oc_utf32 codePoint);
81+
82+
// metrics
83+
oc_font_metrics oc_font_get_metrics(oc_font font, f32 emSize);
84+
oc_font_metrics oc_font_get_metrics_unscaled(oc_font font);
85+
f32 oc_font_get_scale_for_em_pixels(oc_font font, f32 emSize);
86+
87+
oc_text_metrics oc_font_text_metrics_utf32(oc_font font, f32 fontSize, oc_str32 codepoints);
88+
oc_text_metrics oc_font_text_metrics(oc_font font, f32 fontSize, oc_str8 text);
2689

2790
//------------------------------------------------------------------------------------------
28-
// 2D canvas command buffer
91+
//images
2992
//------------------------------------------------------------------------------------------
30-
oc_canvas oc_canvas_nil(void);
31-
bool oc_canvas_is_nil(oc_canvas canvas);
32-
oc_canvas oc_canvas_create(void);
33-
void oc_canvas_destroy(oc_canvas canvas);
34-
oc_canvas oc_canvas_set_current(oc_canvas canvas);
35-
void oc_render(oc_canvas canvas);
93+
oc_image oc_image_nil(void);
94+
bool oc_image_is_nil(oc_image a);
95+
oc_image oc_image_create(oc_canvas_renderer renderer, u32 width, u32 height);
96+
oc_image oc_image_create_from_rgba8(oc_canvas_renderer renderer, u32 width, u32 height, u8* pixels);
97+
oc_image oc_image_create_from_memory(oc_canvas_renderer renderer, oc_str8 mem, bool flip);
98+
oc_image oc_image_create_from_file(oc_canvas_renderer renderer, oc_file file, bool flip);
99+
oc_image oc_image_create_from_path(oc_canvas_renderer renderer, oc_str8 path, bool flip);
100+
void oc_image_destroy(oc_image image);
101+
void oc_image_upload_region_rgba8(oc_image image, oc_rect region, u8* pixels);
102+
oc_vec2 oc_image_size(oc_image image);
36103

37104
//------------------------------------------------------------------------------------------
38-
// transform and clipping
105+
//atlasing
39106
//------------------------------------------------------------------------------------------
40107

108+
oc_rect_atlas* oc_rect_atlas_create(oc_arena* arena, i32 width, i32 height);
109+
oc_rect oc_rect_atlas_alloc(oc_rect_atlas* atlas, i32 width, i32 height);
110+
void oc_rect_atlas_recycle(oc_rect_atlas* atlas, oc_rect rect);
111+
oc_image_region oc_image_atlas_alloc_from_rgba8(oc_rect_atlas* atlas, oc_image backingImage, u32 width, u32 height, u8* pixels);
112+
oc_image_region oc_image_atlas_alloc_from_memory(oc_rect_atlas* atlas, oc_image backingImage, oc_str8 mem, bool flip);
113+
oc_image_region oc_image_atlas_alloc_from_file(oc_rect_atlas* atlas, oc_image backingImage, oc_file file, bool flip);
114+
oc_image_region oc_image_atlas_alloc_from_path(oc_rect_atlas* atlas, oc_image backingImage, oc_str8 path, bool flip);
115+
void oc_image_atlas_recycle(oc_rect_atlas* atlas, oc_image_region imageRgn);
116+
117+
//------------------------------------------------------------------------------------------
118+
//transform, viewport and clipping
119+
//------------------------------------------------------------------------------------------
41120
void oc_matrix_push(oc_mat2x3 matrix);
42121
void oc_matrix_multiply_push(oc_mat2x3 matrix);
43122
void oc_matrix_pop(void);
44123
oc_mat2x3 oc_matrix_top();
45-
46124
void oc_clip_push(f32 x, f32 y, f32 w, f32 h);
47125
void oc_clip_pop(void);
48126
oc_rect oc_clip_top();
49127

50128
//------------------------------------------------------------------------------------------
51-
// graphics attributes setting/getting
129+
//graphics attributes setting/getting
52130
//------------------------------------------------------------------------------------------
53131
void oc_set_color(oc_color color);
54132
void oc_set_color_rgba(f32 r, f32 g, f32 b, f32 a);
133+
void oc_set_color_srgba(f32 r, f32 g, f32 b, f32 a);
134+
void oc_set_gradient(oc_gradient_blend_space blendSpace, oc_color bottomLeft, oc_color bottomRight, oc_color topRight, oc_color topLeft);
55135
void oc_set_width(f32 width);
56136
void oc_set_tolerance(f32 tolerance);
57137
void oc_set_joint(oc_joint_type joint);
@@ -73,9 +153,10 @@ oc_font oc_get_font(void);
73153
f32 oc_get_font_size(void);
74154
bool oc_get_text_flip(void);
75155
oc_image oc_get_image();
156+
oc_rect oc_get_image_source_region();
76157

77158
//------------------------------------------------------------------------------------------
78-
// path construction
159+
//path construction
79160
//------------------------------------------------------------------------------------------
80161
oc_vec2 oc_get_position(void);
81162
void oc_move_to(f32 x, f32 y);
@@ -89,14 +170,14 @@ void oc_codepoints_outlines(oc_str32 string);
89170
void oc_text_outlines(oc_str8 string);
90171

91172
//------------------------------------------------------------------------------------------
92-
// clear/fill/stroke
173+
//clear/fill/stroke
93174
//------------------------------------------------------------------------------------------
94175
void oc_clear(void);
95176
void oc_fill(void);
96177
void oc_stroke(void);
97178

98179
//------------------------------------------------------------------------------------------
99-
// shapes helpers
180+
//shapes helpers
100181
//------------------------------------------------------------------------------------------
101182
void oc_rectangle_fill(f32 x, f32 y, f32 w, f32 h);
102183
void oc_rectangle_stroke(f32 x, f32 y, f32 w, f32 h);
@@ -107,60 +188,9 @@ void oc_ellipse_stroke(f32 x, f32 y, f32 rx, f32 ry);
107188
void oc_circle_fill(f32 x, f32 y, f32 r);
108189
void oc_circle_stroke(f32 x, f32 y, f32 r);
109190
void oc_arc(f32 x, f32 y, f32 r, f32 arcAngle, f32 startAngle);
110-
void oc_image_draw(oc_image image, oc_rect rect);
111-
void oc_image_draw_region(oc_image image, oc_rect srcRegion, oc_rect dstRegion);
112-
113-
//------------------------------------------------------------------------------------------
114-
// fonts
115-
//------------------------------------------------------------------------------------------
116-
oc_font oc_font_nil(void);
117-
bool oc_font_is_nil(oc_font font);
118191

119-
oc_font oc_font_create_from_memory(oc_str8 mem, u32 rangeCount, oc_unicode_range* ranges);
120-
oc_font oc_font_create_from_file(oc_file file, u32 rangeCount, oc_unicode_range* ranges);
121-
oc_font oc_font_create_from_path(oc_str8 path, u32 rangeCount, oc_unicode_range* ranges);
122-
123-
void oc_font_destroy(oc_font font);
124-
125-
oc_str32 oc_font_get_glyph_indices(oc_font font, oc_str32 codePoints, oc_str32 backing);
126-
oc_str32 oc_font_push_glyph_indices(oc_arena* arena, oc_font font, oc_str32 codePoints);
127-
u32 oc_font_get_glyph_index(oc_font font, oc_utf32 codePoint);
128-
129-
oc_font_metrics oc_font_get_metrics(oc_font font, f32 emSize);
130-
oc_font_metrics oc_font_get_metrics_unscaled(oc_font font);
131-
f32 oc_font_get_scale_for_em_pixels(oc_font font, f32 emSize);
132-
133-
oc_text_metrics oc_font_text_metrics_utf32(oc_font font, f32 fontSize, oc_str32 codepoints);
134-
oc_text_metrics oc_font_text_metrics(oc_font font, f32 fontSize, oc_str8 text);
192+
void oc_text_fill(f32 x, f32 y, oc_str8 text);
135193

136-
//------------------------------------------------------------------------------------------
137-
// images
138-
//------------------------------------------------------------------------------------------
139-
oc_image oc_image_nil(void);
140-
bool oc_image_is_nil(oc_image a);
141-
142-
oc_image oc_image_create(oc_surface surface, u32 width, u32 height);
143-
oc_image oc_image_create_from_rgba8(oc_surface surface, u32 width, u32 height, u8* pixels);
144-
oc_image oc_image_create_from_memory(oc_surface surface, oc_str8 mem, bool flip);
145-
oc_image oc_image_create_from_file(oc_surface surface, oc_file file, bool flip);
146-
oc_image oc_image_create_from_path(oc_surface surface, oc_str8 path, bool flip);
147-
148-
void oc_image_destroy(oc_image image);
149-
150-
void oc_image_upload_region_rgba8(oc_image image, oc_rect region, u8* pixels);
151-
oc_vec2 oc_image_size(oc_image image);
152-
153-
//------------------------------------------------------------------------------------------
154-
// image atlas
155-
//------------------------------------------------------------------------------------------
156-
157-
oc_rect_atlas* oc_rect_atlas_create(oc_arena* arena, i32 width, i32 height);
158-
oc_rect oc_rect_atlas_alloc(oc_rect_atlas* atlas, i32 width, i32 height);
159-
void oc_rect_atlas_recycle(oc_rect_atlas* atlas, oc_rect rect);
160-
161-
oc_image_region oc_image_atlas_alloc_from_rgba8(oc_rect_atlas* atlas, oc_image backingImage, u32 width, u32 height, u8* pixels);
162-
oc_image_region oc_image_atlas_alloc_from_memory(oc_rect_atlas* atlas, oc_image backingImage, oc_str8 mem, bool flip);
163-
oc_image_region oc_image_atlas_alloc_from_file(oc_rect_atlas* atlas, oc_image backingImage, oc_file file, bool flip);
164-
oc_image_region oc_image_atlas_alloc_from_path(oc_rect_atlas* atlas, oc_image backingImage, oc_str8 path, bool flip);
165-
166-
void oc_image_atlas_recycle(oc_rect_atlas* atlas, oc_image_region imageRgn);
194+
//NOTE: image helpers
195+
void oc_image_draw(oc_image image, oc_rect rect);
196+
void oc_image_draw_region(oc_image image, oc_rect srcRegion, oc_rect dstRegion);

0 commit comments

Comments
 (0)