diff --git a/.gitignore b/.gitignore index 0cb8563..5943933 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ hexnando hexnando.exe +imgui.ini *.pdb *.ilk diff --git a/imgui.ini b/imgui.ini deleted file mode 100644 index 4ee0af9..0000000 --- a/imgui.ini +++ /dev/null @@ -1,20 +0,0 @@ -[Window][Debug##Default] -Pos=38,60 -Size=400,400 -Collapsed=0 - -[Window][Dear ImGui Demo] -Pos=33,236 -Size=550,680 -Collapsed=0 - -[Window][Hi there] -Pos=138,172 -Size=422,452 -Collapsed=0 - -[Table][0xC9935533,3] -Column 0 Weight=1.0000 -Column 1 Weight=1.0000 -Column 2 Weight=1.0000 - diff --git a/main.cpp b/main.cpp index 33eebd1..5f4e9a2 100644 --- a/main.cpp +++ b/main.cpp @@ -236,7 +236,6 @@ uint32_t make_gl_program(const char *pathname_vertex, const char *pathname_fragm void render_text(const char *text, float x, float y, float scale, glm::vec3 color) { - // TODO: Use triangle strip (4 vertices vs 6) // TODO: Group draw calls together instead of doing 1 draw call/character. Use an atlas with GL_TEXTURE_ARRAY // TODO: Do not make draw calls for invisible characters! @@ -258,14 +257,11 @@ void render_text(const char *text, float x, float y, float scale, glm::vec3 colo float w = charglyph.size.x * scale; float h = charglyph.size.y * scale; // update VBO for each character - float vertices[6][4] = { + float vertices[4][4] = { { xpos, ypos + h, 0.0f, 0.0f }, { xpos, ypos, 0.0f, 1.0f }, { xpos + w, ypos, 1.0f, 1.0f }, - - { xpos, ypos + h, 0.0f, 0.0f }, - { xpos + w, ypos, 1.0f, 1.0f }, - { xpos + w, ypos + h, 1.0f, 0.0f } + { xpos + w, ypos + h, 1.0f, 0.0f } }; // render glyph texture over quad glBindTexture(GL_TEXTURE_2D, charglyph.tex); @@ -274,7 +270,9 @@ void render_text(const char *text, float x, float y, float scale, glm::vec3 colo glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); glBindBuffer(GL_ARRAY_BUFFER, 0); // render quad - glDrawArrays(GL_TRIANGLES, 0, 6); + glEnable(GL_CULL_FACE); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glDisable(GL_CULL_FACE); // now advance cursors for next glyph (note that advance is number of 1/64 pixels) x += (charglyph.advance >> 6) * scale; // bitshift by 6 to get value in pixels (2^6 = 64) } @@ -488,6 +486,7 @@ int main([[maybe_unused]]int argc, [[maybe_unused]]char **argv) camera_t the_camera; bool mouse_pressed; bool mouse_over_gui; + static bool show_hex_numbers = true; static selection_t selection; selection.indices = (int32_t*)calloc(1, sizeof(int32_t) * grid.rows * grid.columns); selection.nselected = 0; @@ -640,8 +639,8 @@ int main([[maybe_unused]]int argc, [[maybe_unused]]char **argv) TIME_BLOCK(text_render); stbsp_snprintf(debug_text_buf, 256, "Cursor position %.0f %.0f screen %.2f %.2f world", cursor_x, cursor_y, cursor_world.x, cursor_world.y); render_text(debug_text_buf, 25, 25, .5f, glm::vec3(1.0f, 1.0f, 1.0f)); - - for (int i = 0; i < grid.rows * grid.columns; ++i) + + for (int i = 0; show_hex_numbers && i < grid.rows * grid.columns; ++i) { // Get position of hexes in screen glm::vec4 v = glm::vec4(grid.hexes[i].position.x, grid.hexes[i].position.y, grid.hexes[i].position.z, 1.0); @@ -650,6 +649,9 @@ int main([[maybe_unused]]int argc, [[maybe_unused]]char **argv) v.x *= window_width/2.0f; v.y += 1; v.y *= window_height/2.0f; + // Do not draw text outside visible window + if (v.x > window_width || v.x < 0 || v.y > window_height || v.y < 0) + continue; char number_string[11]; stbsp_snprintf(number_string, 11, "%d", i); render_text(number_string, v.x, v.y, .2f + (0.3f / the_camera.size.x), glm::vec3(0.0f, 0.0f, 0.0f)); @@ -667,7 +669,7 @@ int main([[maybe_unused]]int argc, [[maybe_unused]]char **argv) static int grid_rows = grid.rows; static int grid_columns = grid.columns; - + if (grid_rows != grid.rows || grid_columns != grid.columns) { create_grid(&grid, grid_rows, grid_columns); @@ -682,6 +684,7 @@ int main([[maybe_unused]]int argc, [[maybe_unused]]char **argv) ImGui::Begin("Hi there"); ImGui::SliderInt("Rows", &grid_rows, 1, 100); ImGui::SliderInt("Columns", &grid_columns, 1, 100); + ImGui::Checkbox("Show hex numbers", &show_hex_numbers); if (ImGui::CollapsingHeader("Debug timers")) { for (int i = 0; i < ntimers; ++i)