This repository has been archived on 2019-09-17. You can view files and clone it, but cannot push or open issues or pull requests.
Files
research-project/src/fmri/Texture.cpp

52 lines
1.1 KiB
C++

#include <algorithm>
#include "Texture.hpp"
using namespace fmri;
Texture::Texture() noexcept
{
glGenTextures(1, &id);
}
Texture::Texture(GLuint id) noexcept : id(id)
{
}
Texture::~Texture()
{
if (id != 0) {
glDeleteTextures(1, &id);
}
}
Texture &Texture::operator=(Texture && other) noexcept
{
std::swap(id, other.id);
return *this;
}
Texture::Texture(Texture && other) noexcept
{
std::swap(id, other.id);
}
void Texture::bind(GLenum target) const
{
glBindTexture(target, id);
}
void Texture::configure(GLenum target) const
{
bind(target);
const float color[] = {1, 0, 1}; // Background color for textures.
// Set up (lack of) repetition
glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, color);
// Set up texture scaling
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); // Use mipmapping for scaling down
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Use nearest pixel when scaling up.
}