This commit is contained in:
2025-01-05 12:51:17 +00:00
parent 2daee71548
commit 595259b2cc
10 changed files with 106 additions and 105 deletions

View File

@@ -1,11 +1,11 @@
#include <iostream>
#include <vector>
#include <optional>
#include "lib/djstdlib/core.h"
#include "lib/glad/glad.c"
#include "lib/djstdlib/core.h"
#include <GLFW/glfw3.h>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/ext/matrix_transform.hpp>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
@@ -23,10 +23,10 @@
struct Entity;
struct Polycube;
struct SceneGraphNode;
int new_entity();
uint32 new_entity();
Entity *get_entity(int id);
SceneGraphNode *get_scene_graph_node(int id);
int new_graph_node();
uint32 new_graph_node();
void print_mat(glm::mat4* matrix) {
glm::mat4 mat = *matrix;
@@ -70,7 +70,7 @@ struct GlobalAppState {
std::vector<Polycube> polycubes;
};
GlobalAppState app_state;
GlobalAppState app_state = {};
struct WindowDims {
uint32 width;
@@ -91,7 +91,7 @@ struct SceneGraphNode {
glm::quat rotation;
glm::vec3 scale;
std::vector<uint32> children;
std::optional<uint32> entity;
uint32 entity;
};
void init_sg_node(SceneGraphNode *n) {
@@ -120,9 +120,9 @@ struct Polycube {
void show_polycube(Polycube *p) {
SceneGraphNode *node = get_scene_graph_node(p->graph_node);
for (uint32 &child : node->children) {
SceneGraphNode *node = get_scene_graph_node(child);
if (node->entity) {
get_entity(*node->entity)->visible = true;
SceneGraphNode *subNode = get_scene_graph_node(child);
if (subNode->entity) {
get_entity(subNode->entity)->visible = true;
}
}
}
@@ -130,9 +130,9 @@ void show_polycube(Polycube *p) {
void hide_polycube(Polycube *p) {
SceneGraphNode *node = get_scene_graph_node(p->graph_node);
for (uint32 &child : node->children) {
SceneGraphNode *node = get_scene_graph_node(child);
if (node->entity) {
get_entity(*node->entity)->visible = false;
SceneGraphNode *subNode = get_scene_graph_node(child);
if (subNode->entity) {
get_entity(subNode->entity)->visible = false;
}
}
}
@@ -154,7 +154,7 @@ struct Frame {
Camera* cam;
};
Frame createFrame(Arena *arena, uint32 width, uint32 height, real32 x, real32 y) {
Frame createFrame(Arena *arena, uint32 width, uint32 height, uint32 x, uint32 y) {
Frame result = {0};
result.width = width;
result.height = height;
@@ -231,12 +231,12 @@ void process_input(GLFWwindow *window) {
}
int new_entity() {
uint32 new_entity() {
entities.emplace_back();
scene_graph_nodes.emplace_back();
entities.back().scene_graph_node = scene_graph_nodes.size();
scene_graph_nodes.back().entity = entities.size();
return entities.size();
entities.back().scene_graph_node = (uint32)scene_graph_nodes.size();
scene_graph_nodes.back().entity = (uint32)entities.size();
return (uint32)entities.size();
}
Entity *get_entity(int id) {
@@ -247,13 +247,13 @@ SceneGraphNode *get_scene_graph_node(int id) {
return &scene_graph_nodes[id - 1];
}
int new_graph_node() {
uint32 new_graph_node() {
scene_graph_nodes.emplace_back();
return scene_graph_nodes.size();
return (uint32)scene_graph_nodes.size();
}
Polycube create_polycube_from_repr(Space *repr) {
int polycube_id = new_graph_node();
uint32 polycube_id = new_graph_node();
init_sg_node(get_scene_graph_node(polycube_id));
for (int x = 0; x < repr->dim_x; x++) {
for (int y = 0; y < repr->dim_y; y++) {
@@ -275,10 +275,9 @@ Polycube create_polycube_from_repr(Space *repr) {
}
}
}
Polycube result = {
.graph_node=polycube_id,
.color=glm::vec3(1.0f),
};
Polycube result = {};
result.graph_node = polycube_id;
result.color = glm::vec3(1.0f);
return result;
}
@@ -308,12 +307,10 @@ int main_gfx() {
Arena *arena = arenaAlloc(Megabytes(128));
app_state = {
.current_polycube=0,
.last_polycube_visible=6,
.active_shader=0,
.polycubes={},
};
app_state.current_polycube=0;
app_state.last_polycube_visible=6;
app_state.active_shader=0;
app_state.polycubes={};
Shader phong_shader = createShader("../assets/shaders/phong-solid.vertex.glsl", "../assets/shaders/phong-solid.fragment.glsl");
app_state.active_shader = &phong_shader;
@@ -353,8 +350,8 @@ int main_gfx() {
glGetUniformLocation(app_state.active_shader->prog_id, "view"),
1, GL_FALSE, glm::value_ptr(big_frame.cam->view));
real32 last_frame = glfwGetTime();
real32 time_delta = 1.0f/60.0f;
real64 last_frame = glfwGetTime();
real64 time_delta = 1.0f/60.0f;
while (!glfwWindowShouldClose(window)) {
time_delta = glfwGetTime() - last_frame;
process_input(window);
@@ -383,7 +380,7 @@ int main_gfx() {
if (entity.visible) {
glUniformMatrix4fv(model_uniform_loc, 1, GL_FALSE, glm::value_ptr(get_scene_graph_node(entity.scene_graph_node)->world));
glBindTexture(GL_TEXTURE_2D, entity.tex->tex_id);
glDrawArrays(GL_TRIANGLES, 0, entity.mesh->num_indices);
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)entity.mesh->num_indices);
//glDrawElements(GL_TRIANGLES, entity->mesh->num_indices, GL_UNSIGNED_INT, 0);
}
}
@@ -398,6 +395,6 @@ int main_gfx() {
int main() {
initialiseCore();
return main_cmd();
return main_gfx();
}