From 11d00dbbf8b7da75da09a3df16bd667da583cba5 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 30 Nov 2023 21:13:27 +0300 Subject: [PATCH] Added ui3d shader --- src/assets/AssetsLoader.cpp | 1 + src/graphics/Batch3D.cpp | 22 +++++++++++++++------- src/graphics/Batch3D.h | 15 +++++++-------- src/logic/PlayerController.cpp | 1 - 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/assets/AssetsLoader.cpp b/src/assets/AssetsLoader.cpp index 6ea3de5b..982f46fa 100644 --- a/src/assets/AssetsLoader.cpp +++ b/src/assets/AssetsLoader.cpp @@ -110,6 +110,7 @@ void AssetsLoader::addDefaults(AssetsLoader& loader) { loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/main"), "main"); loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/lines"), "lines"); loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/ui"), "ui"); + loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/ui3d"), "ui3d"); loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/background"), "background"); loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/skybox_gen"), "skybox_gen"); diff --git a/src/graphics/Batch3D.cpp b/src/graphics/Batch3D.cpp index cb57b53a..48784123 100644 --- a/src/graphics/Batch3D.cpp +++ b/src/graphics/Batch3D.cpp @@ -4,10 +4,18 @@ #include "Texture.h" #include +#include "../typedefs.h" #define VERTEX_SIZE 9 -Batch3D::Batch3D(size_t capacity) : capacity(capacity), offset(0), color(1.0f, 1.0f, 1.0f, 0.0f){ +using glm::vec2; +using glm::vec3; +using glm::vec4; + +Batch3D::Batch3D(size_t capacity) + : capacity(capacity), + offset(0), + color(1.0f, 1.0f, 1.0f, 1.0f) { const vattr attrs[] = { {3}, {2}, {4}, {0} }; @@ -16,8 +24,8 @@ Batch3D::Batch3D(size_t capacity) : capacity(capacity), offset(0), color(1.0f, 1 mesh = new Mesh(buffer, 0, attrs); index = 0; - unsigned char pixels[] = { - 255, 255, 255, 255, + ubyte pixels[] = { + 255, 255, 255, 255, }; blank = new Texture(pixels, 1, 1, GL_RGBA); _texture = nullptr; @@ -35,7 +43,7 @@ void Batch3D::begin(){ } void Batch3D::vertex(float x, float y, float z, float u, float v, - float r, float g, float b, float a) { + float r, float g, float b, float a) { buffer[index++] = x; buffer[index++] = y; buffer[index++] = z; @@ -47,8 +55,8 @@ void Batch3D::vertex(float x, float y, float z, float u, float v, buffer[index++] = a; } void Batch3D::vertex(vec3 point, - vec2 uvpoint, - float r, float g, float b, float a) { + vec2 uvpoint, + float r, float g, float b, float a) { buffer[index++] = point.x; buffer[index++] = point.y; buffer[index++] = point.z; @@ -160,6 +168,6 @@ void Batch3D::sprite(vec3 pos, vec3 up, vec3 right, float w, float h, int atlasR void Batch3D::render() { mesh->reload(buffer, index / VERTEX_SIZE); - mesh->draw(GL_TRIANGLES); + mesh->draw(); index = 0; } diff --git a/src/graphics/Batch3D.h b/src/graphics/Batch3D.h index a63f7c20..5736f00a 100644 --- a/src/graphics/Batch3D.h +++ b/src/graphics/Batch3D.h @@ -4,8 +4,6 @@ #include #include -using namespace glm; - class Mesh; class Texture; @@ -21,10 +19,10 @@ class Batch3D { Texture* _texture; void vertex(float x, float y, float z, - float u, float v, - float r, float g, float b, float a); - void vertex(vec3 point, vec2 uvpoint, - float r, float g, float b, float a); + float u, float v, + float r, float g, float b, float a); + void vertex(glm::vec3 point, glm::vec2 uvpoint, + float r, float g, float b, float a); public: Batch3D(size_t capacity); @@ -32,8 +30,9 @@ public: void begin(); void texture(Texture* texture); - void sprite(vec3 pos, vec3 up, vec3 right, float w, float h, int atlasRes, int index, vec4 tint); - void sprite(vec3 pos, vec3 up, vec3 right, float w, float h); + void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h, + int atlasRes, int index, glm::vec4 tint); + void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h); void render(); }; diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index 726a8fe2..5bca9899 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -181,7 +181,6 @@ void PlayerController::updateControls(float delta){ player->update(level, input, delta); } -#include void PlayerController::updateInteraction(){ auto contentIds = level->content->indices; Chunks* chunks = level->chunks;