From e0a695c7b16cf2c20bcf5edeb9c23c258531fb3d Mon Sep 17 00:00:00 2001 From: k Date: Sun, 12 Jan 2025 22:33:07 -0500 Subject: [PATCH 1/4] Camera spinn around cubes --- src/main.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1718f09..4f8667d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,10 +82,15 @@ int main(void) { stbi_image_free(data); while (!glfwWindowShouldClose(window)) { + glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, + 0.1f, 100.0f); /*camera settings*/ glm::mat4 view = glm::mat4(1.0f); /*move camera*/ - glm::mat4 projection = glm::perspective( - glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f); /*camera settings*/ - view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f)); + const float radius = 10.0f; + float camX = sin(glfwGetTime()) * radius; + float camZ = cos(glfwGetTime()) * radius; + view = glm::lookAt(glm::vec3(camX, 0.0, camZ), glm::vec3(0.0, 0.0, 0.0), + glm::vec3(0.0, 1.0, 0.0)); + glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); From 16d9959ace538270c49c70ee6aab5a0a3ee72e24 Mon Sep 17 00:00:00 2001 From: k Date: Sun, 12 Jan 2025 23:12:29 -0500 Subject: [PATCH 2/4] Created texture class --- headers/texture.hpp | 15 +++++++++++++++ src/main.cpp | 33 ++++++--------------------------- src/texture.cpp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 headers/texture.hpp create mode 100644 src/texture.cpp diff --git a/headers/texture.hpp b/headers/texture.hpp new file mode 100644 index 0000000..86d7ce3 --- /dev/null +++ b/headers/texture.hpp @@ -0,0 +1,15 @@ +#ifndef TEXTURE_H +#define TEXTURE_H +#include + +class Texture { +public: + Texture(GLenum type, const char *path); + ~Texture(); + void bind(GLenum texture); + +private: + unsigned int ID; + GLenum type; +}; +#endif diff --git a/src/main.cpp b/src/main.cpp index 4f8667d..634991f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,8 +5,9 @@ #include #include #include +#include #include -#include + #define UNUSED(x) (void)(x) @@ -55,31 +56,10 @@ int main(void) { glEnableVertexAttribArray(1); /*rgb*/ glEnableVertexAttribArray(2); /*tex_cord*/ - Shader *shaderProgram; - unsigned int texture; - shaderProgram = + Shader *shaderProgram = new Shader("./shaders/MVPTexVert.glsl", "./shaders/TexFrag.glsl"); - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - - 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_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - GL_LINEAR_MIPMAP_LINEAR); - - int width, height, nrChannels; - unsigned char *data; - stbi_set_flip_vertically_on_load(true); - - data = stbi_load("./texture/container.jpg", &width, &height, &nrChannels, 0); - assert(data && "Failed to load image"); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, - GL_UNSIGNED_BYTE, data); - glGenerateMipmap(GL_TEXTURE_2D); - - stbi_image_free(data); + Texture *texture = + new Texture(GL_TEXTURE_2D,"./texture/container.jpg"); while (!glfwWindowShouldClose(window)) { glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, @@ -99,9 +79,8 @@ int main(void) { shaderProgram->setInt("Tex0", 0); shaderProgram->setMat4("view", view); shaderProgram->setMat4("projection", projection); + texture->bind(GL_TEXTURE0); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, texture); glBindVertexArray(VAO); glEnable(GL_DEPTH_TEST); diff --git a/src/texture.cpp b/src/texture.cpp new file mode 100644 index 0000000..df777db --- /dev/null +++ b/src/texture.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +Texture::Texture(GLenum type, const char *path) : type(type) { + glGenTextures(1, &ID); + glBindTexture(type, ID); + + glTexParameteri(type, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(type, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + + int width, height, nrChannels; + unsigned char *data; + stbi_set_flip_vertically_on_load(true); + + data = stbi_load(path, &width, &height, &nrChannels, 0); + assert(data && "Failed to load image"); + + glTexImage2D(type, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, + data); + glGenerateMipmap(type); + + stbi_image_free(data); +}; + +Texture::~Texture() {} + +void Texture::bind(GLenum texture) { + glActiveTexture(texture); + glBindTexture(type, ID); +} From 452e9bdc92237ef172b99c6d964c26311ceb7414 Mon Sep 17 00:00:00 2001 From: k Date: Wed, 22 Jan 2025 09:58:38 -0500 Subject: [PATCH 3/4] Basic camera class working --- headers/camera.hpp | 25 +++++++++++++++++++++++++ src/camera.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/main.cpp | 25 +++++++++---------------- 3 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 headers/camera.hpp create mode 100644 src/camera.cpp diff --git a/headers/camera.hpp b/headers/camera.hpp new file mode 100644 index 0000000..01d78e0 --- /dev/null +++ b/headers/camera.hpp @@ -0,0 +1,25 @@ +#ifndef CAMERA_H +#define CAMERA_H +#include + +class Camera { +public: + Camera(glm::vec3 pos, float yaw, float pitch, float fov, float aspect); + ~Camera(); + void setPos(glm::vec3 pos); + void setRotate(float yaw, float pitch); + glm::mat4 getView(); + glm::mat4 getProjection(); + +private: + void update(); + glm::mat4 projection; + glm::vec3 up; + glm::vec3 front; + glm::vec3 pos; + float yaw; + float pitch; + float fov; + float aspect; +}; +#endif diff --git a/src/camera.cpp b/src/camera.cpp new file mode 100644 index 0000000..5f7f89d --- /dev/null +++ b/src/camera.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +Camera::Camera(glm::vec3 pos, float yaw, float pitch, float fov, float aspect) + : up(glm::vec3(0, 1, 0)), pos(pos), yaw(yaw), pitch(pitch), fov(fov), + aspect(aspect) { + update(); +} + +Camera::~Camera() {} + +void Camera::setRotate(float yaw, float pitch) { + this->yaw = yaw; + this->pitch = pitch; + update(); +} + +void Camera::setPos(glm::vec3 pos) { this->pos = pos; } + +void Camera::update() { + glm::vec3 direction; + direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); + direction.y = sin(glm::radians(pitch)); + direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); + front = glm::normalize(direction); +} + +glm::mat4 Camera::getView() { + glm::mat4 view = glm::mat4(1.0f); + view = glm::lookAt(pos, pos + front, up); + return view; +} + +glm::mat4 Camera::getProjection() { + return glm::perspective(glm::radians(fov), aspect, 0.1f, 100.0f); +} diff --git a/src/main.cpp b/src/main.cpp index 634991f..cbfba97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,13 @@ #include /*Must be before GLFW*/ +#include "camera.hpp" #include #include #include #include #include #include -#include #include - +#include #define UNUSED(x) (void)(x) @@ -57,28 +57,21 @@ int main(void) { glEnableVertexAttribArray(2); /*tex_cord*/ Shader *shaderProgram = - new Shader("./shaders/MVPTexVert.glsl", "./shaders/TexFrag.glsl"); - Texture *texture = - new Texture(GL_TEXTURE_2D,"./texture/container.jpg"); + new Shader("./shaders/MVPTexVert.glsl", "./shaders/TexFrag.glsl"); + + Texture *texture = new Texture(GL_TEXTURE_2D, "./texture/container.jpg"); + + Camera *cam = new Camera(glm::vec3(0.0, 0.0, 5.0),-90.0f, 0.0f,45.0,800.0/600); while (!glfwWindowShouldClose(window)) { - glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, - 0.1f, 100.0f); /*camera settings*/ - glm::mat4 view = glm::mat4(1.0f); /*move camera*/ - const float radius = 10.0f; - float camX = sin(glfwGetTime()) * radius; - float camZ = cos(glfwGetTime()) * radius; - view = glm::lookAt(glm::vec3(camX, 0.0, camZ), glm::vec3(0.0, 0.0, 0.0), - glm::vec3(0.0, 1.0, 0.0)); - glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderProgram->use(); shaderProgram->setInt("Tex0", 0); - shaderProgram->setMat4("view", view); - shaderProgram->setMat4("projection", projection); + shaderProgram->setMat4("view", cam->getView()); + shaderProgram->setMat4("projection", cam->getProjection()); texture->bind(GL_TEXTURE0); glBindVertexArray(VAO); From b734e8270d590c86bcd63966312faf2c427d6b19 Mon Sep 17 00:00:00 2001 From: k Date: Sat, 1 Mar 2025 18:48:34 -0500 Subject: [PATCH 4/4] added build action --- .gitea/workflows/nix-check.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .gitea/workflows/nix-check.yaml diff --git a/.gitea/workflows/nix-check.yaml b/.gitea/workflows/nix-check.yaml new file mode 100644 index 0000000..579af6e --- /dev/null +++ b/.gitea/workflows/nix-check.yaml @@ -0,0 +1,11 @@ +name: Verify build +run-name: ${{ gitea.actor }} is building +on: [push] + +jobs: + verify_build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v30 + - run: nix-shell shell.nix --run make