text rendering over vertex arrays, rework fully done, finally

This commit is contained in:
veclav talica 2024-09-18 19:01:43 +03:00
parent 16c96010dc
commit 691d781827
2 changed files with 130 additions and 351 deletions

View File

@ -401,19 +401,20 @@ bool push_text_payload_to_vertex_buffer_builder(struct font_data const *font_dat
stbtt_aligned_quad quad)
{
(void)font_data;
(void)builder;
/* TODO: use vertex arrays */
glTexCoord2f(quad.s0, quad.t0);
glVertex2f(quad.x0, quad.y0);
glTexCoord2f(quad.s1, quad.t0);
glVertex2f(quad.x1, quad.y0);
glTexCoord2f(quad.s1, quad.t1);
glVertex2f(quad.x1, quad.y1);
glTexCoord2f(quad.s0, quad.t1);
glVertex2f(quad.x0, quad.y1);
struct element_indexed_quad_without_color buffer_element = {
.v0 = (t_fvec2){ quad.x0, quad.y0 },
.v1 = (t_fvec2){ quad.x1, quad.y0 },
.v2 = (t_fvec2){ quad.x1, quad.y1 },
.v3 = (t_fvec2){ quad.x0, quad.y1 },
return false;
.uv0 = (t_fvec2){ quad.s0, quad.t0 },
.uv1 = (t_fvec2){ quad.s1, quad.t0 },
.uv2 = (t_fvec2){ quad.s1, quad.t1 },
.uv3 = (t_fvec2){ quad.s0, quad.t1 },
};
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
}
@ -422,14 +423,41 @@ void finally_draw_text(struct font_data const *font_data,
t_color color,
vertex_buffer buffer)
{
(void)len;
(void)buffer;
/* vertex specification */
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2,
GL_FLOAT,
offsetof(struct element_indexed_quad_without_color, v1),
(void *)(size_t)offsetof(struct element_indexed_quad_without_color, v0));
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTexture(GL_TEXTURE0);
glTexCoordPointer(2,
GL_FLOAT,
offsetof(struct element_indexed_quad_without_color, v1),
(void *)(size_t)offsetof(struct element_indexed_quad_without_color, uv0));
bind_quad_element_buffer();
use_texture_mode(TEXTURE_MODE_GHOSTLY);
glBindTexture(GL_TEXTURE_2D, font_data->texture);
glColor4ub(color.r, color.g, color.b, color.a);
glDrawElements(GL_TRIANGLES, 6 * (GLsizei)len, GL_UNSIGNED_SHORT, NULL);
/* clear the state */
glBufferData(GL_ARRAY_BUFFER, 0, NULL, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glBindTexture(GL_TEXTURE_2D, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

View File

@ -3,6 +3,18 @@
{
"selected_items":
[
[
"GL_STRE",
"GL_STREAM_DRAW"
],
[
"GL_RGBA",
"GL_RGBA8"
],
[
"stdb",
"stdbool.h>"
],
[
"twn",
"twn_rendering_platform.h\""
@ -502,111 +514,11 @@
[
"wi",
"window_size_has_changed"
],
[
"SDL_WINDOWEVENT_",
"SDL_WINDOWEVENT_MINIMIZED"
],
[
"GL_ALPHA_",
"GL_ALPHA_TEST"
],
[
"TEXTURE",
"TEXTURE_MODE_SEETHROUGH"
]
]
},
"buffers":
[
{
"file": "include/twn_config.h",
"settings":
{
"buffer_size": 972,
"encoding": "UTF-8",
"line_ending": "Unix"
},
"undo_stack":
[
[
12,
4,
"cut",
null,
"BAAAAMQDAAAAAAAAxAMAAAAAAAABAAAACsQDAAAAAAAAxAMAAAAAAAASAAAALyogMTAyNCAqIDEwMjQgKi8KxAMAAAAAAADEAwAAAAAAACYAAAAvKiAjZGVmaW5lIFVNS0FfU1RBQ0tfU0laRSAxMDQ4NTc2ICovCsQDAAAAAAAAxAMAAAAAAAABAAAACg",
"AwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPC/AAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8L8AAAAAAQAAAMQDAAAAAAAAxAMAAAAAAAAAAAAAAADwvw"
]
]
},
{
"file": "src/rendering/twn_triangles.c",
"settings":
{
"buffer_size": 2969,
"encoding": "UTF-8",
"line_ending": "Unix"
},
"undo_stack":
[
[
23,
1,
"insert",
{
"characters": "twn_"
},
"BQAAACcAAAAAAAAAKAAAAAAAAAAAAAAAKAAAAAAAAAAoAAAAAAAAAAsAAAB0b3duZW5naW5lLygAAAAAAAAAKQAAAAAAAAAAAAAAKQAAAAAAAAAqAAAAAAAAAAAAAAAqAAAAAAAAACsAAAAAAAAAAAAAAA",
"AwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPC/AAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8L8AAAAAAQAAADIAAAAAAAAAJwAAAAAAAAAAAAAAAADwvw"
],
[
27,
1,
"insert",
{
"characters": "wn"
},
"AwAAAEAAAAAAAAAAQQAAAAAAAAAAAAAAQQAAAAAAAABBAAAAAAAAACAAAAB0b3duZW5naW5lL3RleHR1cmVzL2ludGVybmFsX2FwaUEAAAAAAAAAQgAAAAAAAAAAAAAA",
"AwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPC/AAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8L8AAAAAAQAAAEAAAAAAAAAAYAAAAAAAAAAAAAAAAADwvw"
],
[
28,
2,
"left_delete",
null,
"AgAAAEEAAAAAAAAAQQAAAAAAAAABAAAAbkAAAAAAAAAAQAAAAAAAAAABAAAAdw",
"AwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPC/AAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8L8AAAAAAQAAAEIAAAAAAAAAQgAAAAAAAAAAAAAAAADwvw"
],
[
29,
1,
"insert",
{
"characters": "twn_texture"
},
"CwAAAEAAAAAAAAAAQQAAAAAAAAAAAAAAQQAAAAAAAABCAAAAAAAAAAAAAABCAAAAAAAAAEMAAAAAAAAAAAAAAEMAAAAAAAAARAAAAAAAAAAAAAAARAAAAAAAAABFAAAAAAAAAAAAAABFAAAAAAAAAEYAAAAAAAAAAAAAAEYAAAAAAAAARwAAAAAAAAAAAAAARwAAAAAAAABIAAAAAAAAAAAAAABIAAAAAAAAAEkAAAAAAAAAAAAAAEkAAAAAAAAASgAAAAAAAAAAAAAASgAAAAAAAABLAAAAAAAAAAAAAAA",
"AwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPC/AAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8L8AAAAAAQAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAADwvw"
],
[
30,
1,
"insert",
{
"characters": "s_c"
},
"AwAAAEsAAAAAAAAATAAAAAAAAAAAAAAATAAAAAAAAABNAAAAAAAAAAAAAABNAAAAAAAAAE4AAAAAAAAAAAAAAA",
"AwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPC/AAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8L8AAAAAAQAAAEsAAAAAAAAASwAAAAAAAAAAAAAAAADwvw"
]
]
},
{
"file": "include/twn_vec.h",
"settings":
{
"buffer_size": 4341,
"line_ending": "Unix"
}
}
],
"build_system": "",
"build_system_choices":
@ -785,37 +697,74 @@
"expanded_folders":
[
"/home/tochie/Code/townengine",
"/home/tochie/Code/townengine/docs",
"/home/tochie/Code/townengine/include",
"/home/tochie/Code/townengine/apps",
"/home/tochie/Code/townengine/apps/testgame",
"/home/tochie/Code/townengine/src",
"/home/tochie/Code/townengine/src/system"
"/home/tochie/Code/townengine/src/rendering"
],
"file_history":
[
"/mnt/win/tracks/morning-brew.it",
"/home/tochie/Code/townengine/src/rendering/twn_gl_15_rendering.c",
"/home/tochie/Code/townengine/apps/testgame/testgame",
"/home/tochie/Code/townengine/src/rendering/twn_gl_any_rendering.c",
"/home/tochie/Code/townengine/src/rendering/twn_rendering_c.h",
"/home/tochie/Code/townengine/src/twn_textures_c.h",
"/home/tochie/Code/townengine/src/rendering/twn_gpu_texture_c.h",
"/home/tochie/Code/townengine/src/rendering/twn_gl_15_gpu_texture.c",
"/home/tochie/Code/townengine/CMakeLists.txt",
"/home/tochie/Code/townengine/src/rendering/twn_triangles.c",
"/home/tochie/Code/townengine/src/rendering/twn_text_c.h",
"/home/tochie/Code/townengine/src/rendering/twn_text.c",
"/home/tochie/Code/townengine/src/rendering/twn_sprites.c",
"/home/tochie/Code/townengine/src/rendering/twn_rendering.c",
"/home/tochie/Code/townengine/src/rendering/twn_circles.c",
"/home/tochie/Code/townengine/src/rendering/twn_rendering_platform_c.h",
"/home/tochie/Code/townengine/src/rendering/twn_gl_any_rendering_c.h",
"/home/tochie/Code/townengine/src/rendering/twn_gl_15_rendering_c.h",
"/home/tochie/Code/townengine/src/twn_engine_context_c.h",
"/home/tochie/Code/townengine/src/twn_game_object_c.h",
"/home/tochie/Code/townengine/include/twn_context.h",
"/home/tochie/Code/townengine/src/twn_textures.c",
"/home/tochie/Code/townengine/src/game_object/twn_linux_game_object_c.h",
"/home/tochie/Code/townengine/src/twn_input.c",
"/home/tochie/Code/townengine/src/twn_audio.c",
"/home/tochie/Code/townengine/src/rendering/twn_gpu_texture.h",
"/home/tochie/Code/townengine/src/twn_util.c",
"/home/tochie/Code/townengine/src/twn_input_c.h",
"/home/tochie/Code/townengine/src/twn_loop.c",
"/home/tochie/Code/townengine/src/twn_camera.c",
"/home/tochie/Code/townengine/src/twn_context.c",
"/home/tochie/Code/townengine/apps/testgame/scenes/title.h",
"/home/tochie/Code/townengine/apps/testgame/scenes/title.c",
"/home/tochie/Code/townengine/apps/testgame/scenes/ingame.h",
"/home/tochie/Code/townengine/apps/testgame/scenes/ingame.c",
"/home/tochie/Code/townengine/apps/testgame/world.c",
"/home/tochie/Code/townengine/apps/testgame/world.h",
"/home/tochie/Code/townengine/apps/testgame/state.h",
"/home/tochie/Code/townengine/apps/testgame/player.h",
"/home/tochie/Code/townengine/apps/testgame/player.c",
"/home/tochie/Code/townengine/apps/testgame/game.c",
"/home/tochie/Code/townengine/include/twn_rendering.h",
"/home/tochie/Code/townengine/include/twn_option.h",
"/home/tochie/Code/townengine/.gitignore",
"/home/tochie/Code/townengine/include/twn_config.h",
"/home/tochie/Code/townengine/include/twn_input.h",
"/home/tochie/Code/townengine/include/twn_util.h",
"/home/tochie/Code/townengine/include/twn_vec.h",
"/home/tochie/Code/townengine/src/twn_varargcount.h",
"/home/tochie/Code/townengine/docs/source_directory_structure.txt",
"/home/tochie/Code/townengine/src/system/linux/twn_elf.h",
"/home/tochie/Code/townengine/src/twn_context.c",
"/home/tochie/Code/townengine/src/twn_audio_c.h",
"/home/tochie/Code/townengine/src/twn_concatenate_c.h",
"/home/tochie/Code/townengine/src/twn_option_c.h",
"/home/tochie/Code/townengine/include/twn_context.h",
"/home/tochie/Code/townengine/include/twn_camera.h",
"/home/tochie/Code/townengine/include/twn_vec.h",
"/home/tochie/Code/townengine/include/twn_util.h",
"/home/tochie/Code/townengine/src/twn_textures_c.h",
"/home/tochie/Code/townengine/src/twn_util.c",
"/home/tochie/Code/townengine/src/twn_camera.c",
"/home/tochie/Code/townengine/src/twn_texture_modes_c.h",
"/home/tochie/Code/townengine/src/rendering/twn_gl_15_rendering.c",
"/home/tochie/Code/townengine/include/twn_config.h",
"/home/tochie/Code/townengine/include/twn_game_api.h",
"/home/tochie/Code/townengine/src/twn_engine_context.h",
"/home/tochie/Code/townengine/include/readme.txt",
"/home/tochie/Code/townengine/include/twn_audio.h",
"/home/tochie/Code/townengine/src/camera.h",
"/home/tochie/Code/townengine/include/twn_input.h",
"/home/tochie/Code/townengine/townengine/rendering/twn_gl_any_rendering_c.h",
"/home/tochie/Code/townengine/townengine/rendering/twn_rendering_c.h",
"/home/tochie/Code/townengine/townengine/rendering/twn_text.c",
@ -848,9 +797,7 @@
"/home/tochie/Code/townengine/townengine/rendering/twn_triangles_c.h",
"/home/tochie/Code/townengine/townengine/rendering/quad_element_buffer.h",
"/home/tochie/Code/townengine/third-party/glad/include/glad/glad.h",
"/home/tochie/Code/townengine/.gitignore",
"/home/tochie/Code/townengine/townengine/twn_loop.c",
"/home/tochie/Code/townengine/CMakeLists.txt",
"/home/tochie/Code/townengine/apps/testgame/build.sh",
"/home/tochie/Code/townengine/townengine/input/input.c",
"/home/tochie/Code/townengine/townengine/input.h",
@ -861,9 +808,6 @@
"/home/tochie/Code/townengine/third-party/physfs/CMakeLists.txt",
"/home/tochie/Code/townengine/third-party/stb/stb_image.h",
"/home/tochie/Code/townengine/apps/template/game.c",
"/home/tochie/Code/townengine/apps/testgame/game.c",
"/home/tochie/Code/townengine/apps/testgame/scenes/ingame.c",
"/home/tochie/Code/townengine/apps/testgame/scenes/title.c",
"/home/tochie/Code/townengine/townengine/game_object/twn_linux_game_object_c.h",
"/home/tochie/Code/townengine/townengine/game_object/twn_win32_game_object_c.h",
"/home/tochie/Code/townengine/apps/testgame/.build/CMakeFiles/testgame_app.dir/build.make",
@ -872,16 +816,11 @@
"/home/tochie/Code/townengine/townengine/rendering.h",
"/home/tochie/Code/townengine/townengine/game_api.h",
"/home/tochie/Code/townengine/apps/testgame/scenes/scene.c",
"/home/tochie/Code/townengine/apps/testgame/world.c",
"/home/tochie/Code/townengine/apps/testgame/player.h",
"/home/tochie/Code/townengine/townengine/scripting.c",
"/home/tochie/Code/townengine/townengine/camera.c",
"/home/tochie/Code/townengine/townengine/util.c",
"/home/tochie/Code/townengine/townengine/audio/audio.c",
"/home/tochie/Code/townengine/apps/testgame/player.c",
"/home/tochie/Code/townengine/apps/testgame/state.h",
"/home/tochie/Code/townengine/townengine/input/internal_api.h",
"/home/tochie/Code/townengine/apps/testgame/scenes/ingame.h",
"/home/tochie/Code/townengine/third-party/stb/stb_ds.h",
"/home/tochie/Code/townengine/townengine/context/internal_api.h",
"/home/tochie/Code/townengine/apps/testgame/game.h",
@ -892,44 +831,18 @@
"/home/tochie/Code/townengine/third-party/x-watcher.h",
"/home/tochie/Code/townengine/townengine/tabela.c",
"/home/tochie/Code/townengine/townengine/tabela.h",
"/home/tochie/Code/salesman/townengine/game_api.h",
"/home/tochie/Code/salesman/third-party/stb/stb_perlin.h",
"/home/tochie/Code/salesman/apps/testgame/scenes/ingame.c",
"/home/tochie/Code/salesman/townengine/context.c",
"/home/tochie/Code/salesman/townengine/context.h",
"/home/tochie/Code/salesman/apps/template/state.h",
"/home/tochie/Code/salesman/CMakeLists.txt",
"/home/tochie/Code/salesman/apps/testgame/game.c",
"/home/tochie/Code/salesman/townengine/tabela.h",
"/home/tochie/Code/salesman/third-party/stb/stb_truetype.h",
"/home/tochie/Code/salesman/third-party/stb/stb_ds.h",
"/home/tochie/Code/salesman/townengine/camera.h",
"/home/tochie/Code/salesman/townengine/util.h",
"/home/tochie/Code/salesman/townengine/macros/inout.h",
"/home/tochie/Code/salesman/townengine/camera/internal_api.h",
"/home/tochie/Code/salesman/townengine/textures/textures.c",
"/home/tochie/Code/salesman/.build/test.tbl",
"/home/tochie/Code/salesman/townengine/rendering/sprites.h",
"/home/tochie/Code/salesman/townengine/rendering.h",
"/home/tochie/Code/salesman/townengine/macros/option.h",
"/usr/include/SDL2/SDL_surface.h",
"/home/tochie/Code/salesman/townengine/rendering/internal_api.h",
"/home/tochie/Code/salesman/townengine/macros/varargcount.h",
"/home/tochie/Code/salesman/townengine/textures/internal_api.h",
"/usr/include/SDL2/SDL_rect.h",
"/home/tochie/Code/salesman/townengine/vec.h",
"/home/tochie/Code/salesman/townengine/tabela.c",
"/usr/lib/clang/17/include/stddef.h"
"/home/tochie/Code/salesman/townengine/game_api.h"
],
"find":
{
"height": 32.0
"height": 44.0
},
"find_in_files":
{
"height": 194.0,
"where_history":
[
"/home/tochie/Code/townengine/src",
"/home/tochie/Code/townengine/townengine",
"/home/tochie/Code/townengine/",
"/home/tochie/Code/townengine/townengine",
@ -960,6 +873,29 @@
"case_sensitive": false,
"find_history":
[
"GL_RGBA8",
"GL_NEAREST",
"TWN_RENDERING_PLATFORM_H",
"TWN_GL_15_RENDERING_H",
"TWN_GL_ANY_RENDERING_H",
"TWN_GPU_TEXTURE_H",
"use",
"use_sprite_blendmode",
"TWN_TEXTURES_H",
"TWN_TEXTURES_MODES_H",
"TWN_GAME_OBJECT_H",
"TWN_ENGINE_CONTEXT_H",
"RENDERING_INTERNAL_API_H",
"gpu_",
"audio_callback",
"#include \"twn_context.h\"",
"include_deps",
"struct text_cache",
"text_cache",
"townengine/",
"include_deps",
"include",
"engine/",
"ELF_H",
"VARARGCOUNT_H",
"OPTION_H",
@ -1064,30 +1000,7 @@
"copy_if",
"TEXT_FONT_OVERSAMPLING",
"TEXT_FONT_FILTERING",
"linux",
"data",
"btw",
"TOWNENGINE_ARCHIVE_DATA",
"PACKAGE_EXTENSION",
"TOWNENGINE_DIR",
"compile",
"TOWNENGINE_BOOTSTRAP",
"bootstrap",
"set",
"bootstrap",
"_shared",
"_SHA",
"_shared",
"UNIX",
"link_deps",
"${target}",
"bind_quad_element_buffer",
"grass.gif",
"ptr_to_texture",
"textures_get_key",
"GAME_OBJECT_PATH",
"libgame",
"SOURCE_DIR"
"linux"
],
"highlight": true,
"in_selection": false,
@ -1119,161 +1032,6 @@
{
"sheets":
[
{
"buffer": 0,
"file": "include/twn_config.h",
"selected": true,
"semi_transient": false,
"settings":
{
"buffer_size": 972,
"regions":
{
},
"selection":
[
[
972,
972
]
],
"settings":
{
"auto_complete_triggers":
[
{
"characters": "<",
"selector": "text.html, text.xml"
},
{
"rhs_empty": true,
"selector": "punctuation.accessor"
},
{
"characters": ".<>:\"/*",
"selector": "meta.tag, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",
"server": "clangd"
}
],
"lsp_active": true,
"lsp_uri": "file:///home/tochie/Code/townengine/include/twn_config.h",
"show_definitions": false,
"syntax": "Packages/C++/C++.sublime-syntax"
},
"translation.x": 0.0,
"translation.y": 345.0,
"zoom_level": 1.0
},
"stack_index": 0,
"stack_multiselect": false,
"type": "text"
}
]
},
{
"sheets":
[
{
"buffer": 1,
"file": "src/rendering/twn_triangles.c",
"semi_transient": false,
"settings":
{
"buffer_size": 2969,
"regions":
{
},
"selection":
[
[
118,
118
]
],
"settings":
{
"auto_complete_triggers":
[
{
"characters": "<",
"selector": "text.html, text.xml"
},
{
"rhs_empty": true,
"selector": "punctuation.accessor"
},
{
"characters": ".<>:\"/*",
"selector": "meta.tag, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",
"server": "clangd"
}
],
"lsp_active": true,
"lsp_uri": "file:///home/tochie/Code/townengine/src/rendering/twn_triangles.c",
"show_definitions": false,
"syntax": "Packages/C++/C.sublime-syntax",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 1,
"stack_multiselect": false,
"type": "text"
},
{
"buffer": 2,
"file": "include/twn_vec.h",
"selected": true,
"semi_transient": true,
"settings":
{
"buffer_size": 4341,
"regions":
{
},
"selection":
[
[
0,
0
]
],
"settings":
{
"auto_complete_triggers":
[
{
"characters": "<",
"selector": "text.html, text.xml"
},
{
"rhs_empty": true,
"selector": "punctuation.accessor"
},
{
"characters": ".<>:\"/*",
"selector": "meta.tag, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",
"server": "clangd"
}
],
"lsp_active": true,
"lsp_uri": "file:///home/tochie/Code/townengine/include/twn_vec.h",
"show_definitions": false,
"syntax": "Packages/C++/C++.sublime-syntax",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 2952.0,
"zoom_level": 1.0
},
"stack_index": 0,
"stack_multiselect": false,
"type": "text"
}
]
}
],
@ -1294,18 +1052,11 @@
0,
1,
1
],
[
1,
0,
2,
1
]
],
"cols":
[
0.0,
0.37740401568,
1.0
],
"rows":
@ -1593,7 +1344,7 @@
],
"width": 592.0
},
"selected_group": 1,
"selected_group": 0,
"settings":
{
},