-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOV.h
1283 lines (850 loc) · 38.4 KB
/
BOV.h
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*************************************************************************
* BOV 0.1
* A wrapper around OpenGL and GLFW (www.glfw.org) to draw simple 2D
* graphics.
*------------------------------------------------------------------------
* Copyright (c) 2019-2020 Célestin Marot <marotcelestin@gmail.com>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would
* be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*
*************************************************************************/
#ifndef BOV_H_
#define BOV_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
/* opaque structures */
typedef struct bov_window_struct bov_window_t;
typedef struct bov_order_struct bov_order_t;
typedef struct bov_text_struct bov_text_t;
typedef struct bov_points_struct bov_points_t;
/***
* _____ _ _ _ _____ _____
* | __ \ | | | |(_) /\ | __ \|_ _|
* | |__) |_ _ | |__ | | _ ___ / \ | |__) | | |
* | ___/| | | || '_ \ | || | / __| / /\ \ | ___/ | |
* | | | |_| || |_) || || || (__ / ____ \ | | _| |_
* |_| \__,_||_.__/ |_||_| \___| /_/ \_\|_| |_____|
*
*
*/
/* a bov_space_type_t can be given to the functions text_set_space_type() and
* points_set_space_type() */
typedef enum {
USUAL_SPACE = 0, // you can zoom and translate the space in which
// the object is embeded
UNZOOMABLE_SPACE = 1, // zooming will not change the size of the object
PIXEL_SPACE = 2, // unzoomable, unmovable and positon and width/height
// must be given in pixel coordinates.
// In addition, the origin of the screen is the bottom
// left corner and not the center
} bov_space_type_t;
/*%%%%%%%%%%%%%%%%%%%%%%%%%
% Window
%%%%%%%%%%%%%%%%%%%%%%%%%*/
/* creating a window is probably the first thing a program must do.
*
* `width` is either:
* - the width of the window in pixel
* - 0 for full screen
* - a negative number for a maximized window
*
* `height` is either:
* - the height of the window in pixel
* - 0 for full screen
* - negative height for a fixed size window
*
* win_name is the title of the window
* return a window object
*/
bov_window_t* bov_window_new(int width,
int height,
const char* win_name);
/* Once something was drawn to the framebuffer, the window must be updated to
* display the content of the framebuffer on the screen. Updating the window
* also handles the mouse and keyboard inputs, thus you must redraw your scene
* frequently even if nothing changed in order to get smooth input handling.
*/
void bov_window_update(bov_window_t* window);
/* same as bov_window_update but wait for input events before clearing the screen
*/
void bov_window_update_and_wait_events(bov_window_t* window);
/* delete the window properly */
void bov_window_delete(bov_window_t* window);
/*%%%%%%%%%%%%%%%%%%%%%%%%%
% Text
%%%%%%%%%%%%%%%%%%%%%%%%%*/
/* Create a text object from a string. string a null-terminated C string
*
* `usage` is either:
* - GL_STATIC_DRAW if you don't intend to change the content of the text
* object (the string of characters)
* - GL_DYNAMIC_DRAW if you intend to change it with the text_update function
*/
bov_text_t* bov_text_new(const GLubyte* string,
GLenum usage);
/* change the content of the text object */
bov_text_t* bov_text_update(bov_text_t* text,
const GLubyte* string);
/* draw a text object, using a text rasterizer (note: a text rasterizer can be
* used to draw multiple text object)*/
void bov_text_draw(bov_window_t* window,
const bov_text_t* text);
/* delete text properly */
void bov_text_delete(bov_text_t* text);
/*%%%%%%%%%%%%%%%%%%%%%%%%%
% Points
%%%%%%%%%%%%%%%%%%%%%%%%%*/
#define BOV_TILL_END (0x7FFFFFFFUL)
/* Create a points object
*
* `coord` is either:
* - an array of coordinates, interleaved : x1, y1, x2, y2, ... xn, yn
* => n is the number of points and the maximum capacity
* - NULL, in which case a points object is created with a maximum capacity
* of n points
*
* `usage` is either:
* - GL_STATIC_DRAW if you don't intend to update the coordinates of the
* points regularly
* - GL_DYNAMIC_DRAW if you intend to change coordinates regularly with the
* points_update or points_partial_update function
*/
bov_points_t* bov_points_new(const GLfloat coords[][2],
GLsizei n,
GLenum usage);
/* change the content of the points object (the maximum capacity can be increased)*/
bov_points_t* bov_points_update(bov_points_t* points,
const GLfloat coords[][2],
GLsizei n);
/* change the content of the points object, but only from start to
* start+count excluded.
*
* `newN` is the new number of points contained in the points object, or 0 to keep
* the same size.
* `newN` can only be lower than the maximum number of points that has been
* contained in the given points object (the capacity cannot be increased)
*/
bov_points_t* bov_points_partial_update(bov_points_t* points,
const GLfloat coords[][2],
GLint start,
GLsizei count,
GLsizei newN);
/* draw points markers to the window
*
* `start` is the index of the first point to draw
* `count` is the number of points to draw
* if `count` is greater than the number of points, all the points are drawn.
* the value TILL_END is guaranteed to be greater than the number of points.
*/
static inline void bov_points_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
// using the order defined by the order object
static inline void bov_points_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* same argument as above, but draw lines between pairs of points,
* (p1->p2) (p3->p4) (p5->p6)...
*
* line are only drawn when both points are withing [start, start+count[,
* so only the even part of count is taken into account
*/
static inline void bov_lines_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_lines_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* same as bov_lines_draw(with_order)() using default shaders =>
* the default shaders are pretty basic, they just display thin lines of the
* selected color, without outline, without anti-aliasing, without taking the
* width into account.
*/
static inline void bov_fast_lines_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_fast_lines_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* draw lines that connect each points p1->p2->p3->p4->p5->p6...->pn */
static inline void bov_line_strip_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_line_strip_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* same as bov_line_strip_draw(with_order) using default shaders.
* see bov_fast_lines_draw() for what the default shaders is missing. */
static inline void bov_fast_line_strip_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_fast_line_strip_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* draw lines that connect each points and end with the first
* p1->p2->p3->p4->p5->p6...->pn->p1*/
static inline void bov_line_loop_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_line_loop_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* same as bov_line_loop_draw(with_order) using default shaders.
* see bov_fast_lines_draw() for what the default shaders is missing. */
static inline void bov_fast_line_loop_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_fast_line_loop_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* draw a single line that connect each points p1->p2->p3->p4->p5->p6...->pn
* The difference with line_strip_draw can really be seen with an outline or
* transparency */
static inline void bov_curve_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_curve_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
static inline void bov_triangles_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_triangles_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* same as bov_triangles_draw(with_order) using default shaders.
* the default shaders are pretty basic, they just display thin triangles of the
* selected color, without outline, without anti-aliasing, without taking the
* width into account.
*/
static inline void bov_fast_triangles_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_fast_triangles_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
static inline void bov_triangle_strip_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_triangle_strip_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* same as bov_triangle_strip_draw(with_order) using default shaders.
* see bov_fast_triangles_draw() for what the default shaders is missing. */
static inline void bov_fast_triangle_strip_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_fast_triangle_strip_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
static inline void bov_triangle_fan_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_triangle_fan_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* same as bov_triangle_fan_draw(with_order) using default shaders.
* see bov_fast_triangles_draw() for what the default shaders is missing. */
static inline void bov_fast_triangle_fan_draw(bov_window_t* window,
const bov_points_t* pts,
GLint start,
GLsizei count);
static inline void bov_fast_triangle_fan_draw_with_order(bov_window_t* window,
const bov_points_t* pts,
const bov_order_t* order,
GLint start,
GLsizei count);
/* delete a points object WORKS FOR BOTH ! */
void bov_points_delete(bov_points_t* points);
/*%%%%%%%%%%%%%%%%%%%%%%%%%
% Order
%%%%%%%%%%%%%%%%%%%%%%%%%*/
/* Create an order object, that enables to draw only certain points, or to draw
* lines that connect different points.
*
* `elements` is either:
* - an array of indices (the indices of the point that we will draw) => n
* is the number of indices
* - NULL, in which case an order object is created with a maximum capacity
* of n indices
*
* `usage` is either:
* - GL_STATIC_DRAW if you don't intend to update the content of the order
* object regularly
* - GL_DYNAMIC_DRAW if you intend to change it regularly with the
* order_update or order_partial_update function
*/
bov_order_t* bov_order_new(const GLuint* elements,
GLsizei n,
GLenum usage);
/* Change the content of the order object. */
bov_order_t* bov_order_update(bov_order_t* order,
const GLuint* elements,
GLsizei n);
/* change the content of the points object, but only from start to
* start+count excluded.
*
* `newN` is the new number of indices contained in the order object, or 0 to
* keep the same size.
* `newN` can only be lower than the maximum number of indices that has been
* contained in the given order object (the capacity cannot be increased)
*/
bov_order_t* bov_order_partial_update(bov_order_t* order,
const GLuint* elements,
GLint start,
GLsizei count,
GLsizei newN);
/* delete an order object */
void bov_order_delete(bov_order_t* order);
/*%%%%%%%%%%%%%%%%%%%%%%%%%
% Window parameters
%%%%%%%%%%%%%%%%%%%%%%%%%*/
/* get the time in second associated with the window. The time is updated via
* the bov_window_update() and bov_window_update_and_wait_events() functions.
* The time is stopped if the user press the space bar. */
static inline double bov_window_get_time(const bov_window_t* window);
/* get the value of the counter associated to a window. The counter is set to
* 0 at window creation. It is incremented every time the user hit the up
* arrow key, and decremented every time the user hit the down arrow key.
*/
static inline unsigned bov_window_get_counter(const bov_window_t* window);
static inline void bov_window_set_counter(bov_window_t* window,
unsigned counter);
/* get the resolution in pixel of the window */
static inline GLfloat bov_window_get_xres(const bov_window_t* window);
static inline GLfloat bov_window_get_yres(const bov_window_t* window);
/* tells if the window should close (because the user decided it) */
static inline int bov_window_should_close(const bov_window_t* window);
/* sets the background color with a 4-channel color (red, blue, green, alpha).
* The alpha channel (transparency) is useless here */
static inline void bov_window_set_color(bov_window_t* window,
const GLfloat rgba[4]);
/* translates the content of the window (similar to dragging with the mouse */
static inline void bov_window_translate(bov_window_t* window,
const GLfloat pos[2]);
/* set the scaling factor of the whole window content (similar to zooming with
* the mouse) */
static inline void bov_window_set_zoom(bov_window_t* window,
GLfloat zoom);
/* get the current zooming factor */
static inline GLfloat bov_window_get_zoom(const bov_window_t* window);
/* enable/disable a little help message for keyboard shortcuts */
static inline void bov_window_enable_help(bov_window_t* window);
static inline void bov_window_disable_help(bov_window_t* window);
/* take a screenshot and save it as a PPM with the name 'filename' */
void bov_window_screenshot(const bov_window_t* window,
const char* filename);
/*%%%%%%%%%%%%%%%%%%%%%%%%%
% text parameters
%%%%%%%%%%%%%%%%%%%%%%%%%*/
/* set the position of the text on the screen.
* Note that coordinates must be given in pixels if the space type is set to
* PIXEL_SPACE*/
static inline void bov_text_set_pos(bov_text_t* text,
const GLfloat pos[2]);
/* set the font size of the text object on the screen.
* The font size is equal to the baselineskip, which is
* the height of a line of characters.
* The width of each character == baselineskip/2.
* Note that the baselineskip must be given in pixels if
* the space type is set to PIXEL_SPACE */
static inline void bov_text_set_fontsize(bov_text_t* text,
GLfloat baselineskip);
/* sets the text color to a 4 channel color (red, gree, blue, alpha) */
static inline void bov_text_set_color(bov_text_t* text,
const GLfloat rgba[4]);
/* boldness is a parameter, usually between -1 and 1, that define
* how massive the font should be. -1 means light, 1 means bold */
static inline void bov_text_set_boldness(bov_text_t* text,
GLfloat width);
/* sets the text outline color to a 4 channel color (red, gree, blue, alpha) */
static inline void bov_text_set_outline_color(bov_text_t* text,
const GLfloat rgba[4]);
/* for text, the outline width must be between 0 and 1
* 0 means no outline, 1 means the outline might meet in the middle of the character */
static inline void bov_text_set_outline_width(bov_text_t* text,
GLfloat width);
/* the outline can be slightly shifted in some direction.
* More specifically, if you have a normal vector to the font 'n',
* and a shift vector 's', and an outline width 'w', then we will have
* a new outline width 'w = w + dot(s,n)'.
* For example, if we have an outline width of 0.2, and a shift vector of
* (0.1, 0.0), the outline will be 0.3 on the right of each character and
* 0.1 on the left of each character
*
* Note: font with an outline shift can become very bad when zoom in.
* actually, it uses the gradient of the sdf based font to calculate
* the normal, and this gradient approaches 0 when zoomed in...
*/
static inline void bov_text_set_outline_shift(bov_text_t* text,
const GLfloat shift[2]);
/* for more detail on what this function does, see:
* - the structure `bov_space_type_t`
* - the function `bov_text_set_pos()` and `text_set_fontsize()`
*
* Changing the spaceType of a text object to PIXEL_SPACE also sets its
* position and scaling to meaningfull values (negative positions are set to
* zero, fontSize less than 32 are set to 32) */
static inline void bov_text_set_space_type(bov_text_t* text,
bov_space_type_t spaceType);
/* a structure to hold all the parameters of a text object */
typedef struct {
GLfloat fillColor[4];
GLfloat outlineColor[4];
GLfloat pos[2];
GLfloat shift[2];
GLfloat fontSize;
GLfloat boldness;
GLfloat outlineWidth;
bov_space_type_t spaceType;
} bov_text_param_t;
/* retrieve all the parameters from a text object */
static inline bov_text_param_t bov_text_get_param(const bov_text_t* text);
/* set all the parameters of a text object at once */
static inline void bov_text_set_param(bov_text_t* text,
bov_text_param_t parameters);
/*%%%%%%%%%%%%%%%%%%%%%%%%%
% points parameters
%%%%%%%%%%%%%%%%%%%%%%%%%*/
/* set the position of the points on the screen.
* Note that coordinates must be given in pixels if the space type is set to
* PIXEL_SPACE*/
static inline void bov_points_set_pos(bov_points_t* points,
const GLfloat pos[2]);
/* you can give a local scaling factor to your set of points in both x and y
* directions. The translation given by points_set_pos() is applied AFTER the
* local scaling, so it is not impacted by the scaling. The local scaling
* factors is only applied to point coordinates, not to the width and outline
* width*/
static inline void bov_points_scale(bov_points_t* points,
const GLfloat scale[2]);
/* set the width of the marker/line/curve/... associated with the points
* Note that the width must be given in pixels if the space type is set to
* PIXEL_SPACE*/
static inline void bov_points_set_width(bov_points_t* points,
GLfloat width);
/* sets color of the marker/line/curve/... associated with the points to a 4
* channel color (red, gree, blue, alpha) */
static inline void bov_points_set_color(bov_points_t* points,
const GLfloat rgba[4]);
static inline void bov_points_set_outline_color(bov_points_t* points,
const GLfloat rgba[4]);
static inline void bov_points_set_outline_width(bov_points_t* points,
GLfloat width);
/* TODO: document the different shapes */
static inline void bov_points_set_marker(bov_points_t* points,
GLfloat marker);
/* for more detail on what this function does, see:
* - the structure `bov_space_type_t`
* - the function `bov_points_set_pos()` and `points_set_width()`
*
* Changing the spaceType of a text object to PIXEL_SPACE also sets its
* position and scaling to meaningfull values (negative positions are set to
* zero, width less than 32 are set to 32) */
static inline void bov_points_set_space_type(bov_points_t* points,
bov_space_type_t spaceType);
/* a structure to hold all the parameters of a points object */
typedef struct {
GLfloat fillColor[4];
GLfloat outlineColor[4];
GLfloat pos[2];
GLfloat scale[2];
GLfloat width;
GLfloat marker;
GLfloat outlineWidth;
bov_space_type_t spaceType;
} bov_points_param_t;
/* retrieve all the parameters from a points object */
static inline bov_points_param_t bov_points_get_param(const bov_points_t* points);
/* set all the parameters of a points object at once */
static inline void bov_points_set_param(bov_points_t* points,
bov_points_param_t parameters);
/*%%%%%%%%%%%%%%%%%%%%%%%%%
% error_log
%%%%%%%%%%%%%%%%%%%%%%%%%*/
/* some error code in addition to those defined by GLFW (www.glfw.org/docs/latest/group__errors.html) */
#define BOV_PARAMETER_ERROR (0x00020001)
#define BOV_SHADER_ERROR (0x00020002)
#define BOV_FRAMEBUFFER_ERROR (0x00020003)
#define BOV_GLAD_ERROR (0x00020004)
#define BOV_OUT_OF_MEM_ERROR (0x00030001)
#define BOV_IO_ERROR (0x00030002)
/* display an error with BOV_ERROR_LOG, for example :
* if(parameter_not_valid) {
* BOV_ERROR_LOG(BOV_PARAMETER_ERROR, "parameter XX must be positive !");
* return NULL;
*/
#ifndef NDEBUG
#define BOV_ERROR_LOG(errorCode, fmt, ...) do{ \
bov_error_log(errorCode, fmt, ## __VA_ARGS__ ); \
fprintf(stderr, "\t(in function %s, line %d)\n", __func__, __LINE__); \
}while(0)
#else
#define BOV_ERROR_LOG(errorCode,fmt, ...) \
bov_error_log(errorCode, fmt, ## __VA_ARGS__ )
#endif
/***********************************************************************************/
/* __| | ___ _ __ |/| |_ | | ___ ___ | | __ | |__ ___| | _____ __
* / _` |/ _ \| '_ \ | __| | |/ _ \ / _ \| |/ / | '_ \ / _ \ |/ _ \ \ /\ / /
* | (_| | (_) | | | | | |_ | | (_) | (_) | < | |_) | __/ | (_) \ V V /
* \__,_|\___/|_| |_| \__| |_|\___/ \___/|_|\_\ |_.__/ \___|_|\___/ \_/\_/
* (seriously)
*/
/* _____ _____ _____ __ __ _______ ______
* | __ \ | __ \ |_ _|\ \ / //\ |__ __|| ____|
* | |__) || |__) | | | \ \ / // \ | | | |__
* | ___/ | _ / | | \ \/ // /\ \ | | | __|
* | | | | \ \ _| |_ \ // ____ \ | | | |____
* |_| |_| \_\|_____| \//_/ \_\|_| |______|
*/
typedef struct {
GLfloat res[2];
GLfloat translate[2];
GLfloat zoom;
} bov_world_param_t;
struct bov_window_struct
{
GLFWwindow* self;
GLFWcursor* leftClickCursor;
bov_world_param_t param;
GLfloat backgroundColor[4];
int size[2]; // size of window (might not be in pixel => !=framebuffer)
double cursorPos[2]; // new position of the cursor in screen coordinates
double clickTime[2]; // time of the click (left and right) or -1 if released
double wtime;
unsigned counter;
GLuint ubo[2]; // 1 ubo for world params, 1 ubo for points and text params
int last_program;
GLuint program[8];
GLuint font_atlas_texture;
int running;
bov_text_t* help;
int help_needed;
bov_text_t* indication;
int indication_needed;
};
struct bov_text_struct {
GLuint vao;
GLuint vbo;
GLsizei vboCapacity; // capacity of the vbo
GLsizei vboLen; // number of letter in vbo
// const GLubyte* string;
GLsizei dataCapacity; // length of the string
GLfloat* data;
bov_text_param_t param;
};
struct bov_points_struct{
GLuint vao;
GLuint vbo;
GLsizei vboCapacity;
GLsizei vboLen;
bov_points_param_t param;
};
static inline double bov_window_get_time(const bov_window_t* window)
{
return window->wtime;
}
static inline unsigned bov_window_get_counter(const bov_window_t* window)
{
return window->counter;
}
static inline void bov_window_set_counter(bov_window_t* window,
unsigned counter)
{
window->counter = counter;