Actually show rendered textures for image-like-layers.
This commit is contained in:
@@ -52,9 +52,24 @@ MultiImageVisualisation::~MultiImageVisualisation()
|
||||
|
||||
void MultiImageVisualisation::render()
|
||||
{
|
||||
static const float textureCoords[] = {
|
||||
1, 1,
|
||||
1, 0,
|
||||
0, 0,
|
||||
0, 1,
|
||||
};
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glColor3f(0.3, 0.3, 0.3);
|
||||
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.get());
|
||||
glDrawArrays(GL_QUADS, 0, 4 * textureReferences.size());
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
for (auto i : Range(textureReferences.size())) {
|
||||
glBindTexture(GL_TEXTURE_2D, textureReferences[i]);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, textureCoords);
|
||||
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.get() + i * BASE_VERTICES.size());
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,23 @@
|
||||
using namespace fmri;
|
||||
using namespace std;
|
||||
|
||||
static void handleGLError(GLenum error) {
|
||||
switch (error) {
|
||||
case GL_NO_ERROR:
|
||||
return;
|
||||
|
||||
default:
|
||||
cerr << "OpenGL error: " << (const char*) glewGetErrorString(error) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint fmri::loadTexture(DType const *data, int width, int height)
|
||||
{
|
||||
// Load and scale texture
|
||||
vector<DType> textureBuffer(data, data + (width * height));
|
||||
vector<float> textureBuffer(data, data + (width * height));
|
||||
rescale(textureBuffer.begin(), textureBuffer.end(), 0, 1);
|
||||
|
||||
const float color[] = {0, 0, 0}; // Background color for textures.
|
||||
const float color[] = {1, 1, 1}; // Background color for textures.
|
||||
GLuint texture;
|
||||
glGenTextures(1, &texture);
|
||||
|
||||
@@ -28,15 +38,12 @@ GLuint fmri::loadTexture(DType const *data, int width, int height)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
|
||||
|
||||
static_assert(sizeof(DType) == 4); // verify data type for texture.
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 2, 2, 0, GL_R32F, GL_FLOAT, textureBuffer.data());
|
||||
|
||||
// Set up texture scaling
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Use mipmapping for scaling down
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); // Use mipmapping for scaling down
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Use nearest pixel when scaling up.
|
||||
checkGLErrors();
|
||||
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, width, height, GL_LUMINANCE, GL_FLOAT, textureBuffer.data());
|
||||
|
||||
return texture;
|
||||
}
|
||||
@@ -78,14 +85,7 @@ void fmri::renderText(std::string_view text)
|
||||
void fmri::checkGLErrors()
|
||||
{
|
||||
while (auto error = glGetError()) {
|
||||
switch (glGetError()) {
|
||||
case GL_NO_ERROR:
|
||||
// Should not get here, but whatever.
|
||||
return;
|
||||
|
||||
default:
|
||||
cerr << "OpenGL error: " << (const char*) glewGetErrorString(error) << endl;
|
||||
}
|
||||
handleGLError(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user