source: tags/cvs_2_svn/RNA3D/RNA3D_Textures.cxx

Last change on this file was 5390, checked in by westram, 16 years ago
  • TAB-Ex
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
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
9#include <arbdb.h>
10
11
12using namespace std;
13
14Texture2D::Texture2D(void){
15}
16
17Texture2D::~Texture2D(void){
18}
19
20static char* GetImageFile(int ImageId){
21    const char *imageName = 0;
22
23    switch (ImageId) {
24        case CIRCLE:          imageName = "Circle.png"; break;
25        case DIAMOND:         imageName = "Diamond.png"; break;
26        case POLYGON:         imageName = "Polygon.png"; break;
27        case STAR:            imageName = "Star.png"; break;
28        case RECTANGLE:       imageName = "Rectangle.png"; break;
29        case RECTANGLE_ROUND: imageName = "RectangleRound.png"; break;
30        case STAR_SMOOTH:     imageName = "StarSmooth.png"; break;
31        case CONE_UP:         imageName = "ConeUp.png"; break;
32        case CONE_DOWN:       imageName = "ConeDown.png"; break;
33        case CROSS:           imageName = "Cross.png"; break;
34        case QUESTION:        imageName = "Question.png"; break;
35        case DANGER:          imageName = "Danger.png"; break;
36        case HEXAGON:         imageName = "Hexagon.png"; break;
37        case LETTER_A:        imageName = "LetterA.png"; break;
38        case LETTER_G:        imageName = "LetterG.png"; break;
39        case LETTER_C:        imageName = "LetterC.png"; break;
40        case LETTER_U:        imageName = "LetterU.png"; break;
41    }
42
43    if (!imageName) {
44        throw string(GBS_global_string("Illegal image id %i", ImageId));
45    }
46
47    char *fname = GBS_find_lib_file(imageName, "rna3d/images/", 0);
48    if (!fname) {
49        throw string("File not found: ")+imageName;
50    }
51    return fname;
52}
53
54// Load Bitmaps And Convert To Textures
55void Texture2D::LoadGLTextures(void) {
56
57    for (int i = 0; i < SHAPE_MAX; i++)
58    {
59        char    *ImageFile = GetImageFile(i);
60        pngInfo  info;
61
62        // Using pngLoadAndBind to set texture parameters automatically.
63        texture[i] = pngBind(ImageFile, PNG_NOMIPMAP, PNG_ALPHA, &info, GL_CLAMP, GL_NEAREST, GL_NEAREST);
64
65        if (texture[i] == 0) {
66            throw string(GBS_global_string("Error loading %s", ImageFile));
67        }
68
69        if (!RNA3D->bPointSpritesSupported) {
70            glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
71        }
72        else {
73            glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
74        }
75
76#ifdef DEBUG
77        cout<<ImageFile<<" : Size = "<<info.Width<<" x "<<info.Height <<", Depth = "
78            <<info.Depth<<", Alpha = "<<info.Alpha<<endl;
79#endif
80
81        free(ImageFile);
82    }
83
84}
Note: See TracBrowser for help on using the repository browser.