This commit is contained in:
Kamil_DLC 2021-02-11 21:52:08 +01:00
commit cb7d45d220
4 changed files with 70 additions and 7 deletions

12
9.2.geometry_shader.frag Normal file
View File

@ -0,0 +1,12 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D texture_diffuse1;
void main()
{
FragColor = texture(texture_diffuse1, TexCoords);
}

16
9.2.geometry_shader.vert Normal file
View File

@ -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);
}

13
build.sh Executable file
View File

@ -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

View File

@ -7,7 +7,7 @@
#include <glm/gtc/type_ptr.hpp>
#include <learnopengl/filesystem.h>
#include <learnopengl/shader_m.h>
#include <learnopengl/shader.h>
#include <learnopengl/camera.h>
#include <learnopengl/model.h>
@ -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<std::string> faces
vector<string> 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);