C:/Projekte/C++/FlowVIS_107/src/Texture.cpp

Go to the documentation of this file.
00001 #include "Texture.h"
00002 
00003 GLuint Texture::Create(FlowChannel* channel, int dimX, int dimY)
00004 {
00005   if(texId)
00006     Delete(texId);
00007 
00008 //  float val;
00009   texId = 0;
00010   //glEnable(GL_TEXTURE_2D);
00011   //glEnable(GL_TEXTURE_RECTANGLE_ARB);
00012   //glGenTextures(1, &texId);
00013   //glBindTexture(GL_TEXTURE_2D, texId);
00014 
00015   //float xMax = (float) (dimX - 1.0f);
00016   //float yMax = (float) (dimY - 1.0f);
00017 
00018   //printf("ResX: %d, ResY: %d\n", dimX, dimY);
00019 
00020   //GLubyte* texData = new GLubyte[dimX * dimY];
00021 
00022   //for(int y = 0; y < dimY; y++)
00023   //{
00024   //  for(int x = 0; x < dimX; x++)
00025   //  {
00026   //    // already normalized value -> scale to 255.0 for GL_UBYTE
00027   //    val = channel->getValue(y * dimX + x);
00028   //    texData[dimX * y + x] = (GLubyte) (255.0f * val);
00029 
00030   //    printf("\r(%d%%) loaded", (dimX * y + x) * 100 / (dimX * dimY));
00031   //  }
00032   //}
00033 
00034   //printf("Texture generation complete\n");
00035 
00036   //glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8, dimX, dimY, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texData);
00037   //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00038   //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00039   //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00040   //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00041 
00042   //glDisable(GL_TEXTURE_RECTANGLE_ARB);
00043   //glDisable(GL_TEXTURE_2D);
00044 
00045   //delete[] texData;
00046   return texId;
00047 }
00048 
00049 void Texture::CreateBackground(FlowChannel* channel, int dimX, int dimY, GLuint texID[], int idx)
00050 {
00051   glGenTextures(1,&texID[idx]);
00052   glBindTexture(GL_TEXTURE_2D, texID[idx]);
00053 
00054   printf("ResX: %d, ResY: %d\n", dimX, dimY);
00055 
00056   //glPixelStorei(GL_UNPACK_ALIGNMENT, 2); //byte
00057 
00059   glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, dimX, dimY, 0, GL_LUMINANCE, GL_FLOAT, channel->getData());
00060   
00061   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00062   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00063   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00064   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00065 }
00066 
00067 #if 0
00068 GLuint Texture::CreateGlyph()
00069 {
00070   //determine max point size
00071   GLfloat fSize[2];
00072   GLuint texId = 0;
00073   glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, fSize);
00074 
00075   printf("PointSize: min %f, max %f\n", fSize[0], fSize[1]);
00076 
00077   float texture[GLYPHSIZE][GLYPHSIZE][2]; //RGB+alpha
00078   int indent = 0;
00079 
00080   for(int y = 0; y < GLYPHSIZE; y++)
00081   {
00082     for(int x = 0; x < GLYPHSIZE; x++)
00083     {
00084       if(x == GLYPHSIZE/2 - 1 || x == GLYPHSIZE/2)
00085         texture[y][x][0] = 1.0f;
00086       else
00087         texture[y][x][1] = 0.0f;
00088 
00089       if(y >= GLYPHSIZE/2)
00090       {
00091         if(y == GLYPHSIZE/2)
00092         {
00093           texture[y][x][0] = 1.0f;    
00094         }
00095         else 
00096           if(x > indent && x < (GLYPHSIZE - indent))
00097           {
00098             texture[y][x][0] = 1.0f;    
00099           }
00100       }
00101     }
00102     indent++;
00103   }
00104 
00105   glGenTextures(1, &texId);
00106   glBindTexture(GL_TEXTURE_2D, texId);
00107   //glTexImage2D(GL_TEXTURE_2D, 0, 3, TEXSIZE, TEXSIZE, 0, GL_RGB, GL_FLOAT, &texture[0]);
00108   glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, GLYPHSIZE, GLYPHSIZE, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, &texture[0][0]);
00109   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00110   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00111   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00112   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00113 
00114 return texId;
00115 }
00116 
00117 #endif 
00118 GLuint Texture::CreateGlyph()
00119 {
00120   printf("Create Glyph\n");
00121 
00122   std::string filename = "arrow.png";
00123   ILuint ilTexId = 0;
00124   GLuint glTexId = 0;
00125   ILboolean loaded;
00126 
00127   ilGenImages(1, &ilTexId);
00128   ilBindImage(ilTexId);
00129   loaded = ilLoadImage((const char*) filename.c_str());
00130 
00131   if(loaded)
00132   {
00133     loaded = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
00134 
00135     printf("Glyph file loaded\n");
00136 
00137     glGenTextures(1, &glTexId);
00138     glBindTexture(GL_TEXTURE_2D, glTexId);
00139     //glTexImage2D(GL_TEXTURE_2D, 0, 3, TEXSIZE, TEXSIZE, 0, GL_RGB, GL_FLOAT, &texture[0]);
00140     //glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, GLYPHSIZE, GLYPHSIZE, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, &texture[0][0]);
00141     
00142     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00143     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00144     
00145     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00146     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00147 
00148     glTexImage2D(GL_TEXTURE_2D, 
00149                  0, 
00150                  ilGetInteger(IL_IMAGE_BPP), 
00151                  ilGetInteger(IL_IMAGE_WIDTH), 
00152                  ilGetInteger(IL_IMAGE_HEIGHT), 
00153                  0, 
00154                  ilGetInteger(IL_IMAGE_FORMAT), 
00155                  GL_UNSIGNED_BYTE, 
00156                  ilGetData()); 
00157   }
00158 
00159   ilDeleteImages(1, &ilTexId);
00160   return glTexId;
00161 }
00162 #if 0 
00163 GLuint Texture::CreateColorBar(QGradientStops stops)
00164 {
00165   GLuint glTexId = 0;
00166   glGenTextures(1, &glTexId);
00167   glBindTexture(GL_TEXTURE_2D, glTexId);
00168 
00170   QPolygonF pts;
00171   pts << QPointF(0,0) << QPointF (colorBarTextureWidth-1, 0);
00172 
00174   QLinearGradient gradient = QLinearGradient(pts.at(0), pts.at(1));
00175   gradient.setSpread(QGradient::PadSpread);
00176 
00178   for(int i = 0; i < stops.size(); i++)
00179   {
00180     gradient.setColorAt(stops.at(i).first, stops.at(i).second);
00181   }
00182 
00184   QImage image = QImage(colorBarTextureWidth, 512, QImage::Format_ARGB32);
00185   image.fill(Qt::transparent);
00186 
00188   QPainter painter(&image);
00189 
00191   painter.fillRect(0, 0, colorBarTextureWidth, 512, gradient);
00192   painter.end();
00193 
00194   
00195   QImage texture;
00196 
00198   texture = QGLWidget::convertToGLFormat(image);
00199 
00200   //texture.save("texture2.png");
00201 
00202   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4096, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.bits());
00203     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00204     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00205     
00206     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00207     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00208 
00209   //GLfloat bCol[] = { 0.0, 0.0, 0.0, 1.0 };
00210   //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bCol );
00211 
00212   return glTexId;
00213 }
00214 #endif 
00215 
00216 GLuint Texture::CreateColorBar(QGradientStops stops)
00217 {
00218   GLuint glTexId = 0;
00219   glGenTextures(1, &glTexId);
00220   glBindTexture(GL_TEXTURE_1D, glTexId);
00221 
00223   QPolygonF pts;
00224   pts << QPointF(0,0) << QPointF (colorBarTextureWidth-1, 0);
00225 
00227   QLinearGradient gradient = QLinearGradient(pts.at(0), pts.at(1));
00228   gradient.setSpread(QGradient::PadSpread);
00229 
00231   for(int i = 0; i < stops.size(); i++)
00232   {
00233     gradient.setColorAt(stops.at(i).first, stops.at(i).second);
00234   }
00235 
00237   QImage image = QImage(colorBarTextureWidth, 1, QImage::Format_ARGB32);
00238   image.fill(Qt::transparent);
00239 
00241   QPainter painter(&image);
00242 
00244   painter.fillRect(0, 0, colorBarTextureWidth, 1, gradient);
00245   painter.end();
00246 
00248   image = QGLWidget::convertToGLFormat(image);
00249   printf("1D-Texture width: %d\n", image.width());
00250 
00251   //image.save("texture2.png");
00252 
00253   glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, image.width(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
00254     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00255     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00256     
00257     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00258     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00259 
00260   //GLfloat bCol[] = { 0.0, 0.0, 0.0, 1.0 };
00261   //glTexParameterfv(GL_TEXTURE_1D, GL_TEXTURE_BORDER_COLOR, bCol );
00262 
00263   return glTexId;
00264 }
00265 
00266 void Texture::Delete(GLuint id)
00267 {
00268   glDeleteTextures(1, &id);
00269 }

Generated on Mon Jan 21 14:50:12 2008 for VisLU by  doxygen 1.5.4