source: branches/profile/RNA3D/RNA3D_Textures.cxx

Last change on this file was 9003, checked in by westram, 12 years ago
  • changed 'PNG_' into 'GLPNG_' (libpng reserves 'PNG_' and 'png_')
    • suggested by John Bowler + Matt Cottrell
  • 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#include <stdlib.h>
9
10#include <arbdb.h>
11
12
13using namespace std;
14
15Texture2D::Texture2D() {
16}
17
18Texture2D::~Texture2D() {
19}
20
21static char* GetImageFile(int ImageId) {
22    const char *imageName = 0;
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
56void 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
70        if (!RNA3D->bPointSpritesSupported) {
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}
Note: See TracBrowser for help on using the repository browser.