diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1ff0c42..0000000 --- a/.gitattributes +++ /dev/null @@ -1,63 +0,0 @@ -############################################################################### -# Set default behavior to automatically normalize line endings. -############################################################################### -* text=auto - -############################################################################### -# Set default behavior for command prompt diff. -# -# This is need for earlier builds of msysgit that does not have it on by -# default for csharp files. -# Note: This is only used by command line -############################################################################### -#*.cs diff=csharp - -############################################################################### -# Set the merge driver for project and solution files -# -# Merging from the command prompt will add diff markers to the files if there -# are conflicts (Merging from VS is not affected by the settings below, in VS -# the diff markers are never inserted). Diff markers may cause the following -# file extensions to fail to load in VS. An alternative would be to treat -# these files as binary and thus will always conflict and require user -# intervention with every merge. To do so, just uncomment the entries below -############################################################################### -#*.sln merge=binary -#*.csproj merge=binary -#*.vbproj merge=binary -#*.vcxproj merge=binary -#*.vcproj merge=binary -#*.dbproj merge=binary -#*.fsproj merge=binary -#*.lsproj merge=binary -#*.wixproj merge=binary -#*.modelproj merge=binary -#*.sqlproj merge=binary -#*.wwaproj merge=binary - -############################################################################### -# behavior for image files -# -# image files are treated as binary by default. -############################################################################### -#*.jpg binary -#*.png binary -#*.gif binary - -############################################################################### -# diff behavior for common document formats -# -# Convert binary document formats to text before diffing them. This feature -# is only available from the command line. Turn it on by uncommenting the -# entries below. -############################################################################### -#*.doc diff=astextplain -#*.DOC diff=astextplain -#*.docx diff=astextplain -#*.DOCX diff=astextplain -#*.dot diff=astextplain -#*.DOT diff=astextplain -#*.pdf diff=astextplain -#*.PDF diff=astextplain -#*.rtf diff=astextplain -#*.RTF diff=astextplain diff --git a/Callbacks.cpp b/Callbacks.cpp deleted file mode 100644 index 6d10a4a..0000000 --- a/Callbacks.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "Callbacks.h" -#include - -#include "Game.h" - - -void errorCallback(int error, const char* description) { - fputs(description, stderr); -} - -void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) { - Game& game = Game::getInstance(); - game.m_textArea.keyInput(key, scancode, action, mods); -} - -void charCallback(GLFWwindow* window, unsigned int codepoint) { - Game& game = Game::getInstance(); - game.m_textArea.charInput(codepoint); -} - -void windowResizeCallback(GLFWwindow* window, int width, int height) { - if (height == 0) return; - glViewport(0, 0, width, height); -} - diff --git a/Callbacks.h b/Callbacks.h deleted file mode 100644 index 402a524..0000000 --- a/Callbacks.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include -#include - - -void errorCallback(int error, const char* description); - -void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); - -void charCallback(GLFWwindow* window, unsigned int codepoint); - -void windowResizeCallback(GLFWwindow* window, int width, int height); \ No newline at end of file diff --git a/Game.cpp b/Game.cpp deleted file mode 100644 index c41c489..0000000 --- a/Game.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "Game.h" -#include "Callbacks.h" -#include "Utils.h" - -void Game::initOpenGL() { - - glfwSetErrorCallback(errorCallback); - - if (!glfwInit()) { - fprintf(stderr, "Failed to initialize GLFW.\n"); - exit(EXIT_FAILURE); - } - - glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); - glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); - - int width = 800; - int height = 800; - - m_window = glfwCreateWindow(width, height, "OpenGL", NULL, NULL); - - if (!m_window) - { - fprintf(stderr, "Failed to create window.\n"); - glfwTerminate(); - exit(EXIT_FAILURE); - } - - glfwMakeContextCurrent(m_window); - glfwSwapInterval(1); - - if (glewInit() != GLEW_OK) { - fprintf(stderr, "Failed to initialize GLEW.\n"); - glfwTerminate(); - exit(EXIT_FAILURE); - } -} - -void Game::init() { - - glClearColor(0.8f, 0.8f, 0.8f, 1); - glEnable(GL_DEPTH_TEST); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - - glfwSetWindowSizeCallback(m_window, windowResizeCallback); - glfwSetKeyCallback(m_window, keyCallback); - glfwSetCharCallback(m_window, charCallback); - - m_sp2d = new ShaderProgram("shaders/2d_vec.glsl", "shaders/2d_geom.glsl", "shaders/2d_frag.glsl"); - m_sp2dPost = new ShaderProgram("shaders/post_vec.glsl", nullptr, "shaders/post_frag.glsl"); - - m_asciiTexture = loadTexture("assets/ascii.png"); - - m_frameColorBuffer = createColorBuffer(m_window); - m_frameDepthBuffer = createDepthBuffer(m_window); - m_frameBuffer = createFrameBuffer(m_frameColorBuffer, m_frameDepthBuffer); - -} - -void Game::update(double delta) { - m_textArea.update(delta); - -} - -void Game::draw() { - glBindFramebuffer(GL_FRAMEBUFFER, m_frameBuffer); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - - m_sp2d->use(); - glEnableVertexAttribArray(m_sp2d->a("pos")); - glEnableVertexAttribArray(m_sp2d->a("dim")); - glEnableVertexAttribArray(m_sp2d->a("tex")); - glEnableVertexAttribArray(m_sp2d->a("inv")); - - bindTilemap(m_sp2d, m_asciiTexture, 2, glm::ivec2(16, 16)); - - int width, height; - glfwGetWindowSize(m_window, &width, &height); - glUniform2f(m_sp2d->u("window"), width, height); - glUniform1f(m_sp2d->u("layer"), 0.0f); - - m_textArea.draw(m_sp2d); - - // The value zero is reserved to represent the default framebuffer provided by the windowing system - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glDisable(GL_DEPTH_TEST); - glClear(GL_COLOR_BUFFER_BIT); - - m_sp2dPost->use(); - glActiveTexture(GL_TEXTURE0 + 3); - glBindTexture(GL_TEXTURE_2D, m_frameColorBuffer); - glDrawArrays(GL_TRIANGLES, 0, 6); - glUniform1i(m_sp2dPost->u("colorBuffer"), 3); - glfwSwapBuffers(m_window); -} - -void Game::clean() { - delete m_sp2d; - delete m_sp2dPost; - - glDeleteFramebuffers(1, &m_frameBuffer); - glDeleteTextures(1, &m_frameColorBuffer); - glDeleteRenderbuffers(1, &m_frameDepthBuffer); -} - -void Game::cleanOpenGL() { - glfwDestroyWindow(m_window); - glfwTerminate(); -} - - diff --git a/Game.h b/Game.h deleted file mode 100644 index a13c943..0000000 --- a/Game.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include "Callbacks.h" -#include "ShaderProgram.h" -#include "GraphicalTextArea.h" - - -class Game{ - -private: - void initOpenGL(); - void init(); - void update(double delta); - void draw(); - void clean(); - void cleanOpenGL(); - -public: - static Game& getInstance() { - static Game instance; - return instance; - } - - void run() { - initOpenGL(); - init(); - - double lastFrameTime = glfwGetTime(); - - while (!glfwWindowShouldClose(m_window)) - { - double newFrameTime = glfwGetTime(); - double delta = newFrameTime - lastFrameTime; - - update(delta); - draw(); - - lastFrameTime = newFrameTime; - glfwPollEvents(); - } - - clean(); - cleanOpenGL(); - } - -private: - GLFWwindow* m_window; - GraphicalTextArea m_textArea{ }; - - ShaderProgram* m_sp2d{ nullptr }; - ShaderProgram* m_sp2dPost{ nullptr }; - - GLuint m_frameColorBuffer; - GLuint m_frameDepthBuffer; - GLuint m_frameBuffer; - - GLuint m_asciiTexture; - - friend void errorCallback(int error, const char* description); - friend void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); - friend void charCallback(GLFWwindow* window, unsigned int codepoint); - friend void windowResizeCallback(GLFWwindow* window, int width, int height); -}; - diff --git a/GraphicalTextArea.cpp b/GraphicalTextArea.cpp deleted file mode 100644 index e9bdecc..0000000 --- a/GraphicalTextArea.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include -#include - -#include "GraphicalTextArea.h" - - - -bool GraphicalTextArea::keyInput(int key, int scancode, int action, int mods) { - if (action == GLFW_RELEASE) return false; - - bool shift_mod = mods & GLFW_MOD_SHIFT; - bool controlMod = mods & GLFW_MOD_CONTROL; - - switch (key) { - case GLFW_KEY_ENTER: - type('\n'); - return true; - case GLFW_KEY_BACKSPACE: - backspace(); - return true; - case GLFW_KEY_DELETE: - del(); - return true; - case GLFW_KEY_UP: - moveCursorUp(shift_mod); - return true; - case GLFW_KEY_DOWN: - moveCursorDown(shift_mod); - return true; - case GLFW_KEY_LEFT: - moveCursorLeft(shift_mod); - return true; - case GLFW_KEY_RIGHT: - moveCursorRight(shift_mod); - return true; - case GLFW_KEY_END: - end(shift_mod); - return true; - case GLFW_KEY_HOME: - home(shift_mod); - return true; - case GLFW_KEY_TAB: - type('\t'); - return true; - case GLFW_KEY_V: - if (controlMod) { - const char* clipboardString = glfwGetClipboardString(NULL); - if (clipboardString) { - paste(clipboardString); - return true; - } - } - break; - case GLFW_KEY_C: - if (controlMod) { - std::string selectedText = getSelected(); - if (!selectedText.empty()) { - glfwSetClipboardString(NULL, selectedText.c_str()); - return true; - }; - } - break; - case GLFW_KEY_X: - if (mods & GLFW_MOD_CONTROL) { - std::string selectedText = getSelected(); - if (!selectedText.empty()) { - glfwSetClipboardString(NULL, selectedText.c_str()); - del(); - return true; - } - } - break; - case GLFW_KEY_A: - if (controlMod) { - selectAll(); - return true; - } - break; - default: - return false; - } -} - -bool GraphicalTextArea::charInput(unsigned int codepoint) { - if (codepoint < 0 || codepoint > 255) return false; - type(static_cast(codepoint)); - return true; -} - -void GraphicalTextArea::update(double delta) { - // update cursor blink - cursorBlinkTimer.update(delta); - if (cursorBlinkTimer.done()) { - cursorBlinkState = !cursorBlinkState; - cursorBlinkTimer.restart(); - } -} - -void GraphicalTextArea::draw(ShaderProgram* shader) { - - data.clear(); - - // draw margin - for (size_t line = 0; line < areaSize.y; ++line) { - std::string numberStr = line < lineCount() ? std::to_string(line + 1) : ""; - for (size_t margin = 0; margin < marginSize; ++margin) { - size_t index = numberStr.length() - marginSize + margin + 1; - char c = (index < numberStr.length()) ? numberStr[index] : 0; - - data.push_back({ origin + glm::vec2(margin, line) * charSize, charSize, 2 + 32 * c, 1 }); - } - } - - - // draw text area - CharPos char_pos{ 0, 0 }; - CharPos cursor_pos = getRealCursor(); - for (char_pos.y = 0; char_pos.y < areaSize.y; ++char_pos.y) { - for (char_pos.x = 0; char_pos.x < areaSize.x; ++char_pos.x) { - - char c = getChar(char_pos); - - bool inverse; - if (char_pos == cursor_pos) { - inverse = cursorBlinkState; - } else { - inverse = isCharSelected(char_pos); - } - - data.push_back({ origin + (char_pos.convert() + glm::vec2(marginSize, 0)) * charSize, charSize, texture_index + 32 * c, inverse ? 1 : 0 }); - } - } - - if (data.size() == 0) return; - - shader->use(); - glVertexAttribPointer(shader->a("pos"), 2, GL_FLOAT, false, sizeof(DrawData), &data[0].pos); - glVertexAttribPointer(shader->a("dim"), 2, GL_FLOAT, false, sizeof(DrawData), &data[0].dim); - glVertexAttribIPointer(shader->a("tex"), 1, GL_INT, sizeof(DrawData), &data[0].tex); - glVertexAttribIPointer(shader->a("inv"), 1, GL_INT, sizeof(DrawData), &data[0].invert); - - glDrawArrays(GL_POINTS, 0, data.size()); -} diff --git a/GraphicalTextArea.h b/GraphicalTextArea.h deleted file mode 100644 index 4fbe87e..0000000 --- a/GraphicalTextArea.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#include - -#include "ShaderProgram.h" -#include "TextArea.h" -#include "Timer.h" - - -struct DrawData { - glm::vec2 pos; - glm::vec2 dim; - int tex; - int invert; // treated as bool -}; - -class GraphicalTextArea : public TextArea { -public: - using TextArea::TextArea; - - bool keyInput(int key, int scancode, int action, int mods); - bool charInput(unsigned int codepoint); - - void update(double delta); - void draw(ShaderProgram* shader); - -private: - std::vector data; - - glm::vec2 origin{ 48, 80 }; - glm::ivec2 areaSize{ 40, 20 }; - glm::vec2 charSize{ 16, 32 }; - - size_t marginSize = 4; - - int texture_index = 2; - - Timer cursorBlinkTimer{ 0.5 }; - bool cursorBlinkState = false; -}; \ No newline at end of file diff --git a/LoadOBJ.cpp b/LoadOBJ.cpp deleted file mode 100644 index d059bd4..0000000 --- a/LoadOBJ.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "LoadOBJ.h" - -bool loadOBJ(const std::string path, std::vector& outVertices, std::vector& outUVs, std::vector& outNormals) { - - std::vector vertexIndices, uvIndices, normalIndices; - std::vector tempVertices; - std::vector tempUvs; - std::vector tempNormals; - - std::ifstream file(path); - if (!file.is_open()) { - std::cerr << "Unable to load .obj file" << std::endl; - return false; - } - - std::string line; - - while (std::getline(file, line)) { - if (line.substr(0, 2) == "v ") { - std::istringstream iss(line.substr(2)); - glm::vec3 vertex; - iss >> vertex[0] >> vertex[1] >> vertex[2]; - tempVertices.push_back(vertex); - } else if (line.substr(0, 3) == "vt ") { - std::istringstream iss(line.substr(3)); - glm::vec2 uv; - iss >> uv[0] >> uv[1]; - tempUvs.push_back(uv); - } else if (line.substr(0, 3) == "vn ") { - std::istringstream iss(line.substr(3)); - glm::vec3 normal; - iss >> normal[0] >> normal[1] >> normal[2]; - tempNormals.push_back(normal); - } else if (line.substr(0, 2) == "f ") { - unsigned int v[3], vt[3], vn[3]; - sscanf_s(line.c_str(), "f %i/%i/%i %i/%i/%i %i/%i/%i", &v[0], &vt[0], &vn[0], &v[1], &vt[1], &vn[1], &v[2], &vt[2], &vn[2]); - vertexIndices.push_back(v[0]); - vertexIndices.push_back(v[1]); - vertexIndices.push_back(v[2]); - - uvIndices.push_back(vt[0]); - uvIndices.push_back(vt[1]); - uvIndices.push_back(vt[2]); - - normalIndices.push_back(vn[0]); - normalIndices.push_back(vn[1]); - normalIndices.push_back(vn[2]); - } - } - - file.close(); - - for (unsigned int i = 0; i < vertexIndices.size(); i++) { - outVertices.push_back(tempVertices[vertexIndices[i] - 1]); - } - - for (unsigned int i = 0; i < uvIndices.size(); i++) { - outUVs.push_back(tempUvs[uvIndices[i] - 1]); - } - - for (unsigned int i = 0; i < normalIndices.size(); i++) { - outNormals.push_back(tempNormals[normalIndices[i] - 1]); - } - - return true; -} \ No newline at end of file diff --git a/LoadOBJ.h b/LoadOBJ.h deleted file mode 100644 index 7b4aeb8..0000000 --- a/LoadOBJ.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include -#include -#include - -bool loadOBJ(const std::string path, std::vector& out_vertices, std::vector& out_uvs, std::vector& out_normals); // \ No newline at end of file diff --git a/Main.cpp b/Main.cpp deleted file mode 100644 index 24aa668..0000000 --- a/Main.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#define GLM_FORCE_RADIANS -#define GLM_FORCE_SWIZZLE - -#include -#include -#include -#include -#include -#include "Game.h" - - -int main(void) -{ - Game& game = Game::getInstance(); - game.run(); - - return EXIT_SUCCESS; -} \ No newline at end of file diff --git a/ProgrammingGame.filters b/ProgrammingGame.filters deleted file mode 100644 index 5eb84e2..0000000 --- a/ProgrammingGame.filters +++ /dev/null @@ -1,53 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Pliki nagłówkowe - - - Pliki nagłówkowe - - - Pliki nagłówkowe - - - Pliki nagłówkowe - - - Pliki nagłówkowe - - - - - Pliki źródłowe - - - Pliki źródłowe - - - Pliki źródłowe - - - - - Pliki zasobów - - - Pliki zasobów - - - \ No newline at end of file diff --git a/ProgrammingGame.sln b/ProgrammingGame.sln deleted file mode 100644 index 8aa124b..0000000 --- a/ProgrammingGame.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29728.190 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProgrammingGame", "ProgrammingGame.vcxproj", "{7288C82C-3F3E-4501-8878-A310FCA284FE}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7288C82C-3F3E-4501-8878-A310FCA284FE}.Debug|x64.ActiveCfg = Debug|x64 - {7288C82C-3F3E-4501-8878-A310FCA284FE}.Debug|x64.Build.0 = Debug|x64 - {7288C82C-3F3E-4501-8878-A310FCA284FE}.Debug|x86.ActiveCfg = Debug|Win32 - {7288C82C-3F3E-4501-8878-A310FCA284FE}.Debug|x86.Build.0 = Debug|Win32 - {7288C82C-3F3E-4501-8878-A310FCA284FE}.Release|x64.ActiveCfg = Release|x64 - {7288C82C-3F3E-4501-8878-A310FCA284FE}.Release|x64.Build.0 = Release|x64 - {7288C82C-3F3E-4501-8878-A310FCA284FE}.Release|x86.ActiveCfg = Release|Win32 - {7288C82C-3F3E-4501-8878-A310FCA284FE}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B1F1DB69-65FD-4B28-A71D-12DE03393EB1} - EndGlobalSection -EndGlobal diff --git a/ProgrammingGame.vcxproj b/ProgrammingGame.vcxproj deleted file mode 100644 index 5155fe4..0000000 --- a/ProgrammingGame.vcxproj +++ /dev/null @@ -1,196 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 16.0 - {7288C82C-3F3E-4501-8878-A310FCA284FE} - Win32Proj - plszkielet08win - 10.0 - ProgrammingGame - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - glew\include;glfw\include;$(SolutionDir);%(AdditionalIncludeDirectories) - stdcpp20 - - - Console - true - glew\lib;glfw\lib;%(AdditionalLibraryDirectories) - glew32.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies) - MSVCRT;LIBCMT;%(IgnoreSpecificDefaultLibraries) - - - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - stdcpplatest - - - Console - true - - - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - .;glew\include;glfw\include;%(AdditionalIncludeDirectories) - - - Console - true - true - true - glew32.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies) - %(IgnoreSpecificDefaultLibraries) - glew\lib;glfw\lib;%(AdditionalLibraryDirectories) - - - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - \ No newline at end of file diff --git a/ShaderProgram.cpp b/ShaderProgram.cpp deleted file mode 100644 index 7eb1586..0000000 --- a/ShaderProgram.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* -Niniejszy program jest wolnym oprogramowaniem; możesz go -rozprowadzać dalej i / lub modyfikować na warunkach Powszechnej -Licencji Publicznej GNU, wydanej przez Fundację Wolnego -Oprogramowania - według wersji 2 tej Licencji lub(według twojego -wyboru) którejś z późniejszych wersji. - -Niniejszy program rozpowszechniany jest z nadzieją, iż będzie on -użyteczny - jednak BEZ JAKIEJKOLWIEK GWARANCJI, nawet domyślnej -gwarancji PRZYDATNOŚCI HANDLOWEJ albo PRZYDATNOŚCI DO OKREŚLONYCH -ZASTOSOWAŃ.W celu uzyskania bliższych informacji sięgnij do -Powszechnej Licencji Publicznej GNU. - -Z pewnością wraz z niniejszym programem otrzymałeś też egzemplarz -Powszechnej Licencji Publicznej GNU(GNU General Public License); -jeśli nie - napisz do Free Software Foundation, Inc., 59 Temple -Place, Fifth Floor, Boston, MA 02110 - 1301 USA -*/ - -#include "ShaderProgram.h" - - - -//Procedura wczytuje plik do tablicy znaków. -char* ShaderProgram::readFile(const char* fileName) { - int filesize; - FILE *plik; - char* result; - - #pragma warning(suppress : 4996) //Wyłączenie błędu w Visual Studio wynikające z nietrzymania się standardów przez Microsoft. - plik=fopen(fileName,"rb"); - if (plik != NULL) { - fseek(plik, 0, SEEK_END); - filesize = ftell(plik); - fseek(plik, 0, SEEK_SET); - result = new char[filesize + 1]; - #pragma warning(suppress : 6386) //Wyłączenie błędu w Visual Studio wynikającego z błędnej analizy statycznej kodu. - int readsize=fread(result, 1, filesize, plik); - result[filesize] = 0; - fclose(plik); - - return result; - } - - return NULL; - -} - -//Metoda wczytuje i kompiluje shader, a następnie zwraca jego uchwyt -GLuint ShaderProgram::loadShader(GLenum shaderType,const char* fileName) { - //Wygeneruj uchwyt na shader - GLuint shader=glCreateShader(shaderType);//shaderType to GL_VERTEX_SHADER, GL_GEOMETRY_SHADER lub GL_FRAGMENT_SHADER - //Wczytaj plik ze źródłem shadera do tablicy znaków - const GLchar* shaderSource=readFile(fileName); - //Powiąż źródło z uchwytem shadera - glShaderSource(shader,1,&shaderSource,NULL); - //Skompiluj źródło - glCompileShader(shader); - //Usuń źródło shadera z pamięci (nie będzie już potrzebne) - delete []shaderSource; - - //Pobierz log błędów kompilacji i wyświetl - int infologLength = 0; - int charsWritten = 0; - char *infoLog; - - glGetShaderiv(shader, GL_INFO_LOG_LENGTH,&infologLength); - - if (infologLength > 1) { - infoLog = new char[infologLength]; - glGetShaderInfoLog(shader, infologLength, &charsWritten, infoLog); - printf("%s\n",infoLog); - delete []infoLog; - } - - //Zwróć uchwyt wygenerowanego shadera - return shader; -} - -ShaderProgram::ShaderProgram(const char* vertexShaderFile,const char* geometryShaderFile,const char* fragmentShaderFile) { - //Wczytaj vertex shader - printf("Loading vertex shader...\n"); - vertexShader=loadShader(GL_VERTEX_SHADER,vertexShaderFile); - - //Wczytaj geometry shader - if (geometryShaderFile!=NULL) { - printf("Loading geometry shader...\n"); - geometryShader=loadShader(GL_GEOMETRY_SHADER,geometryShaderFile); - } else { - geometryShader=0; - } - - //Wczytaj fragment shader - printf("Loading fragment shader...\n"); - fragmentShader=loadShader(GL_FRAGMENT_SHADER,fragmentShaderFile); - - //Wygeneruj uchwyt programu cieniującego - shaderProgram=glCreateProgram(); - - //Podłącz do niego shadery i zlinkuj program - glAttachShader(shaderProgram,vertexShader); - glAttachShader(shaderProgram,fragmentShader); - if (geometryShaderFile!=NULL) glAttachShader(shaderProgram,geometryShader); - glLinkProgram(shaderProgram); - - //Pobierz log błędów linkowania i wyświetl - int infologLength = 0; - int charsWritten = 0; - char *infoLog; - - glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH,&infologLength); - - if (infologLength > 1) - { - infoLog = new char[infologLength]; - glGetProgramInfoLog(shaderProgram, infologLength, &charsWritten, infoLog); - printf("%s\n",infoLog); - delete []infoLog; - } - - printf("Shader program created \n"); -} - -ShaderProgram::~ShaderProgram() { - //Odłącz shadery od programu - glDetachShader(shaderProgram, vertexShader); - if (geometryShader!=0) glDetachShader(shaderProgram, geometryShader); - glDetachShader(shaderProgram, fragmentShader); - - //Wykasuj shadery - glDeleteShader(vertexShader); - if (geometryShader!=0) glDeleteShader(geometryShader); - glDeleteShader(fragmentShader); - - //Wykasuj program - glDeleteProgram(shaderProgram); -} - - -//Włącz używanie programu cieniującego reprezentowanego przez aktualny obiekt -void ShaderProgram::use() { - glUseProgram(shaderProgram); -} - -//Pobierz numer slotu odpowiadającego zmiennej jednorodnej o nazwie variableName -GLuint ShaderProgram::u(const char* variableName) { - return glGetUniformLocation(shaderProgram,variableName); -} - -//Pobierz numer slotu odpowiadającego atrybutowi o nazwie variableName -GLuint ShaderProgram::a(const char* variableName) { - return glGetAttribLocation(shaderProgram,variableName); -} diff --git a/ShaderProgram.h b/ShaderProgram.h deleted file mode 100644 index 6663bfa..0000000 --- a/ShaderProgram.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -Niniejszy program jest wolnym oprogramowaniem; możesz go -rozprowadzać dalej i / lub modyfikować na warunkach Powszechnej -Licencji Publicznej GNU, wydanej przez Fundację Wolnego -Oprogramowania - według wersji 2 tej Licencji lub(według twojego -wyboru) którejś z późniejszych wersji. - -Niniejszy program rozpowszechniany jest z nadzieją, iż będzie on -użyteczny - jednak BEZ JAKIEJKOLWIEK GWARANCJI, nawet domyślnej -gwarancji PRZYDATNOśCI HANDLOWEJ albo PRZYDATNOśCI DO OKREśLONYCH -ZASTOSOWAń.W celu uzyskania bliższych informacji sięgnij do -Powszechnej Licencji Publicznej GNU. - -Z pewnością wraz z niniejszym programem otrzymałeś też egzemplarz -Powszechnej Licencji Publicznej GNU(GNU General Public License); -jeśli nie - napisz do Free Software Foundation, Inc., 59 Temple -Place, Fifth Floor, Boston, MA 02110 - 1301 USA -*/ - - -#ifndef SHADERPROGRAM_H -#define SHADERPROGRAM_H - - -#include -#include "stdio.h" - - - -class ShaderProgram { -private: - GLuint shaderProgram; //Uchwyt reprezentujący program cieniujacy - GLuint vertexShader; //Uchwyt reprezentujący vertex shader - GLuint geometryShader; //Uchwyt reprezentujący geometry shader - GLuint fragmentShader; //Uchwyt reprezentujący fragment shader - char* readFile(const char* fileName); //metoda wczytująca plik tekstowy do tablicy znaków - GLuint loadShader(GLenum shaderType,const char* fileName); //Metoda wczytuje i kompiluje shader, a następnie zwraca jego uchwyt -public: - ShaderProgram(const char* vertexShaderFile,const char* geometryShaderFile,const char* fragmentShaderFile); - ~ShaderProgram(); - void use(); //Włącza wykorzystywanie programu cieniującego - GLuint u(const char* variableName); //Pobiera numer slotu związanego z daną zmienną jednorodną - GLuint a(const char* variableName); //Pobiera numer slotu związanego z danym atrybutem -}; - - - - -#endif diff --git a/TextArea.cpp b/TextArea.cpp deleted file mode 100644 index 144a1a3..0000000 --- a/TextArea.cpp +++ /dev/null @@ -1,270 +0,0 @@ -#include -#include -#include - -#include -#include "TextArea.h" - -TextArea::TextArea(std::string initialText) { - paste(initialText); -} - -void TextArea::moveCursorUp(bool select) { - updateSelection(select); - - if (cursor.row > 0) { - --cursor.row; - } else { - cursor.col = 0; - } -} - -void TextArea::moveCursorDown(bool select) { - updateSelection(select); - - if (cursor.row + 1 < lines.size()) { - ++cursor.row; - } else { - cursor.col = lines[cursor.row].length(); - } -} - -void TextArea::moveCursorLeft(bool select) { - updateSelection(select); - - clampCursorToLine(); - if (cursor.col > 0) { - --cursor.col; - } else if (cursor.row > 0) { - --cursor.row; - cursor.col = lines[cursor.row].length(); - } -} - -void TextArea::moveCursorRight(bool select) { - if (isSelectionMode && !select) { - cursor = std::max(cursor, selectionStartCharPos); - isSelectionMode = false; - return; - } - - updateSelection(select); - - if (cursor.col < lines[cursor.row].length()) { - ++cursor.col; - } else if (cursor.row + 1 < lines.size()) { - ++cursor.row; - cursor.col = 0; - } -} - -void TextArea::moveCursorTo(CharPos to, bool select) { - updateSelection(select); - - if (to.row >= lines.size()) { - cursor.row = lines.size() - 1; - cursor.col = lines[cursor.row].length(); - } else { - cursor = to; - clampCursorToLine(); - } -} - - -void TextArea::end(bool select) { - updateSelection(select); - - cursor.col = lines[cursor.row].length(); -} - -void TextArea::home(bool select) { - updateSelection(select); - - cursor.col = 0; -} - -void TextArea::type(char c) { - if (isSelectionMode) { - deleteSelection(); - } - - insertChar(c); -} - -void TextArea::paste(std::string text) { - if (isSelectionMode) { - deleteSelection(); - } - - for (const char& c : text) { - insertChar(c); - } -} - -void TextArea::backspace() { - if (isSelectionMode) { - deleteSelection(); - return; - } - - clampCursorToLine(); - if (cursor.col > 0) { - lines[cursor.row].erase(cursor.col - 1, 1); - --cursor.col; - } else if (cursor.row > 0) { - --cursor.row; - cursor.col = lines[cursor.row].length(); - lines[cursor.row] += lines[cursor.row + 1]; - lines.erase(lines.begin() + cursor.row + 1); - } -} - -void TextArea::del() { - if (isSelectionMode) { - deleteSelection(); - return; - } - - clampCursorToLine(); - if (cursor.col < lines[cursor.row].length()) { - lines[cursor.row].erase(cursor.col, 1); - } else if (cursor.row + 1 < lines.size()) { - lines[cursor.row] += lines[cursor.row + 1]; - lines.erase(lines.begin() + cursor.row + 1); - } -} - -void TextArea::selectAll() { - cursor = { 0, 0 }; - selectionStartCharPos = { lines[lines.size() - 1].length(), lines.size() - 1 }; - isSelectionMode = true; -} - -char TextArea::getChar(CharPos at) const { - if (at.row < lines.size() && at.col < lines[at.row].length() ) { - return lines[at.row][at.col]; - } - return 0; -} - -bool TextArea::isCharSelected(CharPos at) const { - if (!isSelectionMode) return false; - - bool between = selectionStartCharPos <= at && at <= cursor || cursor <= at && at < selectionStartCharPos; - bool filled = at.col <= getLine(at.row).length(); - - return between && filled; -} - -std::string TextArea::getLine(size_t n) const { - if (n < lines.size()) { - return lines[n]; - } - return ""; -} - -std::string TextArea::getFull() const { - std::string rv = ""; - for (const std::string& line : lines) { - rv += line + '\n'; - } - - if (!rv.empty()) { - rv.pop_back(); - } - - return rv; -} - -std::string TextArea::getSelected() const { - if (!isSelectionMode) return ""; - - CharPos start = std::min(cursor, selectionStartCharPos); - CharPos end = std::max(cursor, selectionStartCharPos); - - if (start.row == end.row) { - return lines[start.row].substr(start.col, end.col - start.col); - } else { - std::string rv = ""; - rv += lines[start.row].substr(start.col) + '\n'; - for (size_t i = start.row + 1; i < end.row; ++i) { - rv += lines[i] + '\n'; - } - rv += lines[end.row].substr(0, end.col); - return rv; - } -} - -size_t TextArea::lineCount() const { - return lines.size(); -} - -CharPos TextArea::getRealCursor() const { - return getCharPosClamped(cursor); -} - -CharPos TextArea::getVirtualCursor() const { - return cursor; -} - -void TextArea::insertChar(char c) { - if (c == '\r') return; - if (c == '\0') return; - - clampCursorToLine(); - - if (c == '\n') { - std::string new_line = lines[cursor.row].substr(cursor.col); - lines[cursor.row].erase(cursor.col); - lines.insert(lines.begin() + cursor.row + 1, new_line); - ++cursor.row; - cursor.col = 0; - } else if (c == '\t') { - int spaces = tabSize - (cursor.col % tabSize); - for (int i = 0; i < spaces; ++i) { - insertChar(' '); - } - } else { - lines[cursor.row].insert(lines[cursor.row].begin() + cursor.col, c); - ++cursor.col; - } -} - -void TextArea::clampCursorToLine() { - cursor = getCharPosClamped(cursor); -} - -CharPos TextArea::getCharPosClamped(CharPos pos) const { - pos.col = std::min(pos.col, lines[pos.row].length()); // TODO: handle invalid pos - return pos; -} - -void TextArea::updateSelection(bool select) { - if (select) { - if (!isSelectionMode) { - isSelectionMode = true; - selectionStartCharPos = getCharPosClamped(cursor); - } - } else { - isSelectionMode = false; - } -} - -void TextArea::deleteSelection() { - clampCursorToLine(); - - CharPos start = std::min(cursor, selectionStartCharPos); - CharPos end = std::max(cursor, selectionStartCharPos); - - if (start.row == end.row) { - lines[start.row].erase(start.col, end.col - start.col); - } else { - lines[start.row].erase(start.col); - lines[start.row] += lines[end.row].substr(end.col); - lines[end.row].erase(0, end.col); - lines.erase(lines.begin() + start.row + 1, lines.begin() + end.row + 1); - } - - cursor = start; - isSelectionMode = false; -} diff --git a/TextArea.h b/TextArea.h deleted file mode 100644 index f0576d1..0000000 --- a/TextArea.h +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include -#include - -union CharPos { - struct { size_t col, row; }; - struct { size_t x, y; }; - - bool operator==(const CharPos& other) const { return col == other.col && row == other.row; } - bool operator!=(const CharPos& other) const { return !(*this == other); } - bool operator< (const CharPos& other) const { return (row < other.row) || (row == other.row && col < other.col); } - bool operator> (const CharPos& other) const { return other < *this; } - bool operator<=(const CharPos& other) const { return !(*this > other); } - bool operator>=(const CharPos& other) const { return !(*this < other); } - - template - T convert() const { - return T(x, y); - } -}; - - -class TextArea { -public: - TextArea() = default; - TextArea(std::string initial_text); - - void moveCursorUp(bool select = false); - void moveCursorDown(bool select = false); - void moveCursorLeft(bool select = false); - void moveCursorRight(bool select = false); - void moveCursorTo(CharPos to, bool select = false); - - void end(bool select = false); - void home(bool select = false); - - void type(char c); - void paste(std::string text); - - void backspace(); - void del(); - - void selectAll(); - - char getChar(CharPos at) const; - bool isCharSelected(CharPos at) const; - - std::string getLine(size_t n) const; - std::string getFull() const; - std::string getSelected() const; - - size_t lineCount() const; - - CharPos getRealCursor() const; - CharPos getVirtualCursor() const; - -private: - void insertChar(char c); - - void clampCursorToLine(); - CharPos getCharPosClamped(CharPos pos) const; - - void updateSelection(bool select); - void deleteSelection(); - - std::vector lines{ "" }; - CharPos cursor{ 0, 0 }; - - bool isSelectionMode = false; - CharPos selectionStartCharPos = cursor; - - const int tabSize = 4; -}; diff --git a/Timer.cpp b/Timer.cpp deleted file mode 100644 index 2b0dc77..0000000 --- a/Timer.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include ; -#include "Timer.h" - - -Timer::Timer(double time) : duration(time), time(time) {} - -void Timer::update(double delta) { - time -= delta; -} - -double Timer::remaining() { - return std::max(0.0, time); -} - -bool Timer::done() { - return time <= 0; -} - -void Timer::restart() { - time = duration; -} diff --git a/Timer.h b/Timer.h deleted file mode 100644 index 85f56eb..0000000 --- a/Timer.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -class Timer { -public: - Timer(double time); - - void update(double delta); - double remaining(); - bool done(); - void restart(); - -private: - double duration; - double time; -}; diff --git a/Utils.cpp b/Utils.cpp deleted file mode 100644 index 3c93d74..0000000 --- a/Utils.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "Utils.h" -#include - -#include "ShaderProgram.h" - - -GLuint loadTexture(const char* filename) { - GLuint tex; - glActiveTexture(GL_TEXTURE0); - - std::vector image; - unsigned width, height; - - unsigned error = lodepng::decode(image, width, height, filename); // TODO: handle error - - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)image.data()); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - return tex; -} - -GLuint createColorBuffer(GLFWwindow* window) { - - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - unsigned int colorBuffer; - glGenTextures(1, &colorBuffer); - glBindTexture(GL_TEXTURE_2D, colorBuffer); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); - - return colorBuffer; -} - -GLuint createDepthBuffer(GLFWwindow* window) { - - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - unsigned int depthBuffer; - glGenRenderbuffers(1, &depthBuffer); - glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); - - return depthBuffer; -} - -GLuint createFrameBuffer(GLuint color_buffer, GLuint depth_buffer) { - GLuint frameBuffer; - - glGenFramebuffers(1, &frameBuffer); - glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); - - glFramebufferTexture2D( - GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, color_buffer, 0); - - glFramebufferRenderbuffer( - GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, - GL_RENDERBUFFER, depth_buffer); - - return frameBuffer; -} - -void bindTexture(ShaderProgram* shader, GLuint textureId, unsigned textureIndex) { - glActiveTexture(GL_TEXTURE0 + textureIndex); - glBindTexture(GL_TEXTURE_2D, textureId); - std::string address = "textures[" + std::to_string(textureIndex) + "]"; - glUniform1i(shader->u(address.c_str()), textureIndex); - -} - -void bindTilemap(ShaderProgram* shader, GLuint textureId, unsigned textureIndex, glm::ivec2 tilemapSize) { - bindTexture(shader, textureId, textureIndex); - std::string tilemapSizeAddress = "tilemapSize[" + std::to_string(textureIndex) + "]"; - glUniform2i(shader->u(tilemapSizeAddress.c_str()), tilemapSize.x, tilemapSize.y); -} \ No newline at end of file diff --git a/Utils.h b/Utils.h deleted file mode 100644 index 4dbeb0e..0000000 --- a/Utils.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - - -#include -#include -#include - -#include "ShaderProgram.h" - -#include -#include - - -GLuint loadTexture(const char* filename); - -GLuint createColorBuffer(GLFWwindow* window); - -GLuint createDepthBuffer(GLFWwindow* window); - -GLuint createFrameBuffer(GLuint color_buffer, GLuint depth_buffer); - -void bindTexture(ShaderProgram* shader, GLuint textureId, unsigned textureIndex); - -void bindTilemap(ShaderProgram* shader, GLuint textureId, unsigned textureIndex, glm::ivec2 tilemapSize); \ No newline at end of file diff --git a/interpreter/tests/test_interpreter.h b/interpreter/tests/test_interpreter.h index 53845cf..79b2f30 100644 --- a/interpreter/tests/test_interpreter.h +++ b/interpreter/tests/test_interpreter.h @@ -1,18 +1,16 @@ #pragma once - -#include "tests/test_macros.h" #include "../CodeInterpreter.h" +#include "tests/test_macros.h" namespace TestInterpreter { +TEST_CASE("[Interpreter] 2+2") +{ + CodeInterpreter interpreter{}; + interpreter.interpret("START auto val1 = 2 + 2 END."); -TEST_CASE("[Interpreter] 2+2") { - CodeInterpreter interpreter{}; - interpreter.interpret("START auto val1 = 2 + 2 END."); - - CHECK(interpreter.getVariable("val1") == "4"); + CHECK(interpreter.getVariable("val1") == "4"); } - -} +} // namespace TestInterpreter diff --git a/shaders/2d_frag.glsl b/shaders/2d_frag.glsl deleted file mode 100644 index c9a7c6f..0000000 --- a/shaders/2d_frag.glsl +++ /dev/null @@ -1,46 +0,0 @@ -#version 420 - -#define TEX_NUM 32 // this is the max number of guaranteed textures - -uniform sampler2D textures[TEX_NUM]; -uniform ivec2 tilemapSize[TEX_NUM]; - -in vec2 f_texPos; -flat in int f_tex; -flat in int f_inv; // treated as bool - -out vec4 pixelColor; - - -void main(void) { - - vec3 color; - - // g_tex contains index of texture and index of tile within the texture - // TODO: change to two separate input arguments - int textureIndex = f_tex % TEX_NUM; - int tileIndex = f_tex / TEX_NUM; - - // get (x, y) tile position in tilemap - vec2 tilePos = vec2(tileIndex % tilemapSize[textureIndex].x, tileIndex / tilemapSize[textureIndex].x); - - // get (x, y) position in tilemap - vec2 texPos = (f_texPos + tilePos) / tilemapSize[textureIndex]; - - color = texture(textures[textureIndex], texPos).xyz; - - // invert color - if (f_inv > 0) { - color = 1 - color; - } - - // change colors - // TODO: make customizable - if (color.r == 0) { - color = vec3(0.13f); - } else { - color = vec3(0.67f); - } - - pixelColor = vec4(color, 1.0); -} diff --git a/shaders/2d_geom.glsl b/shaders/2d_geom.glsl deleted file mode 100644 index f67d3b6..0000000 --- a/shaders/2d_geom.glsl +++ /dev/null @@ -1,43 +0,0 @@ -#version 420 - -layout (points) in; -layout (triangle_strip, max_vertices = 4) out; - -in vec2 g_dim[]; -in int g_tex[]; -in int g_inv[]; - -out vec2 f_texPos; -flat out int f_tex; -flat out int f_inv; // treated as bool - - -void main(void) { - - vec4 pos = gl_in[0].gl_Position; - vec2 dim = g_dim[0]; - - f_tex = g_tex[0]; - f_inv = g_inv[0]; - - // draw 4 corners of 2d tile - - gl_Position = pos + vec4(0, 0, 0, 0); - f_texPos = vec2(0, 0); - EmitVertex(); - - gl_Position = pos + vec4(dim.x, 0, 0, 0); - f_texPos = vec2(1, 0); - EmitVertex(); - - gl_Position = pos + vec4(0, -dim.y, 0, 0); - f_texPos = vec2(0, 1); - EmitVertex(); - - gl_Position = pos + vec4(dim.x, -dim.y, 0, 0); - f_texPos = vec2(1, 1); - EmitVertex(); - - EndPrimitive(); - -} \ No newline at end of file diff --git a/shaders/2d_vec.glsl b/shaders/2d_vec.glsl deleted file mode 100644 index 0e9871c..0000000 --- a/shaders/2d_vec.glsl +++ /dev/null @@ -1,49 +0,0 @@ -#version 420 - -layout (location = 0) in vec2 pos; -layout (location = 1) in vec2 dim; -layout (location = 2) in int tex; -layout (location = 3) in int inv; // treated as bool - -uniform vec2 window; -uniform float layer; - -out vec2 g_dim; -out int g_tex; -out int g_inv; // treated as bool - -vec2 map(vec2 value, vec2 min1, vec2 max1, vec2 min2, vec2 max2) { - return min2 + (value - min1) * (max2 - min2) / (max1 - min1); -} - -vec2 map_from_pixel_to_screen(vec2 value) { - - //////////////////////////////////////// - // (0, 0) (window.x, 0) // - // // - // Pixel Space // - // // - // (0, window.y) (window.x, window.y) // - //////////////////////////////////////// - - //////////////////////////////////////// - // (-1, 1) (1, 1) // - // // - // Screen Space // - // // - // (-1, -1) (1, -1) // - //////////////////////////////////////// - - return map(value, vec2(0, 0), window, vec2(-1, 1), vec2(1, -1)); -} - -void main(void) { - - vec2 screenPos = map_from_pixel_to_screen(pos); - - gl_Position = vec4(screenPos, layer, 1); - - g_dim = dim / window * 2; - g_tex = tex; - g_inv = inv; -} diff --git a/shaders/post_frag.glsl b/shaders/post_frag.glsl deleted file mode 100644 index 78f126d..0000000 --- a/shaders/post_frag.glsl +++ /dev/null @@ -1,58 +0,0 @@ -#version 330 core - -in vec2 f_texPos; - -uniform sampler2D colorBuffer; - -out vec4 pixelColor; - -// TODO: rewrite/change -vec2 curveRemapUV(vec2 uv) { - - vec2 curvature = vec2(4.0); - - uv = uv * 2.0-1.0; - vec2 offset = abs(uv.yx) / vec2(curvature.x, curvature.y); - uv = uv + uv * offset * offset; - uv = uv * 0.5 + 0.5; - return uv; -} - -// TODO: rewrite/change -float vignetteMod(inout vec3 color, vec2 uv) { - - float vignette = uv.x * uv.y * (1.0 - uv.x) * (1.0 - uv.y); - vignette = clamp(pow(32.0 * vignette, 0.3), 0.0, 1.0); - return vignette; -} - -// TODO: rewrite/change -float scanlineMod(inout vec3 color, vec2 uv) { - - float scanline = clamp(0.95 + 0.05 * cos(3.14 * 240.0), 0.0, 1.0); - float grille = 0.75 + 0.25 * clamp(1.5 * cos(3.14 * uv.x * 800 * 0.8), 0.0, 1.0); - return scanline * grille * 1.5; -} - -bool isTextureInBounds(vec2 pos) { - return pos.x >= 0.0 && pos.x <= 1.0 && pos.y >= 0.0 && pos.y <= 1.0; -} - -void main() { - - vec2 remappedUV = curveRemapUV(f_texPos); - vec4 pixel = texture(colorBuffer, remappedUV); - - pixel.xyz *= vignetteMod(pixel.xyz, remappedUV); - pixel.xyz *= scanlineMod(pixel.xyz, remappedUV); - - if (!isTextureInBounds(remappedUV)) { - pixel = vec4(0.0); - } - - if (pixel.a == 0) { - discard; - } - - pixelColor = vec4(pixel.xyz, 1.0); -} \ No newline at end of file diff --git a/shaders/post_vec.glsl b/shaders/post_vec.glsl deleted file mode 100644 index e173362..0000000 --- a/shaders/post_vec.glsl +++ /dev/null @@ -1,20 +0,0 @@ -#version 330 core - -out vec2 f_texPos; - -vec2 trianglePoints[6] = vec2[6]( - vec2(1.0, 1.0), - vec2(-1.0, 1.0), - vec2(-1.0, -1.0), - - vec2(-1.0, -1.0), - vec2(1.0, -1.0), - vec2(1.0, 1.0) -); - -void main() { - vec2 vertexPos = trianglePoints[gl_VertexID]; - - gl_Position = vec4(vertexPos, 0.0, 1.0); - f_texPos = 0.5 * (vertexPos + vec2(1.0, 1.0)); -} \ No newline at end of file diff --git a/shaders/tex_quad_frag.glsl b/shaders/tex_quad_frag.glsl deleted file mode 100644 index e69de29..0000000 diff --git a/shaders/tex_quad_vec.glsl b/shaders/tex_quad_vec.glsl deleted file mode 100644 index e69de29..0000000