diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 0cbfcf6..228bc3e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,7 +4,8 @@ "name": "linux-gcc-x64", "includePath": [ "${workspaceFolder}/**", - "${workspaceFolder}/dependencies/include" + "${workspaceFolder}/dependencies/include", + "${workspaceFolder}/dependencies/include/glad/**" ], "compilerPath": "/usr/bin/gcc", "cStandard": "${default}", diff --git a/Engine/engine/beforeRender.cpp b/Engine/engine/beforeRender.cpp index ce590e8..7f08e11 100644 --- a/Engine/engine/beforeRender.cpp +++ b/Engine/engine/beforeRender.cpp @@ -1,15 +1,15 @@ +// "Copyright [2023] " #ifndef BEFORE_RENDER_CPP #define BEFORE_RENDER_CPP +#include "Engine/engine/beforeRender.hpp" #include #include #include -#include "beforeRender.hpp" -#include "constants.hpp" -#include "misc.hpp" +#include "./constants.hpp" +#include "./misc.hpp" -void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion) -{ +void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion) { // first argument tells us what option to configure // second is to what we set the value of this option // see: https://www.glfw.org/docs/latest/window.html#window_hints @@ -17,7 +17,8 @@ void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GLFWMinorVersion); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // we set GLFW to 3.3 CORE -// core profile gives us access to smaller subset of OGL without backwards compatible features +// core profile gives us access to smaller subset of +// OGL without backwards compatible features // if we are on Mac OS X we need this for our code to work #ifdef __APPLE__ @@ -25,27 +26,28 @@ void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion) #endif } -void instantiateGLFWwindow() -{ +void instantiateGLFWwindow() { // Initialize GLFW glfwInit(); configureGLFW(constants::GLFW_MAJOR_VERSION, constants::GLFW_MINOR_VERSION); } -GLFWwindow *createWindowObject() -{ +GLFWwindow *createWindowObject() { // First two arguments are width and height // Third is the name of the window // We ignore last two - GLFWwindow *window = glfwCreateWindow(constants::MAIN_WINDOW_WIDTH, constants::MAIN_WINDOW_HEIGHT, constants::MAIN_WINDOW_NAME, nullptr, nullptr); + GLFWwindow *window = glfwCreateWindow( + constants::MAIN_WINDOW_WIDTH, + constants::MAIN_WINDOW_HEIGHT, + constants::MAIN_WINDOW_NAME, + nullptr, + nullptr); return window; } -int initializeGLAD() -{ +int initializeGLAD() { // we load address of OGL OS-specific function pointers - if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) - { + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { print("Failed to initialize GLAD"); return -1; } @@ -53,33 +55,36 @@ int initializeGLAD() } // resizes viewport when user resizes window -void framebuffer_size_callback(GLFWwindow *window, const int width, const int height) -{ +void framebuffer_size_callback(GLFWwindow *window, + const int width, + const int height) { glViewport(0, 0, width, height); } -void viewPort(GLFWwindow *window) -{ +void viewPort(GLFWwindow *window) { // We tell OGL size of rendering window // First two define left corner of window // 3th and 4th width and height of rendering window - // we could set them to be smaller than window dimension, ogl rendering will be then displayed in smaller window - glViewport(0, 0, constants::MAIN_WINDOW_WIDTH, constants::MAIN_WINDOW_HEIGHT); + // we could set them to be smaller than window dimension, + // ogl rendering will be then displayed in smaller window + glViewport(0, + 0, + constants::MAIN_WINDOW_WIDTH, + constants::MAIN_WINDOW_HEIGHT); // processed coordinates are between -1 and 1 so here we map: - // (-1 to 1) to (0, constants::MAIN_WINDOW_WIDTH) and (0, constants::MAIN_WINDOW_HEIGHT) + // (-1 to 1) to (0, constants::MAIN_WINDOW_WIDTH) + // and (0, constants::MAIN_WINDOW_HEIGHT) glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // we call framebuffer_size_callback on every window resize } -GLFWwindow *prepareForRender() -{ +GLFWwindow *prepareForRender() { instantiateGLFWwindow(); GLFWwindow *window = createWindowObject(); // function returns GLFWWindow object - if (window == nullptr) - { + if (window == nullptr) { print("Failed to create GLFW window"); glfwTerminate(); return window; @@ -93,4 +98,4 @@ GLFWwindow *prepareForRender() return window; } -#endif \ No newline at end of file +#endif diff --git a/Engine/engine/beforeRender.hpp b/Engine/engine/beforeRender.hpp index 2a42f84..6f415da 100644 --- a/Engine/engine/beforeRender.hpp +++ b/Engine/engine/beforeRender.hpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef BEFORE_RENDER_HPP #define BEFORE_RENDER_HPP #include diff --git a/Engine/engine/constants.hpp b/Engine/engine/constants.hpp index 8b6f08f..13cc794 100644 --- a/Engine/engine/constants.hpp +++ b/Engine/engine/constants.hpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef CONSTANTS_HPP #define CONSTANTS_HPP #include diff --git a/Engine/engine/cppCheckIgnore.txt b/Engine/engine/cppCheckIgnore.txt new file mode 100644 index 0000000..72be6a9 --- /dev/null +++ b/Engine/engine/cppCheckIgnore.txt @@ -0,0 +1,2 @@ +*:stb_image.h:* +*:stb_images_implementation.cpp:* \ No newline at end of file diff --git a/Engine/engine/draw.cpp b/Engine/engine/draw.cpp index 192e8d9..1bbf8a1 100644 --- a/Engine/engine/draw.cpp +++ b/Engine/engine/draw.cpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef DRAW_CPP #define DRAW_CPP #include @@ -103,34 +104,10 @@ drawFigureReturn drawTriangleClass(const float triangleVertices[], const size_t return newReturn; } -drawFigureReturn drawTriangle(const float triangleVertices[], const size_t triangleVerticesSize, const char* vertexShaderSource, const char* fragmentShaderSource, const bool colorIncluded, const bool textureIncluded) -{ - - const unsigned int shaderProgram = getShaderProgram(vertexShaderSource, fragmentShaderSource); - drawFigureReturn newReturn; - if (shaderProgram == 0) { - newReturn.success = -1; - return newReturn; - } - - const unsigned int vertexBufferObject = copyVerticesMemory(triangleVertices, triangleVerticesSize, GL_ARRAY_BUFFER); - const unsigned int vertexArrayObject = generateBindVAO(); - copyVerticesArray(vertexBufferObject, triangleVertices, triangleVerticesSize, GL_ARRAY_BUFFER); - - // set vertex attribute pointers - configureVertexAttribute(colorIncluded, textureIncluded); - doDrawArrays(shaderProgram, vertexArrayObject, GL_TRIANGLES, 0, triangleVerticesSize); - newReturn.success = 0; - newReturn.VAO = vertexArrayObject; - newReturn.VBO = vertexBufferObject; - newReturn.EBO = 0; - return newReturn; -} - drawFigureReturn drawSquare(const float squareVertices[], const size_t squareVerticesSize, const unsigned int squareIndices[], const size_t squareIndicesSize, const char* vertexShaderSource, const char* fragmentShaderSource, const bool colorIncluded, const bool textureIncluded, const offsetsStruct offsets) { const unsigned int shaderProgram = getShaderProgram(vertexShaderSource, fragmentShaderSource); - drawFigureReturn newReturn; + drawFigureReturn newReturn = drawFigureReturn(); if (shaderProgram == 0) { newReturn.success = -1; return newReturn; @@ -145,27 +122,6 @@ drawFigureReturn drawSquare(const float squareVertices[], const size_t squareVer doDrawElements(shaderProgram, VAO, GL_TRIANGLES, GL_UNSIGNED_INT, squareIndicesSize); newReturn.success = 0; newReturn.VAO = VAO; - newReturn.VBO = 0; - newReturn.EBO = 0; - return newReturn; -} - -drawFigureReturn drawSquareClass(const char* vertexPath, const char* fragmentPath, const bool colorIncluded, const bool textureIncluded, const offsetsStruct offsets) -{ - Shader ourShader(vertexPath, fragmentPath); - ourShader.use(); - const unsigned int vertexBufferObject = copyVerticesMemory(constants::SQUARE_VERTICES, constants::SQUARE_VERTICES_SIZE, GL_ARRAY_BUFFER); - const unsigned int vertexArrayObject = generateBindVAO(); - copyVerticesArray(vertexBufferObject, constants::SQUARE_VERTICES, constants::SQUARE_VERTICES_SIZE, GL_ARRAY_BUFFER); - - // set vertex attribute pointers - configureVertexAttribute(false, false); - doDrawArrays(ourShader.ID, vertexArrayObject, GL_TRIANGLES, 0, constants::SQUARE_VERTICES_SIZE); - drawFigureReturn newReturn; - newReturn.success = 0; - newReturn.VAO = vertexArrayObject; - newReturn.VBO = vertexBufferObject; - newReturn.EBO = 0; return newReturn; } @@ -179,8 +135,8 @@ drawFigureReturn drawDebilMode(const char* vertexPath, const char* fragmentPath, configureVertexAttribute(true, true); - unsigned int texture1 = loadAndCreateTexture("assets/container.png", GL_RGB, true); - unsigned int texture2 = loadAndCreateTexture("assets/awesomeface.png", GL_RGBA, false); + unsigned int texture1 = loadAndCreateTexture("assets/container.png", true); + unsigned int texture2 = loadAndCreateTexture("assets/awesomeface.png", false); ourShader.use(); // don't forget to activate/use the shader before setting uniforms! // either set it manually like so: @@ -243,11 +199,4 @@ void doDrawArrays(const unsigned int shaderProgram, const unsigned int vertexArr glDrawArrays(drawArrayMode, firstIndex, numberOfIndicesToBeRendered); } -int drawTexture() { - // we added new vertex attribute and need to inform opengl that we done so - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float))); - glEnableVertexAttribArray(2); - return -1; -} - #endif \ No newline at end of file diff --git a/Engine/engine/draw.hpp b/Engine/engine/draw.hpp index aa9bd07..8c2a446 100644 --- a/Engine/engine/draw.hpp +++ b/Engine/engine/draw.hpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef DRAW_HPP #define DRAW_HPP #include @@ -11,6 +12,7 @@ struct offsetsStruct { }; struct drawFigureReturn { + drawFigureReturn(): success(-1), VAO(0), VBO(0), EBO(0){ } int success; unsigned int VAO; unsigned int VBO; @@ -19,14 +21,10 @@ struct drawFigureReturn { drawFigureReturn drawFigure(const int whatToDraw); drawFigureReturn drawSquare(const float squareVertices[] = constants::SQUARE_VERTICES, const size_t squareVerticesSize = constants::SQUARE_VERTICES_SIZE, const unsigned int squareIndices[] = constants::SQUARE_INDICES, const size_t squareIndicesSize = constants::SQUARE_INDICES_SIZE, const char* vertexShaderSource = constants::VERTEX_SHADER_SOURCE, const char* fragmentShaderSource = constants::FRAGMENT_SHADER_SOURCE, const bool colorIncluded = false, const bool textureIncluded = false, const offsetsStruct offsets = offsetsStruct()); -drawFigureReturn drawSquareClass(const char* vertexPath, const char* fragmentPath, const bool colorIncluded = false, const bool textureIncluded = false, const offsetsStruct offsets = offsetsStruct()); void doDrawElements(const unsigned int shaderProgram, const unsigned int vertexArrayObject, const GLenum drawArrayMode, const GLenum drawType, const int numberOfElementsToDraw); drawFigureReturn drawTriangleClass(const float triangleVertices[], const size_t triangleVerticesSize, const char* vertexPath, const char* fragmentPath, const bool colorIncluded = false, const bool textureIncluded = false, const offsetsStruct offsets = offsetsStruct()); -drawFigureReturn drawTriangle(const float triangleVertices[], const size_t triangleVerticesSize, const char* vertexShaderSource, const char* fragmentShaderSource, const bool colorIncluded = false, const bool textureIncluded = false); -int drawTexture(); void updateUniformColor(const unsigned int shaderProgram, const GLchar* uniformName); void doDrawArrays(const unsigned int shaderProgram, const unsigned int vertexArrayObject, const GLenum drawArrayMode, const int firstIndex, const unsigned int numberOfIndicesToBeRendered ); -unsigned int drawSquareShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource); drawFigureReturn drawDebilMode(const char* vertexPath, const char* fragmentPath, const float vertices[], const size_t verticesSize, const unsigned int indices[], const size_t indicesSize); #endif \ No newline at end of file diff --git a/Engine/engine/match b/Engine/engine/match index fe38a25..ec7896e 100755 Binary files a/Engine/engine/match and b/Engine/engine/match differ diff --git a/Engine/engine/match.cpp b/Engine/engine/match.cpp index fe912b7..ee6504b 100644 --- a/Engine/engine/match.cpp +++ b/Engine/engine/match.cpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef MAIN_CPP #define MAIN_CPP #include diff --git a/Engine/engine/misc.cpp b/Engine/engine/misc.cpp index e3a8bae..f070bb7 100644 --- a/Engine/engine/misc.cpp +++ b/Engine/engine/misc.cpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef MISC_CPP #define MISC_CPP #include diff --git a/Engine/engine/misc.hpp b/Engine/engine/misc.hpp index 1aeec16..c13a555 100644 --- a/Engine/engine/misc.hpp +++ b/Engine/engine/misc.hpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef MISC_HPP #define MISC_HPP #include diff --git a/Engine/engine/renderLoop.cpp b/Engine/engine/renderLoop.cpp index 18290a1..2fe83eb 100644 --- a/Engine/engine/renderLoop.cpp +++ b/Engine/engine/renderLoop.cpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef RENDER_LOOP_CPP #define RENDER_LOOP_CPP #include diff --git a/Engine/engine/renderLoop.hpp b/Engine/engine/renderLoop.hpp index 3c16f64..24b79f9 100644 --- a/Engine/engine/renderLoop.hpp +++ b/Engine/engine/renderLoop.hpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef RENDER_LOOP_HPP #define RENDER_LOOP_HPP #include diff --git a/Engine/engine/shader.cpp b/Engine/engine/shader.cpp index 34d29e3..7de431b 100644 --- a/Engine/engine/shader.cpp +++ b/Engine/engine/shader.cpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef SHADER_CPP #define SHADER_CPP diff --git a/Engine/engine/shader.hpp b/Engine/engine/shader.hpp index c9a5298..155e245 100644 --- a/Engine/engine/shader.hpp +++ b/Engine/engine/shader.hpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef SHADER_HPP #define SHADER_HPP diff --git a/Engine/engine/shaders.cpp b/Engine/engine/shaders.cpp index c36d6a6..6780e40 100644 --- a/Engine/engine/shaders.cpp +++ b/Engine/engine/shaders.cpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef SHADERS_CPP #define SHADERS_CPP #include diff --git a/Engine/engine/shaders.hpp b/Engine/engine/shaders.hpp index 29b7d46..a783486 100644 --- a/Engine/engine/shaders.hpp +++ b/Engine/engine/shaders.hpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef SHADERS_HPP #define SHADERS_HPP #include diff --git a/Engine/engine/textures.cpp b/Engine/engine/textures.cpp index 8f4f014..274ef7c 100644 --- a/Engine/engine/textures.cpp +++ b/Engine/engine/textures.cpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef TEXTURES_CPP #define TEXTURES_CPP #include @@ -72,14 +73,6 @@ void setTextureFilteringAndMipMap(const GLenum textureTarget, const GLenum filte glTexParameteri(textureTarget, filterType, textureFilteringMethod); } -unsigned char *loadTexture(const char* texturePath, int textureWidth, int textureHeight, int colorChannels) -{ - // first argument is the location of an image - // second and third is its width and height - // fourth is number of color channels - unsigned char *data = stbi_load(texturePath, &textureWidth, &textureHeight, &colorChannels, 0); - return data; -} unsigned int generateAndBindTexture(const GLenum textureTarget, const GLsizei numberOfTextures ) { unsigned int texture; @@ -91,10 +84,10 @@ unsigned int generateAndBindTexture(const GLenum textureTarget, const GLsizei nu return texture; } -unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, GLenum rgbFormat, bool flipImage) { +unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, bool flipImage) { int textureWidth, textureHeight, colorChannels; stbi_set_flip_vertically_on_load(flipImage); - unsigned char *data = stbi_load(texturePath, &textureWidth, &textureHeight, &colorChannels, 0); + unsigned char *data = stbi_load(texturePath, &textureWidth, &textureHeight, &colorChannels, STBI_rgb_alpha); if(data) { std::cout << "textureWidth " << textureWidth << " textureHeight " << textureHeight << " colorChannels " << colorChannels << std::endl; // generate texture @@ -107,7 +100,8 @@ unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePa 7th and 8th are the format and datatype of source image, we store the image data as chars (bytes) so we pass that 9th last argument is actual data of the texture */ - glTexImage2D(GL_TEXTURE_2D, 0, rgbFormat, textureWidth, textureHeight, 0, rgbFormat, GL_UNSIGNED_BYTE, data); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); // after generating texture, lets free the memory from image stbi_image_free(data); @@ -121,7 +115,7 @@ unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePa } // const char* texturePath, int textureWidth, int textureHeight, int colorChannels, const GLenum textureTarget, const GLint sCoordinateOption, const GLint tCoordinateOption, const GLint rCoordinateOption, const float* borderColor -unsigned int loadAndCreateTexture(const char* texturePath, GLenum RGBFormat, bool flipImage) { +unsigned int loadAndCreateTexture(const char* texturePath, bool flipImage) { // load and create a texture // ------------------------- unsigned int texture = generateAndBindTexture(GL_TEXTURE_2D, 1); @@ -131,7 +125,7 @@ unsigned int loadAndCreateTexture(const char* texturePath, GLenum RGBFormat, boo glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // load image, create texture and generate mipmaps - texture = loadAndBindTextureFile(texture, texturePath, RGBFormat, flipImage); + texture = loadAndBindTextureFile(texture, texturePath, flipImage); return texture; } diff --git a/Engine/engine/textures.hpp b/Engine/engine/textures.hpp index 0ba723c..2c6339e 100644 --- a/Engine/engine/textures.hpp +++ b/Engine/engine/textures.hpp @@ -1,3 +1,4 @@ +// "Copyright [2023] " #ifndef TEXTURES_HPP #define TEXTURES_HPP #include @@ -10,11 +11,10 @@ void setTextureTCoordinate(const GLenum textureTarget = GL_TEXTURE_2D, const GLi void setTextureRCoordinate(const GLenum textureTarget = GL_TEXTURE_3D, const GLint rCoordinateOption = GL_REPEAT, const float* borderColor = NULL); void setTextureFilteringAndMipMap(const GLenum textureTarget = GL_TEXTURE_2D, const GLenum filterType = GL_TEXTURE_MAG_FILTER, const GLint textureFilteringMethod = GL_NEAREST, const GLint mipMapFilteringMethod = GL_NEAREST_MIPMAP_NEAREST); unsigned int generateAndBindTexture(const GLenum textureTarget); -unsigned char* loadTexture(const char* texturePath, int textureWidth, int textureHeight, int colorChannels); // const char* texturePath, int textureWidth, int textureHeight, int colorChannels, const GLenum textureTarget, const GLint sCoordinateOption, const GLint tCoordinateOption, const GLint rCoordinateOption, const float* borderColor -unsigned int loadAndCreateTexture(const char* texturePath, GLenum RGBFormat, bool flipImage); +unsigned int loadAndCreateTexture(const char* texturePath, bool flipImage); void activateAndBindTextures(unsigned int texture, GLenum textureNumber); -unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, GLenum rgbFormat, bool flipImage); +unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, bool flipImage); #endif // TEXTURES_HPP \ No newline at end of file