diff --git a/Engine/engine/match b/Engine/engine/match index 893f4e6..76d46bd 100755 Binary files a/Engine/engine/match and b/Engine/engine/match differ diff --git a/Engine/engine/textures.cpp b/Engine/engine/textures.cpp new file mode 100644 index 0000000..370a8c7 --- /dev/null +++ b/Engine/engine/textures.cpp @@ -0,0 +1,76 @@ +#ifndef TEXTURES_CPP +#define TEXTURES_CPP +#include +#include +#include "stb_image.h" +#include "textures.hpp" + +void setTextureSCoordinate(const GLenum textureTarget, const GLint sCoordinateOption, const float* borderColor) +{ + // https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexParameter.xhtml + // first argument is texture target (by default we work with 2D textures so it will be GL_TEXTURE_2D) + // second argument is what option we want to set and for which texture axis (s, t or r) + // Third argument is texture wrapping mode + glTexParameteri(textureTarget, GL_TEXTURE_WRAP_S, sCoordinateOption); + if(sCoordinateOption == GL_CLAMP_TO_BORDER && borderColor != NULL) + { + // if we use GL_CLAMP_TO_BORDER all of the space that is not occupied by texture will be occupied by color + // we pass the color we want to use in float array (RGB + transparency) + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); + } +} + +void setTextureTCoordinate(const GLenum textureTarget, const GLint tCoordinateOption, const float* borderColor) +{ + // for comments concerning glTexParameteri and glTexParameterfv go to setTextureSCoordinate function + if(textureTarget == GL_TEXTURE_2D || textureTarget == GL_TEXTURE_3D) + { + glTexParameteri(textureTarget, GL_TEXTURE_WRAP_T, tCoordinateOption); + if(tCoordinateOption == GL_CLAMP_TO_BORDER && borderColor != NULL) + { + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); + } + } +} + +void setTextureRCoordinate(const GLenum textureTarget, const GLint rCoordinateOption, const float* borderColor) +{ + // for comments concerning glTexParameteri and glTexParameterfv go to setTextureSCoordinate function + if(textureTarget == GL_TEXTURE_3D) + { + glTexParameteri(textureTarget, GL_TEXTURE_WRAP_R, rCoordinateOption); + if(rCoordinateOption == GL_CLAMP_TO_BORDER && borderColor != NULL) + { + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); + } + } +} + +// Coordinate options can be: GL_REPEAT, GL_MIRRORED_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER +// s t r are equivalent to x y z +void setTextureParametersINT(const GLenum textureTarget, const GLint sCoordinateOption, const GLint tCoordinateOption, const GLint rCoordinateOption, const float* borderColor) +{ + setTextureSCoordinate(textureTarget, sCoordinateOption, borderColor); + setTextureTCoordinate(textureTarget, tCoordinateOption, borderColor); + setTextureRCoordinate(textureTarget, rCoordinateOption, borderColor); +} + +void setTextureFilteringAndMipMap(const GLenum textureTarget, const GLenum filterType, const GLint textureFilteringMethod, const GLint mipMapFilteringMethod) +{ + // mipMapFilteringMethod can be equal to: GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR + // NEAREST_MIPMAP - take nearest mipmap to match pixel size + // LINEAR_MIPMAP - interpolate between two mipmaps that match the size of a pixel + // NEAREST (at the end) - samples texture based on nearest neighbor interpolation + // LINEAR (at the end) - samples texture using linear interpolation + // setting anything else than GL_TEXTURE_MIN_FILTER as a second parameter results in GL_INVALID_ENUM error + glTexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, mipMapFilteringMethod); + // https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexParameter.xhtml + // first argument is texture target (by default we work with 2D textures so it will be GL_TEXTURE_2D) + // second argument is specifying whether this filter works for magnifying textures GL_TEXTURE_MAG_FILTER or minifying GL_TEXTURE_MIN_FILTER + // third argument is how we should magnify/minify textures, whether we should choose the color of pixel closest to the coordinates GL_NEAREST (default) + // or should we blend the neighboring pixels and choose blended color GL_LINEAR + glTexParameteri(textureTarget, filterType, textureFilteringMethod); +} + + +#endif // TEXTURES_CPP diff --git a/Engine/engine/textures.hpp b/Engine/engine/textures.hpp new file mode 100644 index 0000000..b17dc4b --- /dev/null +++ b/Engine/engine/textures.hpp @@ -0,0 +1,12 @@ +#ifndef TEXTURES_HPP +#define TEXTURES_HPP +#include +#include + +void setTextureParametersINT(const GLenum textureTarget = GL_TEXTURE_2D, const GLint sCoordinateOption = GL_REPEAT, const GLint tCoordinateOption = GL_REPEAT, const GLint rCoordinateOption = GL_REPEAT, const float* borderColor = NULL); +void setTextureSCoordinate(const GLenum textureTarget = GL_TEXTURE_2D, const GLint sCoordinateOption = GL_REPEAT, const float* borderColor = NULL); +void setTextureTCoordinate(const GLenum textureTarget = GL_TEXTURE_2D, const GLint tCoordinateOption = GL_REPEAT, const float* borderColor = NULL); +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); + +#endif // TEXTURES_HPP \ No newline at end of file