32 #ifndef __vtkOpenGLContextDevice2DPrivate_h
33 #define __vtkOpenGLContextDevice2DPrivate_h
73 : std::pair<Key,
CacheData>(key, cacheData){}
80 return this->first == other.first;
114 typename std::list<CacheElement >::iterator it;
115 for (it = this->
Cache.begin(); it != this->
Cache.end(); ++it)
117 it->second.Texture->ReleaseGraphicsResources(window);
131 this->
Cache.pop_back();
133 this->
Cache.push_front(CacheElement(key, cacheData));
134 return this->
Cache.begin()->second;
150 typename std::list<CacheElement>::iterator it =
151 std::find(this->Cache.begin(), this->Cache.end(),
CacheElement(key));
152 if (it != this->Cache.end())
160 return this->AddCacheData(key, cacheData);
174 return static_cast<unsigned int>(id);
186 this->
Color.
Set(static_cast<unsigned char>(color[0] * 255),
187 static_cast<unsigned char>(color[1] * 255),
188 static_cast<unsigned char>(color[2] * 255),
189 static_cast<unsigned char>(textProperty->
GetOpacity() * 255));
288 bool colorDiffer =
false;
289 while(!colorDiffer && i < 4)
307 glEnable(capability);
311 glDisable(capability);
317 float* texCoord =
new float[2*n];
318 float minX = f[0];
float minY = f[1];
319 float maxX = f[0];
float maxY = f[1];
321 for(
int i = 0; i < n; ++i)
323 minX = fptr[0] < minX ? fptr[0] : minX;
324 maxX = fptr[0] > maxX ? fptr[0] : maxX;
325 minY = fptr[1] < minY ? fptr[1] : minY;
326 maxY = fptr[1] > maxY ? fptr[1] : maxY;
333 float rangeX = (textureBounds[1] - textureBounds[0]) ?
334 textureBounds[1] - textureBounds[0] : 1.;
335 float rangeY = (textureBounds[3] - textureBounds[2]) ?
336 textureBounds[3] - textureBounds[2] : 1.;
337 for (
int i = 0; i < n; ++i)
339 texCoord[i*2] = (fptr[0]-minX) / rangeX;
340 texCoord[i*2+1] = (fptr[1]-minY) / rangeY;
346 float rangeX = (maxX - minX)? maxX - minX : 1.f;
347 float rangeY = (maxY - minY)? maxY - minY : 1.f;
348 for (
int i = 0; i < n; ++i)
350 texCoord[i*2] = (fptr[0]-minX)/rangeX;
351 texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
361 for (
int i = 0; i < 2; ++i)
363 while (pow2[i] < size[i])
375 cout <<
"Error = not an unsigned char..." << endl;
383 for (
int i = 0; i < 2; ++i)
385 texCoords[i] = size[i] /
float(newImg[i]);
388 unsigned char *dataPtr =
389 new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
390 unsigned char *origPtr =
393 for (
int i = 0; i < newImg[0]; ++i)
395 for (
int j = 0; j < newImg[1]; ++j)
397 for (
int k = 0; k < bytesPerPixel; ++k)
399 if (i < size[0] && j < size[1])
401 dataPtr[i * newImg[0] * bytesPerPixel + j * bytesPerPixel + k] =
402 origPtr[i * size[0] * bytesPerPixel + j * bytesPerPixel + k];
406 dataPtr[i * newImg[0] * bytesPerPixel + j * bytesPerPixel + k] =
414 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
415 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
417 glGenTextures(1, &tmpIndex);
418 glBindTexture(GL_TEXTURE_2D, tmpIndex);
420 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_RGB, GL_REPLACE);
421 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_ALPHA, GL_REPLACE);
423 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
424 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
425 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
426 vtkgl::CLAMP_TO_EDGE );
427 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
428 vtkgl::CLAMP_TO_EDGE );
430 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
431 newImg[0], newImg[1], 0, glFormat,
432 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
433 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
434 glEnable(GL_ALPHA_TEST);
435 glMatrixMode(GL_TEXTURE);
437 glMatrixMode(GL_MODELVIEW);
438 glEnable(GL_TEXTURE_2D);
447 cout <<
"Error = not an unsigned char..." << endl;
454 unsigned char *dataPtr =
457 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
458 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
460 glGenTextures(1, &tmpIndex);
461 glBindTexture(GL_TEXTURE_2D, tmpIndex);
463 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_RGB, GL_REPLACE);
464 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_ALPHA, GL_REPLACE);
466 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
467 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
468 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
469 vtkgl::CLAMP_TO_EDGE );
470 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
471 vtkgl::CLAMP_TO_EDGE );
473 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
474 size[0], size[1], 0, glFormat,
475 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
476 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
477 glEnable(GL_ALPHA_TEST);
478 glMatrixMode(GL_TEXTURE);
480 glMatrixMode(GL_MODELVIEW);
481 glEnable(GL_TEXTURE_2D);
513 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H