ARB
RNA3D_Textures.cxx
Go to the documentation of this file.
1 #include "RNA3D_GlobalHeader.hxx"
2 #include "RNA3D_Global.hxx"
3 #include "RNA3D_Textures.hxx"
4 #include "RNA3D_OpenGLEngine.hxx"
5 
6 #include <string>
7 #include <iostream>
8 #include <stdlib.h>
9 
10 #include <arbdb.h>
11 
12 
13 using namespace std;
14 
15 Texture2D::Texture2D() {
16 }
17 
18 Texture2D::~Texture2D() {
19 }
20 
21 static char* GetImageFile(int ImageId) {
22  const char *imageName = NULp;
23 
24  switch (ImageId) {
25  case CIRCLE: imageName = "Circle.png"; break;
26  case DIAMOND: imageName = "Diamond.png"; break;
27  case POLYGON: imageName = "Polygon.png"; break;
28  case STAR: imageName = "Star.png"; break;
29  case RECTANGLE: imageName = "Rectangle.png"; break;
30  case RECTANGLE_ROUND: imageName = "RectangleRound.png"; break;
31  case STAR_SMOOTH: imageName = "StarSmooth.png"; break;
32  case CONE_UP: imageName = "ConeUp.png"; break;
33  case CONE_DOWN: imageName = "ConeDown.png"; break;
34  case CROSS: imageName = "Cross.png"; break;
35  case QUESTION: imageName = "Question.png"; break;
36  case DANGER: imageName = "Danger.png"; break;
37  case HEXAGON: imageName = "Hexagon.png"; break;
38  case LETTER_A: imageName = "LetterA.png"; break;
39  case LETTER_G: imageName = "LetterG.png"; break;
40  case LETTER_C: imageName = "LetterC.png"; break;
41  case LETTER_U: imageName = "LetterU.png"; break;
42  }
43 
44  if (!imageName) {
45  throw string(GBS_global_string("Illegal image id %i", ImageId));
46  }
47 
48  char *fname = GB_lib_file(false, "rna3d/images/", imageName);
49  if (!fname) {
50  throw string("File not found: ")+imageName;
51  }
52  return fname;
53 }
54 
55 // Load Bitmaps And Convert To Textures
56 void Texture2D::LoadGLTextures() {
57 
58  for (int i = 0; i < SHAPE_MAX; i++)
59  {
60  char *ImageFile = GetImageFile(i);
61  pngInfo info;
62 
63  // Using pngLoadAndBind to set texture parameters automatically.
64  texture[i] = pngBind(ImageFile, GLPNG_NOMIPMAP, GLPNG_ALPHA, &info, GL_CLAMP, GL_NEAREST, GL_NEAREST);
65 
66  if (texture[i] == 0) {
67  throw string(GBS_global_string("Error loading %s", ImageFile));
68  }
69 
71  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
72  }
73  else {
74  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
75  }
76 
77 #ifdef DEBUG
78  cout<<ImageFile<<" : Size = "<<info.Width<<" x "<<info.Height << ", Depth = "
79  <<info.Depth<<", Alpha = "<<info.Alpha<<endl;
80 #endif
81 
82  free(ImageFile);
83  }
84 
85 }
return string(buffer, length)
static char * GetImageFile(int ImageId)
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
STL namespace.
#define GLPNG_NOMIPMAP
Definition: glpng.h:58
unsigned int APIENTRY pngBind(const char *filename, int mipmap, int trans, pngInfo *info, int wrapst, int minfilter, int magfilter)
Definition: glpng.c:569
unsigned int Alpha
Definition: glpng.h:80
unsigned int Height
Definition: glpng.h:78
#define GLPNG_ALPHA
Definition: glpng.h:64
Definition: glpng.h:76
char * GB_lib_file(bool warn_when_not_found, const char *libprefix, const char *filename)
Definition: adfile.cxx:198
unsigned int Width
Definition: glpng.h:77
unsigned int Depth
Definition: glpng.h:79
bool bPointSpritesSupported
#define NULp
Definition: cxxforward.h:116
RNA3D_Global * RNA3D
static int info[maxsites+1]