int opengl_renderer_draw(Image *im, void *pal, int x, int y) { #ifdef USE_OPENGL if (pal) { // set alpha on colorkey index if (im->colorkey_index >= 0 && im->colorkey_index <= 255) ((unsigned char*)pal+4*im->colorkey_index)[3] = 0; glColorTable(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, pal); } glTranslatef(x, y, 0); glBindTexture(GL_TEXTURE_2D, im->tex); glBegin(GL_QUADS); glTexCoord2f(0, 1); glVertex2f( 0, 0); glTexCoord2f(1, 1); glVertex2f(im->width, 0); glTexCoord2f(1, 0); glVertex2f(im->width, im->height); glTexCoord2f(0, 0); glVertex2f( 0, im->height); glEnd(); glTranslatef(-x, -y, 0); if (pal) if (im->colorkey_index >= 0 && im->colorkey_index <= 255) ((unsigned char*)pal+4*im->colorkey_index)[3] = 255; return 0; #else // to prevent compiler complaining about unused variables (void)im; (void)pal; (void)x; (void)y; return -1; #endif }
void PaletteRenderer::uploadTexture2D(VolumeRenderer::DataItem* dataItem,int axis,int index) const { if(dataItem->setParameters) { /* Set the OpenGL texturing parameters: */ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,interpolationMode); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,interpolationMode); } #if 1 /* Upload a color map only if necessary: */ if(static_cast<DataItem*>(dataItem)->uploadColorMap) { /* Set the texture's color map: */ #ifdef __SGI_IRIX__ glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #else glColorTable(GL_TEXTURE_2D,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #endif } #endif if(dataItem->uploadData) { /* Some workaround for SGI's non-compliance of OpenGL (what a shame): */ #if (__SGI_IRIX__ || __APPLE__) const GLenum internalFormat=GL_INTENSITY8; const GLenum uploadFormat=GL_LUMINANCE; #else // use non-ARB extension 78 const GLenum internalFormat=GL_COLOR_INDEX8_EXT; const GLenum uploadFormat=GL_COLOR_INDEX; #endif /* Upload a texture slice: */ const Voxel* slicePtr=values+index*increments[axis]; switch(axis) { case 0: glTexImage2D(GL_TEXTURE_2D,0,internalFormat,textureSize[2],textureSize[1],0,uploadFormat,GL_UNSIGNED_BYTE,0); glTexSubImage2D(GL_TEXTURE_2D,0,0,0,size[2],size[1],increments[2],increments[1],uploadFormat,GL_UNSIGNED_BYTE,slicePtr); break; case 1: glTexImage2D(GL_TEXTURE_2D,0,internalFormat,textureSize[2],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,0); glTexSubImage2D(GL_TEXTURE_2D,0,0,0,size[2],size[0],increments[2],increments[0],uploadFormat,GL_UNSIGNED_BYTE,slicePtr); break; case 2: glTexImage2D(GL_TEXTURE_2D,0,internalFormat,textureSize[1],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,0); glTexSubImage2D(GL_TEXTURE_2D,0,0,0,size[1],size[0],increments[1],increments[0],uploadFormat,GL_UNSIGNED_BYTE,slicePtr); break; } } }
void PaletteRenderer::uploadTexture3D(VolumeRenderer::DataItem* dataItem) const { if(dataItem->setParameters) { /* Set the OpenGL texturing parameters: */ glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_BASE_LEVEL,0); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAX_LEVEL,0); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_R,GL_CLAMP); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAG_FILTER,interpolationMode); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MIN_FILTER,interpolationMode); } #if 1 /* Upload a color map only if necessary: */ if(static_cast<DataItem*>(dataItem)->uploadColorMap) { /* Set the texture's color map: */ #ifdef __SGI_IRIX__ glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #else glColorTable(GL_TEXTURE_3D,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #endif } #endif if(dataItem->uploadData) { /* Some workaround for SGI's non-compliance of OpenGL (what a shame): */ #if (__SGI_IRIX__ || __APPLE__) const GLenum internalFormat=GL_INTENSITY8; const GLenum uploadFormat=GL_LUMINANCE; #else // use non-ARB extension 78 const GLenum internalFormat=GL_COLOR_INDEX8_EXT; const GLenum uploadFormat=GL_COLOR_INDEX; #endif /* Upload the texture block: */ glPixelStorei(GL_UNPACK_ALIGNMENT,1); glPixelStorei(GL_UNPACK_SKIP_PIXELS,0); glPixelStorei(GL_UNPACK_ROW_LENGTH,0); // increments[1]); // Seems to be a bug in OpenGL - consistent across SGI/nVidia platforms glPixelStorei(GL_UNPACK_SKIP_ROWS,0); glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,0); // increments[0]); glPixelStorei(GL_UNPACK_SKIP_IMAGES,0); #ifdef __SGI_IRIX__ glTexImage3D(GL_TEXTURE_3D,0,internalFormat,textureSize[2],textureSize[1],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,values); #else glTexImage3D(GL_TEXTURE_3D,0,internalFormat,textureSize[2],textureSize[1],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,0); glTexSubImage3D(GL_TEXTURE_3D,0,0,0,0,size[2],size[1],size[0],uploadFormat,GL_UNSIGNED_BYTE,values); #endif } }
/** * Use the material, called before mesh calls */ int material_c::use(){ /* Check the texture pointer */ if( !loaded ){ return FAILURE; } /* Only attempt to use the texture if it is loaded */ if( loaded ){ glBindTexture( 0, id ); glColorTable( GL_RGB32_A3, pal_offset[selected_pal] ); } return SUCCESS; }
void PaletteRenderer::setGlobalColorMap(const GLColorMap* newGlobalColorMap) { if(newGlobalColorMap->getNumEntries()==256) { /* Sufficient to upload palette right here: */ #ifdef __SGI_IRIX__ glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,newGlobalColorMap->getColors()); #else glColorTable(GL_SHARED_TEXTURE_PALETTE_EXT,GL_RGBA,256,GL_RGBA,GL_FLOAT,newGlobalColorMap->getColors()); #endif } }
void PaletteRenderer::prepareRenderAxisAligned(VolumeRenderer::DataItem* dataItem) const { //DataItem* myDataItem=static_cast<DataItem*>(dataItem); #if 1 /* Manage color palette uploads: */ if(!textureCachingEnabled) { /* Sufficient to upload palette right here: */ #ifdef __SGI_IRIX__ glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #else glColorTable(GL_TEXTURE_2D,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #endif } #endif }
void PaletteRenderer::setGLState(GLContextData& contextData) const { VolumeRenderer::setGLState(contextData); #ifdef __SGI_IRIX__ glEnable(GL_TEXTURE_COLOR_TABLE_SGI); #endif if(sharePalette) glEnable(GL_SHARED_TEXTURE_PALETTE_EXT); #if 0 /* Sufficient to upload palette right here: */ #ifdef __SGI_IRIX__ glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #else glColorTable(GL_TEXTURE_2D,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #endif #endif }
void init(void) { int i; GLubyte colorTable[256][3]; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glClearColor(0.0, 0.0, 0.0, 0.0); /* Set up an inverse color table */ for ( i = 0; i < 256; ++i ) { colorTable[i][0] = 255 - i; colorTable[i][1] = 255 - i; colorTable[i][2] = 255 - i; } glColorTable(GL_COLOR_TABLE, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, colorTable); glEnable(GL_COLOR_TABLE); }
void _swrast_CopyColorTable( GLcontext *ctx, GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width) { GLchan data[MAX_WIDTH][4]; /* Select buffer to read from */ _swrast_use_read_buffer(ctx); if (width > MAX_WIDTH) width = MAX_WIDTH; /* read the data from framebuffer */ _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data ); /* Restore reading from draw buffer (the default) */ _swrast_use_draw_buffer(ctx); glColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBImaging_nglColorTableBO(JNIEnv *env, jclass clazz, jint target, jint internalFormat, jint width, jint format, jint type, jlong data_buffer_offset, jlong function_pointer) { const GLvoid *data_address = (const GLvoid *)(intptr_t)offsetToPointer(data_buffer_offset); glColorTablePROC glColorTable = (glColorTablePROC)((intptr_t)function_pointer); glColorTable(target, internalFormat, width, format, type, data_address); }
/////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { GLint i; // Looping variable GLint iViewport[4]; // Viewport GLint iLargest; // Largest histogram value static GLubyte invertTable[256][3];// Inverted color table // Do a black and white scaling static GLfloat lumMat[16] = { 0.30f, 0.30f, 0.30f, 0.0f, 0.59f, 0.59f, 0.59f, 0.0f, 0.11f, 0.11f, 0.11f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; static GLfloat mSharpen[3][3] = { // Sharpen convolution kernel {0.0f, -1.0f, 0.0f}, {-1.0f, 5.0f, -1.0f }, {0.0f, -1.0f, 0.0f }}; static GLfloat mEmboss[3][3] = { // Emboss convolution kernel { 2.0f, 0.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, { 0.0f, 0.0f, -1.0f }}; static GLint histoGram[256]; // Storeage for histogram statistics // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); // Current Raster Position always at bottom left hand corner of window glRasterPos2i(0, 0); glGetIntegerv(GL_VIEWPORT, iViewport); glPixelZoom((GLfloat) iViewport[2] / (GLfloat)iWidth, (GLfloat) iViewport[3] / (GLfloat)iHeight); if(bHistogram == GL_TRUE) // Collect Historgram data { // We are collecting luminance data, use our conversion formula // instead of OpenGL's (which just adds color components together) glMatrixMode(GL_COLOR); glLoadMatrixf(lumMat); glMatrixMode(GL_MODELVIEW); // Start collecting histogram data, 256 luminance values glHistogram(GL_HISTOGRAM, 256, GL_LUMINANCE, GL_FALSE); glEnable(GL_HISTOGRAM); } // Do image operation, depending on rendermode index switch(iRenderMode) { case 5: // Sharpen image glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGB, 3, 3, GL_LUMINANCE, GL_FLOAT, mSharpen); glEnable(GL_CONVOLUTION_2D); break; case 4: // Emboss image glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGB, 3, 3, GL_LUMINANCE, GL_FLOAT, mEmboss); glEnable(GL_CONVOLUTION_2D); glMatrixMode(GL_COLOR); glLoadMatrixf(lumMat); glMatrixMode(GL_MODELVIEW); break; case 3: // Invert Image for(i = 0; i < 255; i++) { invertTable[i][0] = (GLubyte)(255 - i); invertTable[i][1] = (GLubyte)(255 - i); invertTable[i][2] = (GLubyte)(255 - i); } glColorTable(GL_COLOR_TABLE, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, invertTable); glEnable(GL_COLOR_TABLE); break; case 2: // Brighten Image glMatrixMode(GL_COLOR); glScalef(1.25f, 1.25f, 1.25f); glMatrixMode(GL_MODELVIEW); break; case 1: // Just do a plain old image copy default: // This line intentially left blank break; } // Do the pixel draw glDrawPixels(iWidth, iHeight, eFormat, GL_UNSIGNED_BYTE, pImage); // Fetch and draw histogram? if(bHistogram == GL_TRUE) { // Read histogram data into buffer glGetHistogram(GL_HISTOGRAM, GL_TRUE, GL_LUMINANCE, GL_INT, histoGram); // Find largest value for scaling graph down iLargest = 0; for(i = 0; i < 255; i++) if(iLargest < histoGram[i]) iLargest = histoGram[i]; // White lines glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_LINE_STRIP); for(i = 0; i < 255; i++) glVertex2f((GLfloat)i, (GLfloat)histoGram[i] / (GLfloat) iLargest * 128.0f); glEnd(); bHistogram = GL_FALSE; glDisable(GL_HISTOGRAM); } // Reset everyting to default glMatrixMode(GL_COLOR); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glDisable(GL_CONVOLUTION_2D); glDisable(GL_COLOR_TABLE); // Show our hard work... glutSwapBuffers(); }