summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compile_flags.txt1
-rw-r--r--src/main.cpp124
-rw-r--r--src/shaders/default.frag4
-rw-r--r--src/texture.cpp50
-rw-r--r--src/texture.hpp10
5 files changed, 133 insertions, 56 deletions
diff --git a/src/compile_flags.txt b/src/compile_flags.txt
index b0924cf..489b8b8 100644
--- a/src/compile_flags.txt
+++ b/src/compile_flags.txt
@@ -1,4 +1,5 @@
-I../glfw/build/include
-I../glad/include
-I../stb
+-I../glm
-I./
diff --git a/src/main.cpp b/src/main.cpp
index 831fd47..2655f8c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,8 +3,7 @@
#include "input.hpp"
#include "shader.hpp"
-#define STB_IMAGE_IMPLEMENTATION
-#include "stb_image.h"
+#include "texture.hpp"
#include <iostream>
#include <cmath>
@@ -88,55 +87,58 @@ int main() {
//}
// Image/Texture stuffs
- unsigned int texture1, texture2;
- glGenTextures(1, &texture1);
- glBindTexture(GL_TEXTURE_2D, texture1);
- // set the texture wrapping/filtering options (on the currently bound texture object)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // load and generate the texture
- {
- int width, height, nrChannels;
- unsigned char *data = stbi_load("assets/container.jpg", &width, &height, &nrChannels, 0);
- if (data)
- {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
- glGenerateMipmap(GL_TEXTURE_2D);
- }
- else
- {
- std::cout << "Failed to load texture" << std::endl;
- }
- stbi_image_free(data);
- }
- glGenTextures(2, &texture2);
- glBindTexture(GL_TEXTURE_2D, texture2);
- // set the texture wrapping/filtering options (on the currently bound texture object)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // load and generate the texture
- {
- int width, height, nrChannels;
- unsigned char *data = stbi_load("assets/awesomeface.png", &width, &height, &nrChannels, 0);
- if (data)
- {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
- glGenerateMipmap(GL_TEXTURE_2D);
- }
- else
- {
- std::cout << "Failed to load texture" << std::endl;
- }
- stbi_image_free(data);
- }
+// unsigned int texture1, texture2;
+// glGenTextures(1, &texture1);
+// glBindTexture(GL_TEXTURE_2D, texture1);
+// // set the texture wrapping/filtering options (on the currently bound texture object)
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+// // load and generate the texture
+// {
+// int width, height, nrChannels;
+// unsigned char *data = stbi_load("assets/container.jpg", &width, &height, &nrChannels, 0);
+// if (data)
+// {
+// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
+// glGenerateMipmap(GL_TEXTURE_2D);
+// }
+// else
+// {
+// std::cout << "Failed to load texture" << std::endl;
+// }
+// stbi_image_free(data);
+// }
+// glGenTextures(2, &texture2);
+// glBindTexture(GL_TEXTURE_2D, texture2);
+// // set the texture wrapping/filtering options (on the currently bound texture object)
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+// // load and generate the texture
+// {
+// int width, height, nrChannels;
+// unsigned char *data = stbi_load("assets/awesomeface.png", &width, &height, &nrChannels, 0);
+// if (data)
+// {
+// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+// glGenerateMipmap(GL_TEXTURE_2D);
+// }
+// else
+// {
+// std::cout << "Failed to load texture" << std::endl;
+// }
+// stbi_image_free(data);
+// }
+ Texture texture3 = Texture("assets/awesomeface.png", VAO, VBO);
shader.use();
shader.setInt("texture1", 0);
shader.setInt("texture2", 1);
+ float pi = 2.0f * acos(0.0f);
+
// game loop
while(!glfwWindowShouldClose(window))
{
@@ -150,17 +152,31 @@ int main() {
shader.use();
float timeValue = glfwGetTime();
- float greenValue = (sin(timeValue) / 2.0f) + 0.5f;
+ float greenValue = 1.0f;//(sin(timeValue) / 2.0f) + 0.5f;
shader.set4f("ourColor", 1.0f - greenValue, greenValue, (greenValue / 2.0f) + 0.25f, 1.0f);
shader.set1f("offset_x", greenValue - 0.5);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, texture1);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, texture2);
- glBindVertexArray(VAO); // activate the preconfigured settings
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); // :)
+ float sin_move0 = sin((timeValue) / 2.0f) / 2.0f;
+ float cos_move0 = cos((timeValue) / 2.0f) / 2.0f;
+ float sin_move1 = sin((timeValue + (1*pi)) / 2.0f) / 2.0f;
+ float cos_move1 = cos((timeValue + (1*pi)) / 2.0f) / 2.0f;
+ float sin_move2 = sin((timeValue + (2*pi)) / 2.0f) / 2.0f;
+ float cos_move2 = cos((timeValue + (2*pi)) / 2.0f) / 2.0f;
+ float sin_move3 = sin((timeValue + (3*pi)) / 2.0f) / 2.0f;
+ float cos_move3 = cos((timeValue + (3*pi)) / 2.0f) / 2.0f;
+ //glActiveTexture(GL_TEXTURE0);
+ //glBindTexture(GL_TEXTURE_2D, texture1);
+ //glActiveTexture(GL_TEXTURE1);
+ //glBindTexture(GL_TEXTURE_2D, texture2);
+ //glBindVertexArray(VAO); // activate the preconfigured settings
+ //glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); // :)
+
+ texture3.draw(cos_move0, sin_move0, 0.5, 0.5);
+ texture3.draw(cos_move1, sin_move1, 0.5, 0.5);
+ texture3.draw(cos_move2, sin_move2, 0.5, 0.5);
+ texture3.draw(cos_move3, sin_move3, 0.5, 0.5);
+ //drawTexture(texture1, VAO, VBO, -0.5, -0.5, 0.5, 0.5);
glBindVertexArray(0);
glfwSwapBuffers(window);
diff --git a/src/shaders/default.frag b/src/shaders/default.frag
index 17b84a0..241369e 100644
--- a/src/shaders/default.frag
+++ b/src/shaders/default.frag
@@ -5,12 +5,12 @@ in vec3 ourColor;
in vec2 TexCoord;
uniform sampler2D texture1;
-uniform sampler2D texture2;
+//uniform sampler2D texture2;
void main()
{
vec2 texInvert = vec2(TexCoord.x, -TexCoord.y);
- FragColor = mix(texture(texture1, texInvert), texture(texture2, texInvert), 0.2);
+ FragColor = texture(texture1, texInvert);// * ourColor;
//FragColor = texture(ourTexture, TexCoord) * vec4(ourColor.xyz, 1.0);
}
diff --git a/src/texture.cpp b/src/texture.cpp
new file mode 100644
index 0000000..4432f4c
--- /dev/null
+++ b/src/texture.cpp
@@ -0,0 +1,50 @@
+#include "texture.hpp"
+
+#include <iostream>
+#include "glad/glad.h"
+#define STB_IMAGE_IMPLEMENTATION
+#include "stb_image.h"
+
+
+Texture::Texture(const char* texturePath, unsigned int VAO, unsigned int VBO)
+{
+ this->VAO = VAO;
+ this->VBO = VBO;
+ glGenTextures(1, &id);
+ glBindTexture(GL_TEXTURE_2D, id);
+ // set the texture wrapping/filtering options (on the currently bound texture object)
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ // load and generate the texture
+ int width, height, nrChannels;
+ unsigned char *data = stbi_load(texturePath, &width, &height, &nrChannels, 0);
+ if (data)
+ {
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ glGenerateMipmap(GL_TEXTURE_2D);
+ }
+ else
+ {
+ std::cout << "Failed to load texture" << std::endl;
+ }
+ stbi_image_free(data);
+}
+
+void Texture::draw(float x, float y, float width, float height)
+{
+ float vertices[] = {
+ // positions // colors // texture coords
+ x-width, y+height, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
+ x-width, y, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
+ x, y, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
+ x, y+height, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left
+ };
+ glBindBuffer(GL_ARRAY_BUFFER, VBO); // bind(activate) the buffer to the ARRAY_BUFFER
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW); // upload the data
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, id);
+ glBindVertexArray(VAO);
+ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
+}
diff --git a/src/texture.hpp b/src/texture.hpp
new file mode 100644
index 0000000..0a9c9e6
--- /dev/null
+++ b/src/texture.hpp
@@ -0,0 +1,10 @@
+#pragma once
+#include "glad/glad.h"
+
+class Texture
+{
+ public:
+ unsigned int id, VAO, VBO;
+ Texture(const char* texturePath, unsigned int VAO, unsigned int VBO);
+ void draw(float x, float y, float width, float height);
+};