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. 8
      src/main.cpp
  3. 12
      src/renderer.cpp
  4. 1
      src/window.cpp

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

@ -105,6 +105,7 @@ std::vector<unsigned int> indices({
// Window for the game // Window for the game
Window win("Euclid Engine: Demo"); Window win("Euclid Engine: Demo");
Renderer::Scene scene(&win);
void framebuffer_size_callback(GLFWwindow* glfwWindow, int w, int h) { void framebuffer_size_callback(GLFWwindow* glfwWindow, int w, int h) {
win.updateSize(w, h); win.updateSize(w, h);
@ -138,12 +139,11 @@ int main() {
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
// Create scene // Create scene
Renderer::Scene scene(&win);
Renderer::TexturedObject ro(verts, indices); Renderer::TexturedObject ro(verts, indices);
Renderer::TexturedObject ro2(verts, indices); Renderer::TexturedObject ro2(verts, indices);
ro.setTexture(RUSTY_METAL_TEXTURE);
ro2.setTexture("assets/textures/meep.jpg"); // TODO: fix texture bug ro2.setTexture("assets/textures/meep.jpg"); // TODO: fix texture bug
ro.setTexture(RUSTY_METAL_TEXTURE);
scene.spawnObject(&ro); scene.spawnObject(&ro);
scene.spawnObject(&ro2); scene.spawnObject(&ro2);
@ -158,7 +158,9 @@ int main() {
processInput(win.win); processInput(win.win);
ro.translate(glm::vec3(0.0f, 0.0f, 0.001f)); 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 // Render new frame
scene.render(); scene.render();

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

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

Loading…
Cancel
Save