00001 #include "ColourPicker.h" 00002 00003 #include "TransferFunctionGUI.h" 00004 00005 00006 GLuint ColourPicker::colourPickerTextureID = -1; 00007 float ColourPicker::colourPickerSliderValue = 0.f; 00008 int ColourPicker::colourPickerOffsetX = 10; 00009 00010 ColourPickerSliderMode ColourPicker::g_iColourPickerLabSwitchMode = ColourPickerSliderMode_L; 00011 00012 int ColourPicker::colourPickerHeight = 180 + TransferFunctionGUI::g_iTransferFunctionTextureDisplayHeight + TransferFunctionGUI::g_iTransferFunctionTextureDisplayYOffset; 00013 int ColourPicker::colourPickerWidth = colourPickerHeight; 00014 00015 RGBA_Colour* ColourPicker::colourPickerTextureData = new RGBA_Colour[colourPickerWidth * colourPickerHeight]; 00016 00017 00018 00019 Lab_Colour ColourPicker::getColourPickerPositionColour(float x, float y) 00020 { 00021 float L = 0.f; 00022 float a = 0.f; 00023 float b = 0.f; 00024 00025 if(g_iColourPickerLabSwitchMode != ColourPickerSliderMode_L) 00026 { 00027 L = 100.f * y / (float)colourPickerHeight; 00028 if(g_iColourPickerLabSwitchMode != ColourPickerSliderMode_A) 00029 { 00030 b = colourPickerSliderValue; 00031 a = 130.f - 260.f * x /(float)colourPickerHeight; 00032 } 00033 else 00034 { 00035 a = colourPickerSliderValue; 00036 b = 130.f - 260.f * x /(float)colourPickerHeight; 00037 } 00038 } 00039 else 00040 { 00041 L = colourPickerSliderValue; 00042 a = 130.f - 260.f * x /(float) colourPickerWidth; 00043 b = 130.f - 260.f * y /(float)colourPickerHeight; 00044 } 00045 00046 return Lab_Colour(L, a, b); 00047 } 00048 00049 void ColourPicker::initColourPickerTexture() 00050 { 00051 glGenTextures(1, &colourPickerTextureID); 00052 00053 get_errors(); 00054 00055 if(colourPickerTextureID != GLuint(-1)) 00056 { 00057 get_errors(); 00058 glBindTexture(GL_TEXTURE_2D, colourPickerTextureID); 00059 00060 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP); 00061 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP); 00062 00063 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 00064 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 00065 00066 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, colourPickerWidth, colourPickerHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 00067 00068 get_errors(); 00069 } 00070 00071 refreshColourPickerTexture(glutGetWindow()); 00072 } 00073 00074 00075 00076 void ColourPicker::refreshColourPickerTexture(int windowID) 00077 { 00078 glutSetWindow(windowID); 00079 00080 for(int y = 0; y < colourPickerHeight; ++y) 00081 { 00082 for(int x = 0; x < colourPickerWidth; ++x) 00083 { 00084 int i = colourPickerWidth * y + x; 00085 00086 Lab_Colour colour = getColourPickerPositionColour((float)x, (float)y); 00087 00088 colourPickerTextureData[i] = RGBA_Colour(toRGB(colour), GLubyte(255)); 00089 } 00090 } 00091 if(colourPickerTextureID != GLuint(-1)) 00092 { 00093 glBindTexture(GL_TEXTURE_2D, colourPickerTextureID); 00094 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, colourPickerWidth, colourPickerHeight, GL_RGBA, GL_UNSIGNED_BYTE, colourPickerTextureData); 00095 get_errors(); 00096 } 00097 00098 }