|
|
@ -7,17 +7,11 @@ |
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
#include <math.h> |
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "../headers/renderer.hpp" |
|
|
|
#include "renderer.hpp" |
|
|
|
#include "glm/trigonometric.hpp" |
|
|
|
|
|
|
|
// #include "../headers/shaders.hpp"
|
|
|
|
|
|
|
|
// #include "../headers/textures.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define WINDOW_WIDTH 640 |
|
|
|
#define WINDOW_WIDTH 640 |
|
|
|
#define WINDOW_HEIGHT 480 |
|
|
|
#define WINDOW_HEIGHT 480 |
|
|
|
|
|
|
|
|
|
|
|
#define VERT_SHADER_SRC_FILE "shaders/vertex.glsl" |
|
|
|
|
|
|
|
#define FRAG_SHADER_SRC_FILE "shaders/fragment.glsl" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define RUSTY_METAL_TEXTURE "assets/textures/rusty_metal.jpg" |
|
|
|
#define RUSTY_METAL_TEXTURE "assets/textures/rusty_metal.jpg" |
|
|
|
|
|
|
|
|
|
|
|
void framebuffer_size_callback(GLFWwindow* win, int w, int h) { |
|
|
|
void framebuffer_size_callback(GLFWwindow* win, int w, int h) { |
|
|
@ -33,8 +27,10 @@ void processInput(GLFWwindow *win) { |
|
|
|
|
|
|
|
|
|
|
|
void renderCallback() { |
|
|
|
void renderCallback() { |
|
|
|
// Make background
|
|
|
|
// Make background
|
|
|
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); |
|
|
|
// glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
// glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
int main() { |
|
|
@ -49,8 +45,6 @@ int main() { |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Renderer::Renderer3D renderer(win); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(win); |
|
|
|
glfwMakeContextCurrent(win); |
|
|
|
|
|
|
|
|
|
|
|
if ( !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) ) { |
|
|
|
if ( !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) ) { |
|
|
@ -59,30 +53,116 @@ int main() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::vector<float> verts({ |
|
|
|
std::vector<float> verts({ |
|
|
|
0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
|
|
|
|
-0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, |
|
|
|
0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, |
|
|
|
0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, |
|
|
|
-0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, |
|
|
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, |
|
|
|
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f |
|
|
|
|
|
|
|
|
|
|
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, |
|
|
|
|
|
|
|
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, |
|
|
|
|
|
|
|
-0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, |
|
|
|
|
|
|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f, 1.0f, 0.0f, 0.0f, |
|
|
|
|
|
|
|
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f |
|
|
|
}); |
|
|
|
}); |
|
|
|
// Vert struc: x y z r g b tx ty
|
|
|
|
// Vert struc: x y z r g b tx ty
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<unsigned int> indices({
|
|
|
|
std::vector<unsigned int> indices({
|
|
|
|
0, 1, 3,
|
|
|
|
0, 1, 3,
|
|
|
|
1, 2, 3
|
|
|
|
1, 2, 3, |
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
11, 12, 13, |
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
11, 12, 13, |
|
|
|
|
|
|
|
0, 1, 3,
|
|
|
|
|
|
|
|
3, 4, 5,
|
|
|
|
|
|
|
|
5, 6, 7,
|
|
|
|
|
|
|
|
7, 8, 9,
|
|
|
|
|
|
|
|
9, 10, 11,
|
|
|
|
|
|
|
|
11, 12, 13, |
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); |
|
|
|
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); |
|
|
|
glfwSetFramebufferSizeCallback(win, framebuffer_size_callback); |
|
|
|
glfwSetFramebufferSizeCallback(win, framebuffer_size_callback); |
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
|
|
|
|
float borderColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
|
|
|
float borderColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
|
|
|
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); |
|
|
|
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); |
|
|
|
|
|
|
|
|
|
|
|
Renderer::Obj2D ro(verts, indices); |
|
|
|
// Create scene
|
|
|
|
renderer.spawnObject(ro); |
|
|
|
Renderer::Scene scene(win); |
|
|
|
renderer.setCamera(glm::vec3(0.0f, 0.0f, -8.0f)); |
|
|
|
|
|
|
|
|
|
|
|
Renderer::TexturedObject ro(verts, indices); |
|
|
|
|
|
|
|
ro.setPosition(glm::vec3(0.2f, -1.0f, -8.0f)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Renderer::TexturedObject ro2(verts, indices); |
|
|
|
|
|
|
|
ro2.setPosition(glm::vec3(0.5f, 0.0, -8.0f)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ro2.setTexture("assets/textures/meep.jpg"); |
|
|
|
ro.setTexture(RUSTY_METAL_TEXTURE); |
|
|
|
ro.setTexture(RUSTY_METAL_TEXTURE); |
|
|
|
|
|
|
|
|
|
|
|
// Window width & height
|
|
|
|
scene.spawnObject(&ro); |
|
|
|
|
|
|
|
scene.spawnObject(&ro2); |
|
|
|
|
|
|
|
|
|
|
|
while (!glfwWindowShouldClose(win)) { |
|
|
|
while (!glfwWindowShouldClose(win)) { |
|
|
|
// Handle input
|
|
|
|
// Handle input
|
|
|
|
processInput(win); |
|
|
|
processInput(win); |
|
|
@ -90,20 +170,19 @@ int main() { |
|
|
|
// rendering
|
|
|
|
// rendering
|
|
|
|
renderCallback(); |
|
|
|
renderCallback(); |
|
|
|
|
|
|
|
|
|
|
|
/* OBJECT RENDERING */ |
|
|
|
|
|
|
|
float time = glfwGetTime(); |
|
|
|
float time = glfwGetTime(); |
|
|
|
float gVal = sin(time) / 10.5f; |
|
|
|
float gVal = sin(time); |
|
|
|
renderer.setCamera(glm::vec3(0.0f, 0.0f, -gVal)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Transformation
|
|
|
|
// Move the camera left and right
|
|
|
|
float rotang = time; |
|
|
|
scene.camera.setRotation(glm::vec3(0.0f, 5.0f, 0.0f)); |
|
|
|
|
|
|
|
scene.camera.translate(glm::vec3(0.0f, 0.0f, 0.02f + gVal/100.0f)); |
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 T = glm::mat4(1.0f); |
|
|
|
// Move the objects & stuff
|
|
|
|
T = glm::rotate(T, rotang, glm::vec3(1.0, 0.0, 1.0)); |
|
|
|
float rotang = time; |
|
|
|
T = glm::scale(T, glm::vec3(0.5, 0.5, 0.5)); |
|
|
|
ro.translate(glm::vec3(0.0f, 0.0f, -0.021f)); |
|
|
|
ro.transform(T); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderer.render(); |
|
|
|
// Render new frame
|
|
|
|
|
|
|
|
scene.render(); |
|
|
|
|
|
|
|
|
|
|
|
// glfw
|
|
|
|
// glfw
|
|
|
|
glfwSwapBuffers(win); |
|
|
|
glfwSwapBuffers(win); |
|
|
|