void GLWidget::setTexture(unsigned char *_data, float transfer, int dispChannelOne, int dispChannelTwo, int dispChannelThree)
{
displayChannels = dispChannelOne + dispChannelTwo + dispChannelThree;
channelOne = dispChannelOne;
channelTwo = dispChannelTwo;
channelThree = dispChannelThree;
textureData = _data;
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Update the texture for channel one
if(channelOne == 1) {
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_LUMINANCE,
512, 512, 0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
textureData+0*512*512);
}
// Update the texture for channel two
if(channelTwo == 1) {
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_LUMINANCE,
512, 512, 0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
textureData + 1*512*512); // + subchannels * widht * height
}
// Update the texture for channel three
if(channelThree == 1) {
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_LUMINANCE,
512, 512, 0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
textureData + 2*512*512); // + subchannels * widht * height
}
updateGL();
}
void GLWidget::paintGL()
{
// Clear color buffer
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClear( GL_COLOR_BUFFER_BIT );
// Set up the camera and projection
// Select and setup the projection matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( -1.0f, 1.0f, -1.0f, 1.0f );
glViewport( 0, 0, 512, 512);
if(hasTexture) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
if(channelOne == 1 && channelTwo == 0)
glBindTexture(GL_TEXTURE_2D, texture[0]);
if(channelOne == 0 && channelTwo == 1)
glBindTexture(GL_TEXTURE_2D, texture[1]);
}
glBegin( GL_QUADS );
glTexCoord2f( 1.0f, 0.0f );
glVertex2f( -1.0f, -1.0f );
glTexCoord2f( 0.0f, 0.0f );
glVertex2f( 1.0f, -1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex2f( 1.0f, 1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex2f( -1.0f, 1.0f );
glEnd();
}
void GLWidget::setTexture(unsigned char *_data, float transfer, int dispChannelOne, int dispChannelTwo, int dispChannelThree)
{
displayChannels = dispChannelOne + dispChannelTwo + dispChannelThree;
channelOne = dispChannelOne;
channelTwo = dispChannelTwo;
channelThree = dispChannelThree;
textureData = _data;
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Update the texture for channel one
if(channelOne == 1) {
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_LUMINANCE,
512, 512, 0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
textureData+0*512*512);
}
// Update the texture for channel two
if(channelTwo == 1) {
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_LUMINANCE,
512, 512, 0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
textureData + 1*512*512); // + subchannels * widht * height
}
// Update the texture for channel three
if(channelThree == 1) {
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_LUMINANCE,
512, 512, 0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
textureData + 2*512*512); // + subchannels * widht * height
}
updateGL();
}
void GLWidget::paintGL()
{
// Clear color buffer
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClear( GL_COLOR_BUFFER_BIT );
// Set up the camera and projection
// Select and setup the projection matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( -1.0f, 1.0f, -1.0f, 1.0f );
glViewport( 0, 0, 512, 512);
if(hasTexture) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
if(channelOne == 1 && channelTwo == 0)
glBindTexture(GL_TEXTURE_2D, texture[0]);
if(channelOne == 0 && channelTwo == 1)
glBindTexture(GL_TEXTURE_2D, texture[1]);
}
glBegin( GL_QUADS );
glTexCoord2f( 1.0f, 0.0f );
glVertex2f( -1.0f, -1.0f );
glTexCoord2f( 0.0f, 0.0f );
glVertex2f( 1.0f, -1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex2f( 1.0f, 1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex2f( -1.0f, 1.0f );
glEnd();
}
To copy to clipboard, switch view to plain text mode
I can se the second texture but cannot switch to the first.
Bookmarks