17 |
#include <GL/glew.h> |
#include <GL/glew.h> |
18 |
#include "texture.hpp" |
#include "texture.hpp" |
19 |
#include "texture-meta.hpp" |
#include "texture-meta.hpp" |
20 |
|
#include <boost/tuple/tuple.hpp> |
21 |
#include <Magick++.h> |
#include <Magick++.h> |
22 |
#include "log.hpp" |
#include "log.hpp" |
23 |
namespace usata |
namespace usata |
47 |
const std::string& |
const std::string& |
48 |
format() const {return Format;} |
format() const {return Format;} |
49 |
unsigned char*get_pixels(){ return pixels.get();} |
unsigned char*get_pixels(){ return pixels.get();} |
50 |
|
|
51 |
}; |
}; |
52 |
|
|
53 |
} |
} |
66 |
{ |
{ |
67 |
|
|
68 |
} |
} |
69 |
|
|
70 |
|
void |
71 |
|
Texture::allocate_gltex(void) |
72 |
|
{ |
73 |
|
glGenTextures(1,&tex_id); |
74 |
|
} |
75 |
|
|
76 |
Texture::Texture (const TextureMeta* meta) |
Texture::Texture (const TextureMeta* meta) |
77 |
{ |
{ |
78 |
Magick::Image XI(meta->filepath.native_file_string()); |
Magick::Image XI(meta->filepath.native_file_string()); |
79 |
log::BufferedStream logstream(log::Level::DEBUG); |
log::BufferedStream logstream(log::Level::DEBUG); |
|
logstream << XI.columns() << "x" <<XI.rows() << log::commit; |
|
80 |
Magick::ImageType image_type = XI.type(); |
Magick::ImageType image_type = XI.type(); |
81 |
unsigned Depth; |
unsigned Depth; |
82 |
|
GLint format = 0; |
83 |
std::string Type; |
std::string Type; |
84 |
switch (image_type) |
switch (image_type) |
85 |
{ |
{ |
86 |
case Magick::TrueColorType: |
case Magick::TrueColorType: |
87 |
case Magick::PaletteType: |
case Magick::PaletteType: |
88 |
{ |
{ |
89 |
|
format = GL_RGB; |
90 |
Type="RGB"; |
Type="RGB"; |
91 |
Depth = 24; |
Depth = 24; |
92 |
break; |
break; |
95 |
case Magick::TrueColorMatteType: |
case Magick::TrueColorMatteType: |
96 |
case Magick::PaletteMatteType: |
case Magick::PaletteMatteType: |
97 |
{ |
{ |
98 |
|
format = GL_RGBA; |
99 |
Type="RGBA"; |
Type="RGBA"; |
100 |
Depth = 32; |
Depth = 32; |
101 |
break; |
break; |
114 |
|
|
115 |
Pixmap pb(XI.columns(),XI.rows(),Depth,Type); |
Pixmap pb(XI.columns(),XI.rows(),Depth,Type); |
116 |
XI.write(0,0,pb.width(), pb.height(), pb.format(),Magick::CharPixel,pb.get_pixels()); |
XI.write(0,0,pb.width(), pb.height(), pb.format(),Magick::CharPixel,pb.get_pixels()); |
117 |
|
glBindTexture(GL_TEXTURE_2D, tex_id); |
118 |
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); |
119 |
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); |
120 |
|
gluBuild2DMipmaps(GL_TEXTURE_2D, format, pb.width(), pb.height(), format, GL_UNSIGNED_BYTE,pb.get_pixels()); |
121 |
|
|
122 |
return; |
return; |
123 |
} |
} |