Skip to content

Commit

Permalink
imgui stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed May 26, 2024
1 parent 444828a commit 402a65e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion engine/include/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Group {

void rotate(float angle, float x, float y, float z);

void drawGroup(bool lights, const Frustsum& frustsum, bool normals, float elapsed_time);
void drawGroup(bool lights, const Frustsum& frustsum, bool normals, float elapsed_time, int& nr_models);

};

Expand Down
5 changes: 3 additions & 2 deletions engine/src/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ glm::mat4 applyTransformations(std::vector<Transformations> order,
return matrix;
}

void Group::drawGroup(bool lights, const Frustsum& frustsum, bool normals, float speed_factor) {
void Group::drawGroup(bool lights, const Frustsum& frustsum, bool normals, float speed_factor, int& nr_models) {
glPushMatrix();

glm::mat4 matrix = applyTransformations(this->order, this->static_transformations, this->rotations, this->translates, speed_factor);
Expand All @@ -69,13 +69,14 @@ void Group::drawGroup(bool lights, const Frustsum& frustsum, bool normals, float
}

if(model.bounding_sphere.isInsideFrustsum(frustsum, matrix)) {
nr_models++;
model.drawModel();
if(normals) model.drawNormals();
}
}

for (Group& sub : this->subgroups) {
sub.drawGroup(lights, frustsum, normals, speed_factor);
sub.drawGroup(lights, frustsum, normals, speed_factor, nr_models);
}

glPopMatrix();
Expand Down
39 changes: 34 additions & 5 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern "C" {
#define _USE_MATH_DEFINES
#include <math.h>
#include <chrono>
#include <unordered_map>

#include "Configuration.hpp"
#include "curves.hpp"
Expand All @@ -29,13 +30,25 @@ bool normals = false;
bool culling = false;
bool lighting = false;
float speed_factor = 1.0f;
bool models_menus = false;

int total_models = 0;
int nr_models = 0;

int timebase;
float frames;

Configuration c;
Camera camera;

struct ModelInfo {
int vertex_number;
int triangle_number;
};

std::unordered_map<std::string, ModelInfo> models_info;


void reshape(int w, int h) {
float aspect_ratio = (float)w / (float)h;

Expand Down Expand Up @@ -99,7 +112,11 @@ void setupConfig(char* arg) {

void setupModels(Group& group) {
for (Model& model : group.models) {
total_models++;
model.initModel();

ModelInfo info = {model.vbo.size(), model.ibo.size() / 3};
models_info[model.filename] = info;
}
for (Group& g : group.subgroups) {
setupModels(g);
Expand Down Expand Up @@ -127,12 +144,13 @@ void renderMenu() {
ImGui::Begin("Infos", NULL, ImGuiWindowFlags_AlwaysAutoResize);

ImGui::Text("FPS: %.1f (%.3f ms/frame)", io.Framerate, 1000.f / io.Framerate);
ImGui::Text("Camera Position: (%f, %f, %f)", camera.position.x, camera.position.y, camera.position.z);
ImGui::Text("Camera LookAt: (%f, %f, %f)", camera.lookAt.x, camera.lookAt.y, camera.lookAt.z);
ImGui::Text("Fov: %d Ratio: %.1f Near: %f Far: %f", c.camera.fov, static_cast<float>(glutGet(GLUT_WINDOW_WIDTH) / glutGet(GLUT_WINDOW_HEIGHT)), c.camera.near, c.camera.far);
ImGui::Text("Camera Position: (%.3f, %.3f, %.3f)", camera.position.x, camera.position.y, camera.position.z);
ImGui::Text("Fov: %d Ratio: %.1f Near: %.3f Far: %.3f", c.camera.fov, static_cast<float>(glutGet(GLUT_WINDOW_WIDTH) / glutGet(GLUT_WINDOW_HEIGHT)), c.camera.near, c.camera.far);
ImGui::Text("XML File: %s", filename.c_str());

ImGui::Text("Models: %d (Total %d)", nr_models, total_models);
ImGui::Checkbox("Models Info", &models_menus);
ImGui::End();

}
{
ImGui::Begin("Options", NULL, ImGuiWindowFlags_AlwaysAutoResize);
Expand All @@ -159,6 +177,16 @@ void renderMenu() {
}
ImGui::End();
}
if(models_menus){
ImGui::Begin("Models", NULL, ImGuiWindowFlags_AlwaysAutoResize);
for (auto& model : models_info) {
ImGui::Text("Model: %s", model.first.c_str());
ImGui::Text("Vertices: %d Triangles: %d", model.second.vertex_number, model.second.triangle_number);
//separator here
ImGui::Separator();
}
ImGui::End();
}
ImGui::Render();
glViewport(0, 0, (GLsizei) io.DisplaySize.x, (GLsizei) io.DisplaySize.y);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
Expand Down Expand Up @@ -209,7 +237,8 @@ void renderScene(void) {
drawLights(c.lights);
}

c.group.drawGroup(lighting, frustsum, normals, speed_factor);
nr_models = 0;
c.group.drawGroup(lighting, frustsum, normals, speed_factor, nr_models);

// Start the Dear ImGui frame
renderMenu();
Expand Down
9 changes: 7 additions & 2 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ Collapsed=0

[Window][Infos]
Pos=15,18
Size=304,116
Size=325,139
Collapsed=0

[Window][Options]
Pos=14,141
Pos=15,169
Size=312,124
Collapsed=0

[Window][Models]
Pos=770,16
Size=297,183
Collapsed=1

0 comments on commit 402a65e

Please sign in to comment.