11
11
#endif
12
12
13
13
// GLOBAL VARIABLES
14
- // GLFWwindow *_window;
15
14
char _window_title [100 ] = {0 };
16
15
int _window_loop = 1 ;
17
16
int _window_width = 0 ;
@@ -32,7 +31,6 @@ double _cursor_last_y = 0.0;
32
31
int _cursor_is_dragging = 0 ;
33
32
int _ui_engaged = 0 ;
34
33
35
- gl_char_t _chars [128 ];
36
34
int _key_q = 0 ;
37
35
int _key_w = 0 ;
38
36
int _key_a = 0 ;
@@ -603,28 +601,28 @@ int gl_save_frame_buffer(const int width, const int height, const char *fp) {
603
601
604
602
void gl_shader_setup (gl_shader_t * shader ) {
605
603
shader -> program_id = 0 ;
606
- shader -> texture_id = 0 ;
607
- shader -> VAO = 0 ;
608
- shader -> VBO = 0 ;
609
- shader -> EBO = 0 ;
604
+ // shader->texture_id = 0;
605
+ // shader->VAO = 0;
606
+ // shader->VBO = 0;
607
+ // shader->EBO = 0;
610
608
}
611
609
612
610
void gl_shader_cleanup (gl_shader_t * shader ) {
613
611
if (glIsProgram (shader -> program_id ) == GL_TRUE ) {
614
612
glDeleteProgram (shader -> program_id );
615
613
}
616
614
617
- if (glIsVertexArray (shader -> VAO ) == GL_TRUE ) {
618
- glDeleteVertexArrays (1 , & shader -> VAO );
619
- }
620
-
621
- if (glIsBuffer (shader -> VBO ) == GL_TRUE ) {
622
- glDeleteBuffers (1 , & shader -> VBO );
623
- }
624
-
625
- if (glIsBuffer (shader -> EBO ) == GL_TRUE ) {
626
- glDeleteBuffers (1 , & shader -> EBO );
627
- }
615
+ // if (glIsVertexArray(shader->VAO) == GL_TRUE) {
616
+ // glDeleteVertexArrays(1, &shader->VAO);
617
+ // }
618
+ //
619
+ // if (glIsBuffer(shader->VBO) == GL_TRUE) {
620
+ // glDeleteBuffers(1, &shader->VBO);
621
+ // }
622
+ //
623
+ // if (glIsBuffer(shader->EBO) == GL_TRUE) {
624
+ // glDeleteBuffers(1, &shader->EBO);
625
+ // }
628
626
}
629
627
630
628
gl_uint_t gl_compile (const char * src , const int type ) {
@@ -2001,7 +1999,6 @@ void setup_points3d_shader(gl_shader_t *shader) {
2001
1999
if (shader -> program_id == GL_FALSE ) {
2002
2000
FATAL ("Failed to create shaders to draw points!" );
2003
2001
}
2004
- shader -> VAO = 0 ;
2005
2002
}
2006
2003
2007
2004
void gl_points3d_setup (gl_points3d_t * points3d ,
@@ -2092,7 +2089,6 @@ void setup_line3d_shader(gl_shader_t *shader) {
2092
2089
if (shader -> program_id == GL_FALSE ) {
2093
2090
FATAL ("Failed to create shaders!" );
2094
2091
}
2095
- shader -> VAO = -1 ;
2096
2092
}
2097
2093
2098
2094
void gl_line3d_setup (gl_line3d_t * line ,
@@ -2196,8 +2192,6 @@ void setup_image_shader(gl_shader_t *shader) {
2196
2192
if (shader -> program_id == GL_FALSE ) {
2197
2193
FATAL ("Failed to create shaders!" );
2198
2194
}
2199
- shader -> texture_id = -1 ;
2200
- shader -> VAO = -1 ;
2201
2195
}
2202
2196
2203
2197
void gl_image_setup (gl_image_t * image ,
@@ -2358,24 +2352,21 @@ void gl_char_print(const gl_char_t *ch) {
2358
2352
2359
2353
void setup_text_shader (gl_shader_t * shader ) {
2360
2354
assert (shader );
2361
-
2362
- // Setup
2363
- const gl_float_t text_size = 18 ;
2364
-
2365
- // Compile shader
2366
2355
gl_shader_setup (shader );
2367
2356
shader -> program_id = gl_shader (GL_TEXT_VS , GL_TEXT_FS , NULL );
2368
2357
if (shader -> program_id == GL_FALSE ) {
2369
2358
FATAL ("Failed to create shaders!" );
2370
2359
}
2360
+ }
2371
2361
2362
+ void gl_text_setup (gl_text_t * text , const int text_size ) {
2372
2363
// VAO
2373
- glGenVertexArrays (1 , & shader -> VAO );
2374
- glBindVertexArray (shader -> VAO );
2364
+ glGenVertexArrays (1 , & text -> VAO );
2365
+ glBindVertexArray (text -> VAO );
2375
2366
2376
2367
// VBO
2377
- glGenBuffers (1 , & shader -> VBO );
2378
- glBindBuffer (GL_ARRAY_BUFFER , shader -> VBO );
2368
+ glGenBuffers (1 , & text -> VBO );
2369
+ glBindBuffer (GL_ARRAY_BUFFER , text -> VBO );
2379
2370
glBufferData (GL_ARRAY_BUFFER , sizeof (float ) * 6 * 4 , NULL , GL_DYNAMIC_DRAW );
2380
2371
glVertexAttribPointer (0 , 4 , GL_FLOAT , GL_FALSE , 4 * sizeof (float ), 0 );
2381
2372
glEnableVertexAttribArray (0 );
@@ -2439,40 +2430,45 @@ void setup_text_shader(gl_shader_t *shader) {
2439
2430
glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR );
2440
2431
2441
2432
// Store character for later use
2442
- _chars [c ].texture_id = texture_id ;
2443
- _chars [c ].size [0 ] = face -> glyph -> bitmap .width ;
2444
- _chars [c ].size [1 ] = face -> glyph -> bitmap .rows ;
2445
- _chars [c ].bearing [0 ] = face -> glyph -> bitmap_left ;
2446
- _chars [c ].bearing [1 ] = face -> glyph -> bitmap_top ;
2447
- _chars [c ].offset = face -> glyph -> advance .x ;
2433
+ text -> chars [c ].texture_id = texture_id ;
2434
+ text -> chars [c ].size [0 ] = face -> glyph -> bitmap .width ;
2435
+ text -> chars [c ].size [1 ] = face -> glyph -> bitmap .rows ;
2436
+ text -> chars [c ].bearing [0 ] = face -> glyph -> bitmap_left ;
2437
+ text -> chars [c ].bearing [1 ] = face -> glyph -> bitmap_top ;
2438
+ text -> chars [c ].offset = face -> glyph -> advance .x ;
2448
2439
}
2449
2440
glBindTexture (GL_TEXTURE_2D , 0 );
2450
2441
FT_Done_Face (face );
2451
2442
FT_Done_FreeType (ft );
2452
2443
}
2453
2444
2454
- void text_width_height (const char * s , gl_float_t * w , gl_float_t * h ) {
2445
+ void text_width_height (gl_text_t * text ,
2446
+ const char * s ,
2447
+ gl_float_t * w ,
2448
+ gl_float_t * h ) {
2455
2449
assert (s );
2456
2450
assert (w );
2457
2451
assert (h );
2458
2452
2459
2453
float x = 0.0f ;
2460
- gl_char_t * hch = & _chars [(int ) 'H' ];
2461
- gl_char_t * ch = & _chars [(int ) s [0 ]];
2454
+ gl_char_t * hch = & text -> chars [(int ) 'H' ];
2455
+ gl_char_t * ch = & text -> chars [(int ) s [0 ]];
2462
2456
2463
2457
for (size_t i = 0 ; i < strlen (s ); ++ i ) {
2464
- ch = & _chars [(int ) s [i ]];
2458
+ ch = & text -> chars [(int ) s [i ]];
2465
2459
x += (ch -> offset >> 6 );
2466
2460
}
2467
2461
2468
2462
* w = x + ch -> bearing [0 ];
2469
2463
* h = (hch -> bearing [1 ] - ch -> bearing [1 ]) + ch -> size [1 ];
2470
2464
}
2471
2465
2472
- void draw_text (const char * s ,
2466
+ void draw_text (gl_text_t * text ,
2467
+ const char * s ,
2473
2468
const float x ,
2474
2469
const float y ,
2475
2470
const gl_color_t c ) {
2471
+ assert (text );
2476
2472
assert (s );
2477
2473
2478
2474
// Setup projection matrix
@@ -2488,13 +2484,13 @@ void draw_text(const char *s,
2488
2484
gl_set_color (shader -> program_id , "text_color" , c );
2489
2485
gl_set_int (shader -> program_id , "text" , 0 );
2490
2486
glActiveTexture (GL_TEXTURE0 );
2491
- glBindVertexArray (shader -> VAO );
2487
+ glBindVertexArray (text -> VAO );
2492
2488
2493
2489
// Render text
2494
2490
float x_ = x ;
2495
- gl_char_t * hch = & _chars [(int ) 'H' ];
2491
+ gl_char_t * hch = & text -> chars [(int ) 'H' ];
2496
2492
for (size_t i = 0 ; i < strlen (s ); ++ i ) {
2497
- gl_char_t * ch = & _chars [(int ) s [i ]];
2493
+ gl_char_t * ch = & text -> chars [(int ) s [i ]];
2498
2494
const float xpos = x_ + ch -> bearing [0 ] * scale ;
2499
2495
const float ypos = y + (hch -> bearing [1 ] - ch -> bearing [1 ]) * scale ;
2500
2496
const float w = ch -> size [0 ] * scale ;
@@ -2516,7 +2512,7 @@ void draw_text(const char *s,
2516
2512
glBindTexture (GL_TEXTURE_2D , ch -> texture_id );
2517
2513
2518
2514
// Update content of VBO memory
2519
- glBindBuffer (GL_ARRAY_BUFFER , shader -> VBO );
2515
+ glBindBuffer (GL_ARRAY_BUFFER , text -> VBO );
2520
2516
glBufferSubData (GL_ARRAY_BUFFER , 0 , sizeof (vertices ), vertices );
2521
2517
glBindBuffer (GL_ARRAY_BUFFER , 0 );
2522
2518
0 commit comments