Prepared everything for the lighting section
This commit is contained in:
parent
42db40144e
commit
e874dae218
|
@ -162,6 +162,7 @@
|
||||||
<ClInclude Include="textures\Texture2D.h" />
|
<ClInclude Include="textures\Texture2D.h" />
|
||||||
<ClInclude Include="util\property.h" />
|
<ClInclude Include="util\property.h" />
|
||||||
<ClInclude Include="util\stb_image.h" />
|
<ClInclude Include="util\stb_image.h" />
|
||||||
|
<ClInclude Include="vertices.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="images\awesomeface.png" />
|
<Image Include="images\awesomeface.png" />
|
||||||
|
|
|
@ -62,6 +62,9 @@
|
||||||
<ClInclude Include="object\game_object.h">
|
<ClInclude Include="object\game_object.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="vertices.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CopyFileToFolders Include="Shaders\default\default.frag" />
|
<CopyFileToFolders Include="Shaders\default\default.frag" />
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#include "util/camera/camera.h"
|
#include "util/camera/camera.h"
|
||||||
#include "object/game_object.h"
|
#include "object/game_object.h"
|
||||||
|
|
||||||
|
#include "vertices.h"
|
||||||
|
|
||||||
// Continue: https://learnopengl.com/Lighting/Colors
|
// Continue: https://learnopengl.com/Lighting/Colors
|
||||||
// Chapter: A lighting scene
|
// Chapter: A lighting scene
|
||||||
//
|
//
|
||||||
|
@ -123,52 +125,6 @@ int main()
|
||||||
|
|
||||||
Configure(window);
|
Configure(window);
|
||||||
|
|
||||||
|
|
||||||
float vertices[] = { // object coordinates, uv-coordinates
|
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
|
|
||||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
|
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
|
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
|
|
||||||
|
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
|
||||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
|
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
|
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
|
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
|
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
|
||||||
|
|
||||||
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
|
||||||
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
|
||||||
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
|
||||||
|
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
|
||||||
|
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
|
||||||
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
|
|
||||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
|
|
||||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
|
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
|
||||||
|
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
|
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
|
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f
|
|
||||||
};
|
|
||||||
std::vector<Nebulix::VertexAttribute> vertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute(GL_FLOAT, GL_FALSE, 2) };
|
|
||||||
|
|
||||||
GLuint faces[]{
|
GLuint faces[]{
|
||||||
0, 1, 3,
|
0, 1, 3,
|
||||||
1, 2, 3
|
1, 2, 3
|
||||||
|
@ -196,7 +152,7 @@ int main()
|
||||||
glBindVertexArray(vertexArrayObject);
|
glBindVertexArray(vertexArrayObject);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_container), vertices_container, GL_STATIC_DRAW);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferObject);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferObject);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(faces), faces, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(faces), faces, GL_STATIC_DRAW);
|
||||||
|
@ -225,10 +181,11 @@ int main()
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
|
||||||
// TEXTURES
|
// TEXTURES
|
||||||
Texture2D containerImage("images/container.jpg");
|
//Texture2D containerImage("images/container.jpg");
|
||||||
Texture2D faceImage("images/awesomeface.png", 0, GL_RGBA);
|
//Texture2D faceImage("images/awesomeface.png", 0, GL_RGBA);
|
||||||
|
|
||||||
std::vector<float> verts(std::begin(vertices), std::end(vertices));
|
std::vector<float> verts(std::begin(vertices_container), std::end(vertices_container));
|
||||||
|
std::vector<Nebulix::VertexAttribute> vertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute(GL_FLOAT, GL_FALSE, 2) };
|
||||||
Nebulix::GameObject cube = Nebulix::GameObject(verts, vertexAttribs);
|
Nebulix::GameObject cube = Nebulix::GameObject(verts, vertexAttribs);
|
||||||
// main loop
|
// main loop
|
||||||
while(!glfwWindowShouldClose(window))
|
while(!glfwWindowShouldClose(window))
|
||||||
|
@ -245,26 +202,10 @@ int main()
|
||||||
mat4 projectionMatrix = glm::perspective(glm::radians(cam.Fov), 800.0f / 600.0f, 0.1f, 100.0f);
|
mat4 projectionMatrix = glm::perspective(glm::radians(cam.Fov), 800.0f / 600.0f, 0.1f, 100.0f);
|
||||||
|
|
||||||
shader->Use();
|
shader->Use();
|
||||||
shader->SetInt("ourTexture1", 0);
|
|
||||||
shader->SetInt("ourTexture2", 1);
|
|
||||||
shader->SetMatrix("viewMatrix", cam.GetViewMatrix()); // more or less the camera
|
shader->SetMatrix("viewMatrix", cam.GetViewMatrix()); // more or less the camera
|
||||||
shader->SetMatrix("projectionMatrix", projectionMatrix);
|
shader->SetMatrix("projectionMatrix", projectionMatrix);
|
||||||
|
shader->SetMatrix("modelMatrix", cube.GetModelMatrix());
|
||||||
containerImage.BindTexture();
|
cube.Draw();
|
||||||
faceImage.BindTexture(GL_TEXTURE0 + 1); // GL_TEXTURE0 + 1 == GL_TEXTURE1, this means looping over multiple texture units is easily possible
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++)
|
|
||||||
{
|
|
||||||
cube.Position = cubePositions[i];
|
|
||||||
mat4 model = cube.GetModelMatrix();
|
|
||||||
float angle = (20.0f * i);
|
|
||||||
if (i % 3 == 0)
|
|
||||||
angle = currentFrameTime * 25;
|
|
||||||
model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
|
|
||||||
shader->SetMatrix("modelMatrix", model);
|
|
||||||
|
|
||||||
cube.Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
in vec3 ourColour;
|
|
||||||
in vec2 texCoord;
|
|
||||||
|
|
||||||
uniform sampler2D ourTexture1;
|
|
||||||
uniform sampler2D ourTexture2;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = mix(texture(ourTexture1, texCoord), texture(ourTexture2, texCoord), 0.2) * vec4(ourColour, 1.0);
|
FragColor = vec4(1.0);
|
||||||
}
|
}
|
|
@ -1,21 +1,12 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
layout (location = 0) in vec3 aPos;
|
layout (location = 0) in vec3 aPos;
|
||||||
layout (location = 1) in vec2 aTexCoord;
|
|
||||||
|
|
||||||
out vec3 ourColour;
|
|
||||||
out vec2 texCoord;
|
|
||||||
|
|
||||||
uniform mat4 modelMatrix;
|
uniform mat4 modelMatrix;
|
||||||
uniform mat4 viewMatrix;
|
uniform mat4 viewMatrix;
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
|
|
||||||
//uniform mat4 transform;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// note that we read the multiplication from right to left
|
// note that we read the multiplication from right to left
|
||||||
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(aPos, 1.0);
|
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(aPos, 1.0);
|
||||||
//gl_Position = transform * vec4(aPos, 1.0);
|
|
||||||
ourColour = vec3(1.0);
|
|
||||||
texCoord = aTexCoord;
|
|
||||||
}
|
}
|
||||||
|
|
90
src/Engine/vertices.h
Normal file
90
src/Engine/vertices.h
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
float vertices_light[] = {
|
||||||
|
-0.5f, -0.5f, -0.5f,
|
||||||
|
0.5f, -0.5f, -0.5f,
|
||||||
|
0.5f, 0.5f, -0.5f,
|
||||||
|
0.5f, 0.5f, -0.5f,
|
||||||
|
-0.5f, 0.5f, -0.5f,
|
||||||
|
-0.5f, -0.5f, -0.5f,
|
||||||
|
|
||||||
|
-0.5f, -0.5f, 0.5f,
|
||||||
|
0.5f, -0.5f, 0.5f,
|
||||||
|
0.5f, 0.5f, 0.5f,
|
||||||
|
0.5f, 0.5f, 0.5f,
|
||||||
|
-0.5f, 0.5f, 0.5f,
|
||||||
|
-0.5f, -0.5f, 0.5f,
|
||||||
|
|
||||||
|
-0.5f, 0.5f, 0.5f,
|
||||||
|
-0.5f, 0.5f, -0.5f,
|
||||||
|
-0.5f, -0.5f, -0.5f,
|
||||||
|
-0.5f, -0.5f, -0.5f,
|
||||||
|
-0.5f, -0.5f, 0.5f,
|
||||||
|
-0.5f, 0.5f, 0.5f,
|
||||||
|
|
||||||
|
0.5f, 0.5f, 0.5f,
|
||||||
|
0.5f, 0.5f, -0.5f,
|
||||||
|
0.5f, -0.5f, -0.5f,
|
||||||
|
0.5f, -0.5f, -0.5f,
|
||||||
|
0.5f, -0.5f, 0.5f,
|
||||||
|
0.5f, 0.5f, 0.5f,
|
||||||
|
|
||||||
|
-0.5f, -0.5f, -0.5f,
|
||||||
|
0.5f, -0.5f, -0.5f,
|
||||||
|
0.5f, -0.5f, 0.5f,
|
||||||
|
0.5f, -0.5f, 0.5f,
|
||||||
|
-0.5f, -0.5f, 0.5f,
|
||||||
|
-0.5f, -0.5f, -0.5f,
|
||||||
|
|
||||||
|
-0.5f, 0.5f, -0.5f,
|
||||||
|
0.5f, 0.5f, -0.5f,
|
||||||
|
0.5f, 0.5f, 0.5f,
|
||||||
|
0.5f, 0.5f, 0.5f,
|
||||||
|
-0.5f, 0.5f, 0.5f,
|
||||||
|
-0.5f, 0.5f, -0.5f
|
||||||
|
};
|
||||||
|
|
||||||
|
float vertices_container[] = { // object coordinates, uv-coordinates
|
||||||
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
|
||||||
|
0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
|
||||||
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
||||||
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
||||||
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
|
||||||
|
|
||||||
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
||||||
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
|
||||||
|
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
|
||||||
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
||||||
|
|
||||||
|
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
||||||
|
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
||||||
|
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
||||||
|
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
||||||
|
|
||||||
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
||||||
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
||||||
|
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
||||||
|
|
||||||
|
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
|
||||||
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
|
||||||
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
|
||||||
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
|
||||||
|
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
|
||||||
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
||||||
|
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
|
||||||
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user