diff --git a/src/Engine/Engine.vcxproj b/src/Engine/Engine.vcxproj index 6ef7053..1163116 100644 --- a/src/Engine/Engine.vcxproj +++ b/src/Engine/Engine.vcxproj @@ -162,6 +162,7 @@ + diff --git a/src/Engine/Engine.vcxproj.filters b/src/Engine/Engine.vcxproj.filters index bb4b653..e908a9c 100644 --- a/src/Engine/Engine.vcxproj.filters +++ b/src/Engine/Engine.vcxproj.filters @@ -62,6 +62,9 @@ Header Files + + Header Files + diff --git a/src/Engine/main.cpp b/src/Engine/main.cpp index 8331c0a..a0757ca 100644 --- a/src/Engine/main.cpp +++ b/src/Engine/main.cpp @@ -13,6 +13,8 @@ #include "util/camera/camera.h" #include "object/game_object.h" +#include "vertices.h" + // Continue: https://learnopengl.com/Lighting/Colors // Chapter: A lighting scene // @@ -123,52 +125,6 @@ int main() 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 vertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute(GL_FLOAT, GL_FALSE, 2) }; - GLuint faces[]{ 0, 1, 3, 1, 2, 3 @@ -196,7 +152,7 @@ int main() glBindVertexArray(vertexArrayObject); 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); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(faces), faces, GL_STATIC_DRAW); @@ -225,10 +181,11 @@ int main() glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // TEXTURES - Texture2D containerImage("images/container.jpg"); - Texture2D faceImage("images/awesomeface.png", 0, GL_RGBA); + //Texture2D containerImage("images/container.jpg"); + //Texture2D faceImage("images/awesomeface.png", 0, GL_RGBA); - std::vector verts(std::begin(vertices), std::end(vertices)); + std::vector verts(std::begin(vertices_container), std::end(vertices_container)); + std::vector vertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute(GL_FLOAT, GL_FALSE, 2) }; Nebulix::GameObject cube = Nebulix::GameObject(verts, vertexAttribs); // main loop 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); shader->Use(); - shader->SetInt("ourTexture1", 0); - shader->SetInt("ourTexture2", 1); shader->SetMatrix("viewMatrix", cam.GetViewMatrix()); // more or less the camera shader->SetMatrix("projectionMatrix", projectionMatrix); - - containerImage.BindTexture(); - 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(); - } + shader->SetMatrix("modelMatrix", cube.GetModelMatrix()); + cube.Draw(); glfwSwapBuffers(window); glfwPollEvents(); diff --git a/src/Engine/shaders/default/default.frag b/src/Engine/shaders/default/default.frag index c796848..3214fb3 100644 --- a/src/Engine/shaders/default/default.frag +++ b/src/Engine/shaders/default/default.frag @@ -1,13 +1,7 @@ #version 330 core out vec4 FragColor; -in vec3 ourColour; -in vec2 texCoord; - -uniform sampler2D ourTexture1; -uniform sampler2D ourTexture2; - void main() { - FragColor = mix(texture(ourTexture1, texCoord), texture(ourTexture2, texCoord), 0.2) * vec4(ourColour, 1.0); + FragColor = vec4(1.0); } \ No newline at end of file diff --git a/src/Engine/shaders/default/default.vert b/src/Engine/shaders/default/default.vert index afa2115..9540dff 100644 --- a/src/Engine/shaders/default/default.vert +++ b/src/Engine/shaders/default/default.vert @@ -1,21 +1,12 @@ #version 330 core layout (location = 0) in vec3 aPos; -layout (location = 1) in vec2 aTexCoord; - -out vec3 ourColour; -out vec2 texCoord; uniform mat4 modelMatrix; uniform mat4 viewMatrix; uniform mat4 projectionMatrix; -//uniform mat4 transform; - void main() { // note that we read the multiplication from right to left gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(aPos, 1.0); - //gl_Position = transform * vec4(aPos, 1.0); - ourColour = vec3(1.0); - texCoord = aTexCoord; } diff --git a/src/Engine/vertices.h b/src/Engine/vertices.h new file mode 100644 index 0000000..fc1a867 --- /dev/null +++ b/src/Engine/vertices.h @@ -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 +};