Merge branch 'window_wrapper' of github.com:E-Almqvist/Euclid into window_wrapper

pull/6/head
E. Almqvist 2 years ago
commit deeb54913f
  1. 10
      headers/renderer.hpp
  2. 60
      src/main.cpp
  3. 12
      src/renderer.cpp
  4. 1
      src/window.cpp

@ -49,20 +49,22 @@ namespace Renderer {
class Camera : public Object {
public:
glm::mat4 projection = glm::mat4(1.0f);
glm::mat4 view = glm::mat4(1.0f);
float FOV;
Camera(Window* win);
Camera(Window* win, glm::vec3 pos);
Camera(Window* win, glm::vec3 pos, glm::vec3 angle);
void setFOV(float deg);
glm::mat4 getProjection();
protected:
Window* window;
glm::vec3 front = glm::vec3(0.0f, 0.0f, 1.0f);
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
void updateCameraTransforms();
private:
glm::mat4 projection = glm::mat4(1.0f);
};
@ -82,7 +84,7 @@ namespace Renderer {
class Scene {
public:
float deltaTime = 0.0f;
float deltaTime = 0.0f; // Seconds
Scene(Window* win);
Scene(Window* win, std::vector<RenderObject*> ROs);
@ -90,7 +92,7 @@ namespace Renderer {
void setCamera(Camera *cam);
void spawnObject(RenderObject *ro);
void render();
protected:
// protected:
Camera *camera;
private:
std::vector<RenderObject*> renderObjects = std::vector<RenderObject*>();

@ -69,42 +69,43 @@ std::vector<float> verts({
});
// Vert struc: x y z r g b tx ty
std::vector<unsigned int> indices({
0, 1, 3,
std::vector<unsigned int> indices({
0, 1, 3,
1, 2, 3,
5, 6, 7,
7, 8, 9,
9, 10, 11,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
});
// Window for the game
Window win("Euclid Engine: Demo");
Renderer::Scene scene(&win);
void framebuffer_size_callback(GLFWwindow* glfwWindow, int w, int h) {
win.updateSize(w, h);
@ -129,7 +130,7 @@ int main() {
glViewport(0, 0, win.width(), win.height());
glfwSetFramebufferSizeCallback(win.win, framebuffer_size_callback); // Framebuffer
glEnable(GL_DEPTH_TEST);
glEnable(GL_DEPTH_TEST);
// Input
glfwSetInputMode(win.win, GLFW_CURSOR, GLFW_CURSOR_DISABLED); // Disable cursor
@ -138,12 +139,11 @@ int main() {
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
// Create scene
Renderer::Scene scene(&win);
Renderer::TexturedObject ro(verts, indices);
Renderer::TexturedObject ro2(verts, indices);
ro.setTexture(RUSTY_METAL_TEXTURE);
ro2.setTexture("assets/textures/meep.jpg"); // TODO: fix texture bug
ro.setTexture(RUSTY_METAL_TEXTURE);
scene.spawnObject(&ro);
scene.spawnObject(&ro2);
@ -158,7 +158,9 @@ int main() {
processInput(win.win);
ro.translate(glm::vec3(0.0f, 0.0f, 0.001f));
// ro2.setPosition(glm::vec3(0.0f, 0.0f, -1000.0f));
// ro2.translate(glm::vec3(0.0f, -0.01f, 0.01f));
ro2.translate(glm::vec3(0.0f, 0.0f, -0.001f));
ro2.rotate(glm::vec3(1.01f, 1.0f, 1.0f));
// Render new frame
scene.render();

@ -2,6 +2,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <iostream>
#include <stdio.h>
#include "GLFW/glfw3.h"
#include "glm/ext/matrix_transform.hpp"
@ -92,6 +93,8 @@ namespace Renderer {
float curFrame = glfwGetTime();
deltaTime = curFrame - lastFrame;
printf("\rdeltaTime=%f FPS=%f", deltaTime, 1/(deltaTime+0.0001f));
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -105,7 +108,7 @@ namespace Renderer {
// Camera
Camera::Camera(Window* win) {
window = win;
setFOV(DEFAULT_FOV);
FOV = DEFAULT_FOV;
}
Camera::Camera(Window* win, glm::vec3 pos) : Camera(win) {
@ -116,8 +119,9 @@ namespace Renderer {
setRotation(angle);
}
void Camera::setFOV(float fov) {
projection = glm::perspective(glm::radians(fov), (float)window->width() / (float)window->height(), NEAR_PLANE, FAR_PLANE);
glm::mat4 Camera::getProjection() {
projection = glm::perspective(glm::radians(FOV), (float)window->width() / (float)window->height(), NEAR_PLANE, FAR_PLANE);
return projection;
}
void Camera::updateCameraTransforms() {
@ -173,7 +177,7 @@ namespace Renderer {
shader.setMat4("model", modelTransform);
shader.setMat4("view", cam.view);
shader.setMat4("projection", cam.projection);
shader.setMat4("projection", cam.getProjection());
shader.use();

@ -34,5 +34,4 @@ void Window::updateSize(int w, int h) {
_width = w;
_height = h;
glViewport(0, 0, w, h);
printf("New size: %i %i\n", w, h);
}

Loading…
Cancel
Save