add simple model view
This commit is contained in:
parent
2125b175a0
commit
008e811958
12
9.2.geometry_shader.frag
Normal file
12
9.2.geometry_shader.frag
Normal 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
16
9.2.geometry_shader.vert
Normal 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);
|
||||
}
|
@ -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 + "/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);
|
||||
|
Loading…
Reference in New Issue
Block a user