Skip to content

Commit

Permalink
Add new scene and tidy up main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
ConniBug committed Mar 5, 2024
1 parent a7db0a1 commit c9277d4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
32 changes: 32 additions & 0 deletions Scenes/star_viewer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by Conni Bilham on 16/10/2023.
//

#include "star_viewer.h"
#include "logging.h"

void star_viewer::Init(Camera *camera) {
this->camera = camera;
camera->type = CAMERA_TYPE::PERSPECTIVE;

shaders.emplace_back(new Shader("shaders/vertex.glsl", "shaders/fragment.glsl"));
auto entity = new Entity_t(shaders[0],
glm::vec3(0, 0, 0),
glm::vec3(0.0f),
glm::vec3(0.5f));

entity_list.push_back(entity);
}

void star_viewer::Update(double deltaTime) {
glm::mat4 view = glm::mat4(1.0f);
glm::mat4 projection = camera->getProjectionMatrix(storage->window.width, storage->window.height);
view *= camera->view_matrix();

for (auto &entity: entity_list) {
{
entity->shader->apply(view, projection);
entity->draw();
}
}
}
16 changes: 16 additions & 0 deletions Scenes/star_viewer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by Conni Bilham on 16/10/2023.
//

#ifndef INC_2D_ENGINE_STAR_VIEWER_H
#define INC_2D_ENGINE_STAR_VIEWER_H

#include "Scene.h"

class star_viewer : public Scene {
public:
void Init(Camera *camera) override;
void Update(double deltaTime) override;
};

#endif//INC_2D_ENGINE_STAR_VIEWER_H
17 changes: 10 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
// Created by Conni Bilham on 10/07/2023.
//

#include <iostream>
#include "Storage.h"
#include "external/glad/include/glad/glad.h"
#include "external/glfw/include/GLFW/glfw3.h"
#include "Storage.h"
#include <iostream>

#include "include/Window.h"

#include "Scenes/main_scene.h"
#include "Scenes/orth_scene.h"
#include "Scenes/star_viewer.h"

Storage* storage;
#include "include/Vector.h"

Storage *storage;

#define T_STR(v) std::to_string(storage->version.v)
#define BUILD_STRING T_STR(major) + "." + T_STR(minor) + "." + T_STR(patch) + " Build " + T_STR(build)
Expand All @@ -26,12 +29,12 @@ int main() {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // For Mac OS X

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);// For Mac OS X

storage->window.title = "";
storage->scene_list.emplace_back(new orth_scene());
storage->window.title = "Engine " + BUILD_STRING;
storage->scene_list.emplace_back(new main_scene());
storage->scene_list.emplace_back(new star_viewer());
storage->scene_list.emplace_back(new orth_scene());

auto camera = new Camera(glm::vec3(0.0f, 0.0f, 3.0f));
storage->window.width = 800;
Expand Down

0 comments on commit c9277d4

Please sign in to comment.