From 2125b175a01224970ad510c6fe7f93a79edff29d Mon Sep 17 00:00:00 2001 From: Artur Tamborski Date: Tue, 9 Feb 2021 00:36:06 +0100 Subject: [PATCH 1/2] moj skrypt do uruchamiania na linuxie --- build.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..6fc21d0 --- /dev/null +++ b/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +rm a.out || true + +g++ \ + -g \ + -I../LearnOpenGL/configuration/ \ + -I../LearnOpenGL/includes/ \ + glad.c opengl_test35.cpp \ + -L/usr/local/lib \ + -ldl -lglfw -lrt -lm -ldl -lGLEW -lassimp \ + && \ + ./a.out From 008e811958b5ba0b918162035653ebe2c92e06ad Mon Sep 17 00:00:00 2001 From: Artur Tamborski Date: Tue, 9 Feb 2021 01:20:47 +0100 Subject: [PATCH 2/2] add simple model view --- 9.2.geometry_shader.frag | 12 ++++++++++++ 9.2.geometry_shader.vert | 16 ++++++++++++++++ opengl_test35.cpp | 36 +++++++++++++++++++++++++++++------- 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 9.2.geometry_shader.frag create mode 100644 9.2.geometry_shader.vert diff --git a/9.2.geometry_shader.frag b/9.2.geometry_shader.frag new file mode 100644 index 0000000..7d157ae --- /dev/null +++ b/9.2.geometry_shader.frag @@ -0,0 +1,12 @@ +#version 330 core +out vec4 FragColor; + +in vec2 TexCoords; + +uniform sampler2D texture_diffuse1; + +void main() +{ + FragColor = texture(texture_diffuse1, TexCoords); +} + diff --git a/9.2.geometry_shader.vert b/9.2.geometry_shader.vert new file mode 100644 index 0000000..ed5332c --- /dev/null +++ b/9.2.geometry_shader.vert @@ -0,0 +1,16 @@ +#version 330 core +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexCoords; + +out vec2 TexCoords; + +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; + +void main() +{ + TexCoords = aTexCoords; + gl_Position = projection * view * model * vec4(aPos, 1.0); +} diff --git a/opengl_test35.cpp b/opengl_test35.cpp index 77afbcc..65d8ca6 100644 --- a/opengl_test35.cpp +++ b/opengl_test35.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -76,6 +76,14 @@ int main() // ----------------------------- 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 // ------------------------- Shader shader("6.2.cubemaps.vert", "6.2.cubemaps.frag"); @@ -195,16 +203,16 @@ int main() // load textures // ------------- - string dir = "park-skyboxes/NiagaraFalls2"; + string dir = "mountain-skyboxes/Ryfjallet"; - vector faces + vector faces { - "../resources/textures/skybox/"+dir+"/posx.jpg", + "../resources/textures/skybox/" + dir + "/posx.jpg", "../resources/textures/skybox/" + dir + "/negx.jpg", "../resources/textures/skybox/" + dir + "/posy.jpg", "../resources/textures/skybox/" + dir + "/negy.jpg", "../resources/textures/skybox/" + dir + "/posz.jpg", - "../resources/textures/skybox/" + dir + "/negz.jpg" + "../resources/textures/skybox/" + dir + "/negz.jpg", }; unsigned int cubemapTexture = loadCubemap(faces); @@ -237,10 +245,24 @@ int main() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // draw scene as normal - shader.use(); - glm::mat4 model = glm::mat4(1.0f); 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 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("view", view); shader.setMat4("projection", projection);