This commit is contained in:
Kamil_DLC 2021-02-16 19:29:52 +01:00
commit 56df882fab

View File

@ -1,13 +1,13 @@
#include <glad/glad.h> #include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
//#include <stb_image.h> #include <stb_image.h>
#define STB_IMAGE_IMPLEMENTATION // dodane do pliku z kursu #define STB_IMAGE_IMPLEMENTATION // dodane do pliku z kursu
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
#include <learnopengl/filesystem.h> #include <learnopengl/filesystem.h>
#include <learnopengl/shader.h> #include <learnopengl/shader_m.h>
#include <learnopengl/camera.h> #include <learnopengl/camera.h>
#include <learnopengl/model.h> #include <learnopengl/model.h>
@ -34,6 +34,11 @@ bool firstMouse = true;
float deltaTime = 0.0f; float deltaTime = 0.0f;
float lastFrame = 0.0f; float lastFrame = 0.0f;
//
float angle = 0;
int main() int main()
{ {
// glfw: initialize and configure // glfw: initialize and configure
@ -76,14 +81,6 @@ int main()
// ----------------------------- // -----------------------------
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
// build and compile shaders
// -------------------------
Shader nanosuitShader("9.2.geometry_shader.vert", "9.2.geometry_shader.frag");
//Model nanosuitModel("../resources/objects/nanosuit/nanosuit.obj");
Model nanosuitModel("../resources/objects/kniede/kniede.obj");
// build and compile shaders // build and compile shaders
// ------------------------- // -------------------------
Shader shader("6.2.cubemaps.vert", "6.2.cubemaps.frag"); Shader shader("6.2.cubemaps.vert", "6.2.cubemaps.frag");
@ -203,16 +200,16 @@ int main()
// load textures // load textures
// ------------- // -------------
string dir = "mountain-skyboxes/Ryfjallet"; string dir = "../resources/textures/SaintsPetersBasilica/";
vector<string> faces vector<std::string> faces
{ {
"../resources/textures/skybox/" + dir + "/posx.jpg", dir + "posx.jpg",
"../resources/textures/skybox/" + dir + "/negx.jpg", dir + "negx.jpg",
"../resources/textures/skybox/" + dir + "/posy.jpg", dir + "posy.jpg",
"../resources/textures/skybox/" + dir + "/negy.jpg", dir + "negy.jpg",
"../resources/textures/skybox/" + dir + "/posz.jpg", dir + "posz.jpg",
"../resources/textures/skybox/" + dir + "/negz.jpg", dir + "negz.jpg"
}; };
unsigned int cubemapTexture = loadCubemap(faces); unsigned int cubemapTexture = loadCubemap(faces);
@ -234,6 +231,7 @@ int main()
float currentFrame = glfwGetTime(); float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame; deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame; lastFrame = currentFrame;
angle += deltaTime;
// input // input
// ----- // -----
@ -245,33 +243,30 @@ int main()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw scene as normal // draw scene as normal
shader.use();
glm::mat4 model = glm::mat4(1.0f);
model = glm::rotate(model, angle/10.f, glm::vec3(0, 1, 0));
glm::mat4 view = camera.GetViewMatrix(); glm::mat4 view = camera.GetViewMatrix();
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f); glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
glm::mat4 model = glm::mat4(1.0f);
// model = glm::translate(model, glm::vec3(0.0f, 0.0f, 0.0f)); // translate it down so it's at the center of the scene
// model = glm::scale(model, glm::vec3(1.0f, 1.0f, 1.0f)); // it's a bit too big for our scene, so scale it down
model = glm::rotate(model, glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
nanosuitShader.use();
nanosuitShader.setMat4("projection", projection);
nanosuitShader.setMat4("view", view);
nanosuitShader.setMat4("model", model);
nanosuitModel.Draw(nanosuitShader);
// draw scene as normal
shader.use();
model = glm::mat4(1.0f);
view = camera.GetViewMatrix();
projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
shader.setMat4("model", model); shader.setMat4("model", model);
shader.setMat4("view", view); shader.setMat4("view", view);
shader.setMat4("projection", projection); shader.setMat4("projection", projection);
shader.setVec3("cameraPos", camera.Position); shader.setVec3("cameraPos", camera.Position);
// cubes // cubes
glBindVertexArray(cubeVAO); glBindVertexArray(cubeVAO);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture); glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
glDrawArrays(GL_TRIANGLES, 0, 36); glDrawArrays(GL_TRIANGLES, 0, 36);
model = glm::mat4(1.0f);
model = glm::rotate(model, angle, glm::vec3(0, 1, 0));
model = glm::translate(model, glm::vec3(5, 0, 0));
model = glm::rotate(model, -angle, glm::vec3(0, 1, 0));
model = glm::translate(model, glm::vec3(0, -5, 0));
shader.setMat4("model", model);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0); glBindVertexArray(0);
// draw skybox as last // draw skybox as last