No Problem, sorry I don't usually ask for help. I just thought including all of the code would make it easier to run and see. I will post a couple of screen shots and the texurize function code. I hope that will help. I attached a working OpenTK application so you can see what the image should look like when rendered properly. Again apologies for the lack of details ...
void GLWidget::texturize()
{
for (uint i = 0; i < imageArrayLength; i++)
dspArray[i] = lutArray[imageArray[i]];
/*ushort val;
for (uint i = 0; i < imageArrayLength; i++)
{
val = imageArray[i];
dspArray[i] = lutArray[val];
}*/
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
// when texture area is small, bilinear filter the closest mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR );
// when texture area is large, bilinear filter the original
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// the texture wraps over at the edges (repeat)
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
//glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, image_array2D );
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, imageSize.width(), imageSize.height(), 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, dspArray );
}
void GLWidget::texturize()
{
for (uint i = 0; i < imageArrayLength; i++)
dspArray[i] = lutArray[imageArray[i]];
/*ushort val;
for (uint i = 0; i < imageArrayLength; i++)
{
val = imageArray[i];
dspArray[i] = lutArray[val];
}*/
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
// when texture area is small, bilinear filter the closest mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR );
// when texture area is large, bilinear filter the original
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// the texture wraps over at the edges (repeat)
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
//glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, image_array2D );
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, imageSize.width(), imageSize.height(), 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, dspArray );
}
To copy to clipboard, switch view to plain text mode
void GLWidget::paintGL()
{
//glClear(GL_COLOR_BUFFER_BIT);
//qglColor(Qt::blue);
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
glScalef(scale, scale, 1.0f);
glTranslated(-centerImage.x(), centerImage.y() - height, 0.0f);
//glColor3i(1.0,1.0,1.0);
qDebug() << "-centerImage.x(): " << -centerImage.x() << " centerImage.y() - height: " << centerImage.y() - height;
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, (GLfloat)height);
glTexCoord2f(1.0f, 0.0f); glVertex2f((GLfloat)width, (GLfloat)height);
glTexCoord2f(1.0f, 1.0f); glVertex2f((GLfloat)width, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 0.0f);
glEnd();
swapBuffers();
}
void GLWidget::paintGL()
{
//glClear(GL_COLOR_BUFFER_BIT);
//qglColor(Qt::blue);
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
glScalef(scale, scale, 1.0f);
glTranslated(-centerImage.x(), centerImage.y() - height, 0.0f);
//glColor3i(1.0,1.0,1.0);
qDebug() << "-centerImage.x(): " << -centerImage.x() << " centerImage.y() - height: " << centerImage.y() - height;
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, (GLfloat)height);
glTexCoord2f(1.0f, 0.0f); glVertex2f((GLfloat)width, (GLfloat)height);
glTexCoord2f(1.0f, 1.0f); glVertex2f((GLfloat)width, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 0.0f);
glEnd();
swapBuffers();
}
To copy to clipboard, switch view to plain text mode
void GLWidget::resizeGL(int w, int h)
{
width = w;
//height = h;
height = h?h:1;
w2 = (double)width / 2;
h2 = (double)height / 2;
scale = 1024;
while(imageSize.width() * scale > width || imageSize.height() * scale > height)
scale /= SCALE_FACTOR;
qDebug() << "Scale: " << scale;
centerImage.setX((int)w2);
centerImage.setY((int)h2);
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-w2, w2, -h2, h2, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void GLWidget::resizeGL(int w, int h)
{
width = w;
//height = h;
height = h?h:1;
w2 = (double)width / 2;
h2 = (double)height / 2;
scale = 1024;
while(imageSize.width() * scale > width || imageSize.height() * scale > height)
scale /= SCALE_FACTOR;
qDebug() << "Scale: " << scale;
centerImage.setX((int)w2);
centerImage.setY((int)h2);
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-w2, w2, -h2, h2, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
To copy to clipboard, switch view to plain text mode
Bookmarks