It would be so awesome... it would be so cool!
This commit is contained in:
parent
aaaa195167
commit
6b9bea7964
33
src/main.cpp
33
src/main.cpp
|
@ -1,16 +1,20 @@
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <glm/ext/vector_float3.hpp>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "rendering/part.h"
|
||||||
#include "rendering/renderer.h"
|
#include "rendering/renderer.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
|
||||||
void errorCatcher(int id, const char* str);
|
void errorCatcher(int id, const char* str);
|
||||||
|
|
||||||
Camera camera(glm::vec3(0.0, 0.0, 3.0));
|
Camera camera(glm::vec3(0.0, 0.0, 3.0));
|
||||||
|
std::vector<Part> parts;
|
||||||
|
|
||||||
// void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
void processInput(GLFWwindow* window);
|
void processInput(GLFWwindow* window);
|
||||||
void mouseCallback(GLFWwindow* window, double xpos, double ypos);
|
void mouseCallback(GLFWwindow* window, double xpos, double ypos);
|
||||||
// void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
// void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
|
@ -21,12 +25,24 @@ int main() {
|
||||||
|
|
||||||
glfwInit();
|
glfwInit();
|
||||||
GLFWwindow *window = glfwCreateWindow(1200, 900, "GLTest", NULL, NULL);
|
GLFWwindow *window = glfwCreateWindow(1200, 900, "GLTest", NULL, NULL);
|
||||||
|
glfwSetKeyCallback(window, keyCallback);
|
||||||
glfwSetMouseButtonCallback(window, mouseButtonCallback);
|
glfwSetMouseButtonCallback(window, mouseButtonCallback);
|
||||||
glfwSetCursorPosCallback(window, mouseCallback);
|
glfwSetCursorPosCallback(window, mouseCallback);
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glewInit();
|
glewInit();
|
||||||
|
|
||||||
|
parts.push_back(Part {
|
||||||
|
.position = glm::vec3(0),
|
||||||
|
.rotation = glm::vec3(0),
|
||||||
|
.scale = glm::vec3(1, 1, 1),
|
||||||
|
.material = Material {
|
||||||
|
.diffuse = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||||
|
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||||
|
.shininess = 32.0f,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
renderInit(window);
|
renderInit(window);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -87,3 +103,18 @@ void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods) {
|
||||||
mouseFirst = true;
|
mouseFirst = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||||
|
if (key == GLFW_KEY_F && action == GLFW_PRESS) {
|
||||||
|
parts.push_back(Part {
|
||||||
|
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
|
||||||
|
.rotation = glm::vec3(0),
|
||||||
|
.scale = glm::vec3(1, 1, 1),
|
||||||
|
.material = Material {
|
||||||
|
.diffuse = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||||
|
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||||
|
.shininess = 32.0f,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
10
src/rendering/part.h
Normal file
10
src/rendering/part.h
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include "material.h"
|
||||||
|
|
||||||
|
struct Part {
|
||||||
|
glm::vec3 position;
|
||||||
|
glm::vec3 rotation;
|
||||||
|
glm::vec3 scale;
|
||||||
|
Material material;
|
||||||
|
};
|
|
@ -2,17 +2,21 @@
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
#include "defaultmeshes.h"
|
#include "defaultmeshes.h"
|
||||||
#include "../camera.h"
|
#include "../camera.h"
|
||||||
|
#include "part.h"
|
||||||
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
Shader *shader = NULL;
|
Shader *shader = NULL;
|
||||||
extern Camera camera;
|
extern Camera camera;
|
||||||
|
extern std::vector<Part> parts;
|
||||||
|
|
||||||
void renderInit(GLFWwindow* window) {
|
void renderInit(GLFWwindow* window) {
|
||||||
glViewport(0, 0, 1200, 900);
|
glViewport(0, 0, 1200, 900);
|
||||||
|
@ -67,14 +71,16 @@ void render(GLFWwindow* window) {
|
||||||
// Pass in the camera position
|
// Pass in the camera position
|
||||||
shader->set("viewPos", camera.cameraPos);
|
shader->set("viewPos", camera.cameraPos);
|
||||||
|
|
||||||
glm::mat4 model = glm::mat4(1.0f);
|
for (Part part : parts) {
|
||||||
model = glm::translate(model, glm::vec3( 0.0f, 0.0f, 0.0f));
|
glm::mat4 model = glm::mat4(1.0f);
|
||||||
// float angle = 20.0f * i;
|
model = glm::translate(model, part.position);
|
||||||
// model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
|
// model = glm::rotate(model, part.position);
|
||||||
shader->set("model", model);
|
model = glm::scale(model, part.scale);
|
||||||
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
shader->set("model", model);
|
||||||
shader->set("normalMatrix", normalMatrix);
|
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
||||||
|
shader->set("normalMatrix", normalMatrix);
|
||||||
|
|
||||||
CUBE_MESH->bind();
|
CUBE_MESH->bind();
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue