Implement a small texture wrapper.

Allows for RAII use of OpenGL textures.
This commit is contained in:
2018-02-25 19:03:10 +01:00
parent 23ae9717ea
commit 17d4e07025
6 changed files with 89 additions and 13 deletions

View File

@@ -8,6 +8,7 @@
#include <thread>
#include "glutils.hpp"
#include "Range.hpp"
#include "Texture.hpp"
using namespace fmri;
using namespace std;
@@ -32,17 +33,16 @@ static void rescaleSubImages(vector<float>& textureBuffer, int subImages) {
}
}
GLuint fmri::loadTexture(DType const *data, int width, int height, int subImages)
fmri::Texture fmri::loadTexture(DType const *data, int width, int height, int subImages)
{
// Load and scale texture
vector<float> textureBuffer(data, data + (width * height));
rescaleSubImages(textureBuffer, subImages);
const float color[] = {1, 1, 1}; // Background color for textures.
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
Texture texture;
texture.bind(GL_TEXTURE_2D);
// Set up (lack of) repetition
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);