Commit c3171b1f authored by Håkon Berg Borhaug's avatar Håkon Berg Borhaug
Browse files

Shaders with textures working

parent d90a5194
......@@ -15,7 +15,7 @@
#include "../../glm-master/glm/glm.hpp"
// 4 points with 3D position and 2D texture position
#define POS_ARRAY_SIZE 4 * 4 * 3 //4 * 4 * (3 + 2)
#define POS_ARRAY_SIZE 4 * 4 * (3 + 2) //4 * 4 * (3 + 2)
#define IND_ARRAY_SIZE 4 * 4 //4 * 4
class Landscape : public SceneObject
......@@ -43,28 +43,28 @@ private:
// 0.5f, 0.5f, 3.0f,
// -0.5f, 0.5f, 0.0f
// Left plane
-100.0f, -50.0f, 100.0f, //0.0f, 0.0f,
100.0f, -50.0f, 100.0f, //1.0f, 0.0f,
100.0f, -50.0f, -100.0f, //1.0f, 1.0f,
-100.0f, -50.0f, -100.0f, //0.0f, 1.0f,
-100.0f, -50.0f, 100.0f, 0.0f, 0.0f,
100.0f, -50.0f, 100.0f, 1.0f, 0.0f,
100.0f, -50.0f, -100.0f, 1.0f, 1.0f,
-100.0f, -50.0f, -100.0f, 0.0f, 1.0f,
// Middle plane
0.0f, -50.0f, 50.0f,
100.0f, -50.0f, 50.0f,
100.0f, -50.0f, -50.0f,
0.0f, -50.0f, -50.0f,
0.0f, -50.0f, 50.0f, 0.0f, 0.0f,
100.0f, -50.0f, 50.0f, 1.0f, 0.0f,
100.0f, -50.0f, -50.0f, 1.0f, 1.0f,
0.0f, -50.0f, -50.0f, 0.0f, 1.0f,
// Right plane
100.0f, -50.0f, 50.0f,
200.0f, -50.0f, 50.0f,
200.0f, -50.0f, -50.0f,
100.0f, -50.0f, -50.0f,
100.0f, -50.0f, 50.0f, 0.0f, 0.0f,
200.0f, -50.0f, 50.0f, 1.0f, 0.0f,
200.0f, -50.0f, -50.0f, 1.0f, 1.0f,
100.0f, -50.0f, -50.0f, 0.0f, 1.0f,
// Background
-1000.0f, -1000.0f, -500.0f,
1000.0f, -1000.0f, -500.0f,
1000.0f, 1000.0f, -500.0f,
-1000.0f, 1000.0f, -500.0f
-1000.0f, -1000.0f, -500.0f, 0.0f, 0.0f,
1000.0f, -1000.0f, -500.0f, 1.0f, 0.0f,
1000.0f, 1000.0f, -500.0f, 1.0f, 1.0f,
-1000.0f, 1000.0f, -500.0f, 0.0f, 1.0f,
};
unsigned int indices_[IND_ARRAY_SIZE] = {
......@@ -80,6 +80,7 @@ private:
IndexBuffer ibo = IndexBuffer(indices_, IND_ARRAY_SIZE);
Shader shader = Shader("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/shaders/Vertex.shader",
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/shaders/Fragment.shader");
Texture texture = Texture("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/color.jpg");
Texture texture = Texture("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/test.jpg");
unsigned int textureSlot = 0;
};
......@@ -4,12 +4,12 @@
layout(location = 0) out vec4 color;
//in vec2 v_TexCoord;
in vec2 v_TexCoord;
uniform vec4 u_Color;
//uniform sampler2D u_Texture;
uniform sampler2D u_Texture;
void main() {
//vec4 texColor = texture(u_Texture, v_TexCoord);
color = u_Color;
vec4 texColor = texture(u_Texture, v_TexCoord);
color = texColor;
};
......@@ -3,13 +3,13 @@
#version 330 core
layout(location = 0) in vec4 position;
//layout(location = 1) in vec2 texCoord;
layout(location = 1) in vec2 texCoord;
//out vec2 v_TexCoord;
out vec2 v_TexCoord;
uniform mat4 u_MVP;
void main() {
gl_Position = u_MVP * position;
// v_TexCoord = texCoord;
v_TexCoord = texCoord;
};
......@@ -20,8 +20,8 @@ void Landscape::privateInit()
/* LAYOUT */
// 3 floats for world position
layout.Push<float>(3);
// // 2 floats for texture position
// layout.Push<float>(2);
// 2 floats for texture position
layout.Push<float>(2);
/* VERTEX ARRAY */
vao.AddBuffer(vbo, layout);
......@@ -35,10 +35,11 @@ void Landscape::privateInit()
/* TEXTURE */
// unsigned int textureSlot = 0;
// texture.Bind(textureSlot);
// shader.SetUniform1i("u_Texture", textureSlot);
texture.Bind(textureSlot);
shader.SetUniform1i("u_Texture", textureSlot);
/* UNBINDING */
texture.Unbind();
vao.Unbind();
vbo.Unbind();
ibo.Unbind();
......@@ -51,6 +52,7 @@ void Landscape::privateRender()
shader.Bind();
vao.Bind();
ibo.Bind();
texture.Bind(textureSlot);
glm::mat4 projectionMatrix = glm::perspective(glm::radians(proj::PoV), proj::aspectRatio, proj::nearClip, proj::farClip);
glm::mat4 mvp = projectionMatrix * viewMatrix_ * matrix_;
......@@ -59,6 +61,7 @@ void Landscape::privateRender()
GLCall(glDrawElements(GL_QUADS, ibo.GetCount(), GL_UNSIGNED_INT, nullptr));
texture.Unbind();
ibo.Unbind();
vao.Unbind();
shader.Unbind();
......
......@@ -21,7 +21,7 @@ Texture::Texture(const std::string& filepath)
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_LocalBuffer));
GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_LocalBuffer));
GLCall(glBindTexture(GL_TEXTURE_2D, 0));
if (m_LocalBuffer) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment