[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Usata-commits] Changes to usata2/src/texture.cpp
From: |
David Lau |
Subject: |
[Usata-commits] Changes to usata2/src/texture.cpp |
Date: |
Mon, 17 Jan 2005 19:12:09 -0500 |
Index: usata2/src/texture.cpp
diff -u usata2/src/texture.cpp:1.6 usata2/src/texture.cpp:1.7
--- usata2/src/texture.cpp:1.6 Sat Jan 15 19:17:35 2005
+++ usata2/src/texture.cpp Tue Jan 18 00:12:08 2005
@@ -10,7 +10,7 @@
// included in the software distribution, or visit
// http://www.fsf.org/licenses/gpl.html.
//
-// $Id: texture.cpp,v 1.6 2005/01/15 19:17:35 skunix Exp $
+// $Id: texture.cpp,v 1.7 2005/01/18 00:12:08 skunix Exp $
#include <boost/scoped_array.hpp>
@@ -18,6 +18,8 @@
#include "texture.hpp"
#include "texture-meta.hpp"
#include <boost/tuple/tuple.hpp>
+#include <boost/format.hpp>
+#include <boost/bind.hpp>
#include <Magick++.h>
#include "log.hpp"
namespace usata
@@ -67,11 +69,88 @@
}
+ImageManager::Image_sp
+ImageManager::get(const std::string& name)
+{
+ return get_resource(name);
+}
+
+void
+ImageManager::meta_add(const TextureMeta* meta)
+{
+ add_meta(meta->alias, *meta);
+}
+
+void
+ImageManager::load_path(const boost::filesystem::path& p)
+{
+ using boost::filesystem::path;
+ log::BufferedStream logstream;
+ path mf = p / "textures" / "meta";
+ logstream << (boost::format("Loading Image metadata from
'%1%'")%mf.native_file_string()).str() << log::commit;
+
+
+ texture_meta_parse(mf,
+ boost::bind(&ImageManager::meta_add,this,_1)
+ );
+
+}
+
void
Texture::allocate_gltex(void)
{
glGenTextures(1,&tex_id);
}
+Texture::Texture(const TextureMeta& tm)
+{
+ const TextureMeta* meta = &tm;
+ Magick::Image XI(meta->filepath.native_file_string());
+ log::BufferedStream logstream(log::Level::DEBUG);
+ Magick::ImageType image_type = XI.type();
+ unsigned Depth;
+ GLint format = 0;
+ std::string Type;
+ switch (image_type)
+ {
+ case Magick::TrueColorType:
+ case Magick::PaletteType:
+ {
+ format = GL_RGB;
+ Type="RGB";
+ Depth = 24;
+ break;
+ }
+
+ case Magick::TrueColorMatteType:
+ case Magick::PaletteMatteType:
+ {
+ format = GL_RGBA;
+ Type="RGBA";
+ Depth = 32;
+ break;
+ }
+
+ case Magick::GrayscaleType:
+ {
+ }
+
+ default:
+ {
+ throw std::runtime_error("Unsupported image pixel
layout");
+ }
+
+ }
+
+ Pixmap pb(XI.columns(),XI.rows(),Depth,Type);
+ XI.write(0,0,pb.width(), pb.height(),
pb.format(),Magick::CharPixel,pb.get_pixels());
+ glBindTexture(GL_TEXTURE_2D, tex_id);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
+ gluBuild2DMipmaps(GL_TEXTURE_2D, format, pb.width(), pb.height(),
format, GL_UNSIGNED_BYTE,pb.get_pixels());
+
+ return;
+
+}
Texture::Texture (const TextureMeta* meta)
{
- [Usata-commits] Changes to usata2/src/texture.cpp, David Lau, 2005/01/15
- [Usata-commits] Changes to usata2/src/texture.cpp,
David Lau <=
- [Usata-commits] Changes to usata2/src/texture.cpp, David Lau, 2005/01/19
- [Usata-commits] Changes to usata2/src/texture.cpp, David Lau, 2005/01/19
- [Usata-commits] Changes to usata2/src/texture.cpp, David Lau, 2005/01/19
- [Usata-commits] Changes to usata2/src/texture.cpp, David Lau, 2005/01/20
- [Usata-commits] Changes to usata2/src/texture.cpp, David Lau, 2005/01/25
- [Usata-commits] Changes to usata2/src/texture.cpp, David Lau, 2005/01/25