COMMAND_CCLD = $(COMPILE) $(CC) $(CFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
COMMAND_CXXLD = $(COMPILE) $(CXX) $(CXXFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
COMMAND_AR = $(AR) rcs $@ $^; $(RANLIB) $@
-COMMAND_RC = $(WINDRES) $(DDEFINES) $(DF_TGT) -o $@ -i $<
+COMMAND_RC = $(WINDRES) -I. $(DF_TGT) -o $@ -i $<
COMMAND_INSTALL = ./tools/install.sh -m $1 $2 -d $3
COMMAND_RM = rm -f $1
COMMAND_IN = sed -f config.sed <"$1" >"$2"
else
DO_CC = @echo " CC $@"; $(COMMAND_CC)
DO_CXX = @echo " CXX $@"; $(COMMAND_CXX)
-DO_LD = @echo " LD $@"; $(COMMAND_LD)
-DO_LDX = @echo " LD $@"; $(COMMAND_LDX)
-DO_CCLD = @echo " CCLD $@"; $(COMMAND_CCLD)
-DO_CXXLD = @echo " CXXLD $@"; $(COMMAND_CXXLD)
+DO_LD = @echo " LINK $@"; $(COMMAND_LD)
+DO_LDX = @echo " LINK $@"; $(COMMAND_LDX)
+DO_CCLD = @echo " LINK $@"; $(COMMAND_CCLD)
+DO_CXXLD = @echo " LINK $@"; $(COMMAND_CXXLD)
DO_AR = @echo " AR $@"; $(COMMAND_AR)
DO_RC = @echo " RC $@"; $(COMMAND_RC)
DO_INSTALL = @echo " CP $2"; $(COMMAND_INSTALL)
DO_RM = @echo " RM $1"; $(COMMAND_RM)
-DO_IN = @echo " MAKE $2"; $(COMMAND_IN)
+DO_IN = @echo " GEN $2"; $(COMMAND_IN)
SHELL_LINE_PREFIX = @
endif
-- Setup a temporary file to collect error messages.
--
-error_log = "config.log"
-os.remove(error_log)
+config_log = "config.log"
+os.remove(config_log)
--
for _,value in ipairs(arg) do
print("fatal: "..tostring(value))
end
- if file_exists(error_log) then
+ if file_exists(config_log) then
print()
print("Look through the file `config.log' for more information:\n")
- os.execute("tail "..error_log)
+ os.execute("tail "..config_log)
end
os.exit(1)
end
-- Execute a command and return its output or nil if the command failed to
-- run.
function backtick_run(command)
- local fd = io.popen(command.." 2>>"..error_log)
+ os.execute("echo '# "..command.."' >>"..config_log)
+ local fd = io.popen(command.." 2>>"..config_log)
if fd then
local stdout = fd:read("*l")
fd:close()
-- Try to execute a command and return true if the command finished
-- successfully (with an exit code of zero).
function try_run(command)
- return os.execute(command.." >/dev/null 2>>"..error_log) == 0
+ os.execute("echo '# "..command.."' >>"..config_log)
+ return os.execute(command.." >/dev/null 2>>"..config_log) == 0
end
-- Remove the whitespace surrounding a string.
end
-- Check for CXX.
-tmpname = os.tmpname()..".c"
+tmpname = os.tmpname()..".cpp"
tmpfile, err = io.open(tmpname, "w")
if tmpfile then
tmpfile:write([[
aabb_.init(a, b);
sphere_.init(center, a);
+
+ int frame = animation.getFrame();
+ tilemap.tile(frame);
}
void Character::draw(moof::scalar alpha) const
{
moof::state2 state = moof::rigid_body2::state(alpha);
- moof::vector2 position = state.position;
-
- //glColor3f(1.0f, 1.0f, 1.0f);
- tilemap.bind();
-
- int frame = animation.getFrame();
- moof::texture::orientation orientation = moof::texture::normal;
+ const moof::vector2& position = state.position;
- if (state_.velocity[0] < 0.0) orientation = moof::texture::reverse;
+ const moof::scalar s = 0.5;
- moof::scalar coords[8];
- tilemap.tile_coordinates(frame, coords, orientation);
+ moof::vector3 coords[4];
- moof::scalar s = 0.5;
+ coords[0] = moof::vector3(position[0] - s, position[1] - s, SCALAR(0.0));
+ coords[1] = moof::vector3(position[0] + s, position[1] - s, SCALAR(0.0));
+ coords[2] = moof::vector3(position[0] + s, position[1] + s, SCALAR(0.0));
+ coords[3] = moof::vector3(position[0] - s, position[1] + s, SCALAR(0.0));
- glBegin(GL_TRIANGLE_FAN);
- glTexCoord(coords[0], coords[1]);
- glVertex(position[0]-s, position[1]-s);
- glTexCoord(coords[2], coords[3]);
- glVertex(position[0]+s, position[1]-s);
- glTexCoord(coords[4], coords[5]);
- glVertex(position[0]+s, position[1]+s);
- glTexCoord(coords[6], coords[7]);
- glVertex(position[0]-s, position[1]+s);
- glEnd();
+ tilemap.draw(coords);
}
#include <moof/math.hh>
#include <moof/rigid_body.hh>
#include <moof/sphere.hh>
-#include <moof/texture.hh>
+#include <moof/sprite.hh>
#include "Animation.hh"
//virtual int getOctant(const moof::Aabb<3>& aabb) const;
- moof::texture tilemap;
- Animation animation;
+ moof::sprite tilemap;
+ Animation animation;
};
state_.camera.upload_to_gl(alpha);
// DRAW THE SCENE
- moof::texture::reset_binding();
+ moof::image::reset_binding();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
#include "Hud.hh"
-ProgressBar::ProgressBar(const moof::texture& tilemap, int index) :
+ProgressBar::ProgressBar(const moof::sprite& tilemap, int index) :
mProgress(0.0),
- mTilemap(tilemap)
+ mTilemap(tilemap, index)
{
- tilemap.tile_coordinates(index, mTexCoords);
-
+ // TODO this is now broken
moof::scalar half = (mTexCoords[2] - mTexCoords[0]) / 2.0 + mTexCoords[0];
mMidCoords[0] = half - 0.01;
mMidCoords[1] = half + 0.01;
Hud::Hud(GameState& state) :
state_(state),
- mBar1(moof::texture("StatusBars"), 0),
- mBar2(moof::texture("StatusBars"), 2),
+ mBar1(moof::sprite("StatusBars"), 0),
+ mBar2(moof::sprite("StatusBars"), 2),
mFont("Font")
{
moof::video* video = moof::video::current();
#include <moof/drawable.hh>
#include <moof/math.hh>
//#include <moof/rectangle.hh>
-#include <moof/texture.hh>
+#include <moof/sprite.hh>
#include <moof/view.hh>
#include "GameState.hh"
{
public:
- ProgressBar(const moof::texture& tilemap, int index);
+ ProgressBar(const moof::sprite& tilemap, int index);
void resize(const moof::rectangle& rect);
moof::vector2 mVertices[8];
moof::scalar mWidth;
- moof::texture mTilemap;
+ moof::sprite mTilemap;
moof::scalar mTexCoords[8];
moof::scalar mMidCoords[2];
};
ProgressBar mBar2;
unsigned mNumber;
- moof::texture mFont;
+ moof::sprite mFont;
moof::matrix4 mProjection;
};
#ifdef YOINK_GITHEAD
<< " Commit: "YOINK_GITHEAD << std::endl
#endif
- << " Version: "PACKAGE_VERSION << std::endl
+ << " Version: " << PACKAGE_VERSION << std::endl
<< " Built: " << COMPILE_TIME << std::endl
- << " Compiler: "COMPILER_STRING << std::endl
+ << " Compiler: " << COMPILER_STRING << std::endl
<< " Assets: " << assets << std::endl
<< "Build options: "
#ifndef HAVE_CLOCK_GETTIME
}
+#include <moof/image.hh>
+#include <moof/backend.hh>
+#include <moof/sprite.hh>
+
+
int main(int argc, char* argv[])
{
+ //moof::backend backend;
+ //moof::resource::add_search_paths(Main::getSearchPath());
+
+ //moof::image hey("textures/AlienWarrior.png");
+
+ //return 0;
+
+
// FIXME: This is temporary.
moof::timer reloadTimer(boost::bind(&moof::resource::reload_as_needed),
SCALAR(2.0),
try
{
- std::string iconPath(PACKAGE".png");
- iconPath = moof::resource::find_file(iconPath);
- moof::image icon(iconPath);
- icon.set_as_icon();
+ //std::string iconPath(PACKAGE".png");
+ //iconPath = moof::resource::find_file(iconPath);
+ //moof::image icon(iconPath);
+ //icon.set_as_icon();
+ moof::image_handle icon(PACKAGE".png");
+ if (icon) icon->set_as_icon();
class moof::video::attributes attributes(settings);
moof::video video(PACKAGE_STRING, attributes);
#include <moof/math.hh>
#include <moof/script.hh>
#include <moof/settings.hh>
-#include <moof/texture.hh>
+#include <moof/sprite.hh>
#include "Character.hh"
#include "Scene.hh"
Quad(const moof::vector3* vertices[4],
const std::string& texture,
int tileIndex) :
- mTilemap(texture),
+ mTilemap(texture, tileIndex),
mBlending(false),
mFog(false),
mSurface(NONE)
//}
}
- if (!mTilemap.tile_coordinates(tileIndex, mTexCoords))
- {
- moof::log_warning << "no index " << tileIndex <<
- " in texture " << texture << std::endl;
-
- mTexCoords[0] = mTexCoords[1] =
- mTexCoords[3] = mTexCoords[6] = 0.0;
- mTexCoords[2] = mTexCoords[4] =
- mTexCoords[5] = mTexCoords[7] = 1.0;
- }
-
aabb_.enclose_vertices(mVertices, 4);
sphere_.point = aabb_.center();
sphere_.radius = (aabb_.min - sphere_.point).length();
}
//glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- mTilemap.bind();
-
- glVertexPointer(3, GL_SCALAR, 0, mVertices[0].data());
- glTexCoordPointer(2, GL_SCALAR, 0, mTexCoords);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ mTilemap.draw(mVertices);
glDisable(GL_BLEND);
glDisable(GL_FOG);
}
- moof::vector3 mVertices[4];
- moof::scalar mTexCoords[8];
+ moof::vector3 mVertices[4];
- moof::texture mTilemap;
+ moof::sprite mTilemap;
bool mBlending;
bool mFog;
- moof::matrix4 mTransform;
- std::string mTexture;
+ moof::matrix4 mTransform;
+ std::string mTexture;
std::list< boost::shared_ptr<impl::Quad> > mObjects;
std::list<moof::line2> mLines;
vertices[h][wPlus1] = moof::demote(mTransform *
moof::vector4(wPlus1, h, 0.0, 1.0));
- if (index == moof::texture::no_tile) continue;
+ if (index == moof::image::no_tile) continue;
const moof::vector3* corners[4] = {
&vertices[h][w],
#include "TilemapFont.hh"
+/*
TilemapFont::TilemapFont() :
moof::texture("Font") {}
moof::texture::tile_coordinates(index, coords, what);
}
+*/
* Text on the screen.
*/
-#include <moof/texture.hh>
+#include <moof/sprite.hh>
+/*
class TilemapFont : public moof::texture
{
public:
void tile_coordinates(char symbol, moof::scalar coords[8],
moof::texture::orientation what = moof::texture::normal);
};
+*/
#endif // _TILEMAPFONT_HH_
#include <moof/shape.hh>
#include <moof/frustum.hh> // FIXME: this file is quite broken
+#include <moof/image.hh>
#include <moof/opengl.hh>
-#include <moof/texture.hh>
namespace moof {
glVertexPointer(3, GL_SCALAR, 0, vertices);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- texture::reset_binding();
+ image::reset_binding();
glDrawElements(GL_QUADS, sizeof(indices), GL_UNSIGNED_BYTE,
indices);
#include <cstdio> // FILE
#include <cstring> // strncmp
-
-#include <boost/algorithm/string.hpp>
+#include <stdexcept>
#include <png.h>
#include <SDL/SDL.h>
#include "backend.hh"
#include "image.hh"
#include "log.hh"
-#include "manager.hh"
+#include "opengl.hh"
+#include "script.hh"
+#include "video.hh"
namespace moof {
-class image::impl : public manager<impl>
-{
-public:
+//static int power_of_two(int input)
+//{
+ //int value = 1;
- explicit impl() :
- context_(0),
- pixels_(0) {}
-
- ~impl()
- {
- SDL_FreeSurface(context_);
- delete[] pixels_;
- }
+ //while (value < input)
+ //{
+ //value <<= 1;
+ //}
+ //return value;
+//}
+unsigned image::global_object_ = 0;
- void flip()
- {
- unsigned char* pixels = (Uint8*)(context_->pixels);
- unsigned pitch = context_->pitch;
- unsigned char line[pitch];
+image::image(const std::string& path) :
+ pixels_(0),
+ object_(0),
+ min_filter_(GL_NEAREST),
+ mag_filter_(GL_NEAREST),
+ wrap_s_(GL_CLAMP),
+ wrap_t_(GL_CLAMP),
+ tile_width_(1),
+ tile_height_(1)
+{
+ FILE* fp = resource::open_file(path);
+ if (!fp) throw std::runtime_error("image not found at " + path);
- int yBegin = 0;
- int yEnd = context_->h - 1;
+ png_byte signature[8];
+ size_t bytesRead;
- if (SDL_MUSTLOCK(context_)) SDL_LockSurface(context_);
- while (yBegin < yEnd)
- {
- memcpy(line, pixels + pitch * yBegin, pitch);
- memcpy(pixels + pitch * yBegin, pixels + pitch * yEnd, pitch);
- memcpy(pixels + pitch * yEnd, line, pitch);
- yBegin++;
- yEnd--;
- }
- if (SDL_MUSTLOCK(context_)) SDL_UnlockSurface(context_);
- }
+ png_infop pngInfo = 0;
+ png_infop pngInfoEnd = 0;
+ png_structp pngObj = 0;
- void set_as_icon() const
- {
- SDL_WM_SetIcon(context_, 0);
- }
+ int bpp;
+ png_byte colors;
+ png_bytepp rows = 0;
- void init(const std::string& name, bool flipped = false)
- {
- std::string path(name);
+ png_textp texts = 0;
+ int nutext_s;
- FILE* fp = resource::open_file(path);
- if (!fp) return;
+ bytesRead = fread(signature, 1, sizeof(signature), fp);
+ if (bytesRead < sizeof(signature) ||
+ png_sig_cmp(signature, 0, sizeof(signature)) != 0) goto cleanup;
- png_byte signature[8];
- size_t bytesRead;
+ pngObj = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
+ if (!pngObj) goto cleanup;
- png_infop pngInfo = 0;
- png_infop pngInfoEnd = 0;
- png_structp pngObj = 0;
+ pngInfo = png_create_info_struct(pngObj);
+ if (!pngInfo) goto cleanup;
- int width;
- int height;
- int pitch;
- int bpp;
- int channels;
+ pngInfoEnd = png_create_info_struct(pngObj);
+ if (!pngInfoEnd) goto cleanup;
- png_byte colors;
- png_bytepp rows = 0;
+ if (setjmp(png_jmpbuf(pngObj))) goto cleanup;
- png_textp texts = 0;
- int nutext_s;
+ png_init_io(pngObj, fp);
+ png_set_sig_bytes(pngObj, sizeof(signature));
+ png_read_info(pngObj, pngInfo);
- bytesRead = fread(signature, 1, sizeof(signature), fp);
- if (bytesRead < sizeof(signature) ||
- png_sig_cmp(signature, 0, sizeof(signature)) != 0) goto cleanup;
+ bpp = png_get_bit_depth(pngObj, pngInfo);
+ colors = png_get_color_type(pngObj, pngInfo);
+ switch (colors)
+ {
+ case PNG_COLOR_TYPE_PALETTE:
+ png_set_palette_to_rgb(pngObj);
+ break;
- pngObj = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
- if (!pngObj) goto cleanup;
+ case PNG_COLOR_TYPE_GRAY:
+ if (bpp < 8) png_set_expand(pngObj);
+ break;
- pngInfo = png_create_info_struct(pngObj);
- if (!pngInfo) goto cleanup;
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ png_set_gray_to_rgb(pngObj);
+ break;
+ }
- pngInfoEnd = png_create_info_struct(pngObj);
- if (!pngInfoEnd) goto cleanup;
+ if (bpp == 16) png_set_strip_16(pngObj);
- if (setjmp(png_jmpbuf(pngObj))) goto cleanup;
+ png_read_update_info(pngObj, pngInfo);
- png_init_io(pngObj, fp);
- png_set_sig_bytes(pngObj, sizeof(signature));
- png_read_info(pngObj, pngInfo);
+ bpp = png_get_bit_depth(pngObj, pngInfo);
+ channels_ = png_get_channels(pngObj, pngInfo);
+ depth_ = bpp * channels_;
- bpp = png_get_bit_depth(pngObj, pngInfo);
- colors = png_get_color_type(pngObj, pngInfo);
- switch (colors)
+ // read comments
+ png_get_text(pngObj, pngInfo, &texts, &nutext_s);
+ for (int i = 0; i < nutext_s; ++i)
+ {
+ if (strncmp(texts[i].key, "TextureInfo", 11) == 0)
{
- case PNG_COLOR_TYPE_PALETTE:
- png_set_palette_to_rgb(pngObj);
- break;
-
- case PNG_COLOR_TYPE_GRAY:
- if (bpp < 8) png_set_expand(pngObj);
- break;
-
- case PNG_COLOR_TYPE_GRAY_ALPHA:
- png_set_gray_to_rgb(pngObj);
- break;
+ set_texture_info(texts[i].text);
+ break;
}
+ }
- if (bpp == 16) png_set_strip_16(pngObj);
+ width_ = png_get_image_width(pngObj, pngInfo);
+ height_ = png_get_image_height(pngObj, pngInfo);
- png_read_update_info(pngObj, pngInfo);
+ pitch_ = png_get_rowbytes(pngObj, pngInfo);
+ pixels_ = new char[width_ * pitch_];
- bpp = png_get_bit_depth(pngObj, pngInfo);
- channels = png_get_channels(pngObj, pngInfo);
- depth_ = bpp * channels;
+ rows = new png_bytep[height_];
+ for (int i = 0; i < height_; ++i)
+ {
+ rows[i] = (png_bytep)(pixels_ + i * channels_ * width_);
+ }
- if (channels == 3) color_mode_ = GL_RGB;
- else color_mode_ = GL_RGBA;
-
- // read comments
- png_get_text(pngObj, pngInfo, &texts, &nutext_s);
- for (int i = 0; i < nutext_s; ++i)
- {
- if (strncmp(texts[i].key, "TextureInfo", 11) == 0)
- {
- comment_ = texts[i].text;
- break;
- }
- }
+ png_read_image(pngObj, rows);
+ png_read_end(pngObj, 0);
- width = png_get_image_width(pngObj, pngInfo);
- height = png_get_image_height(pngObj, pngInfo);
+cleanup:
- pitch = png_get_rowbytes(pngObj, pngInfo);
- pixels_ = new char[width * pitch];
+ delete[] rows;
+ png_destroy_read_struct(pngObj ? &pngObj : 0,
+ pngInfo ? &pngInfo : 0,
+ pngInfoEnd ? &pngInfoEnd : 0);
+ fclose(fp);
+}
- rows = new png_bytep[height];
- if (flipped)
- {
- for (int i = 0; i < height; ++i)
- {
- rows[height - 1 - i] = (png_bytep)(pixels_ +
- i * channels * width);
- }
- }
- else
- {
- for (int i = 0; i < height; ++i)
- {
- rows[i] = (png_bytep)(pixels_ + i * channels * width);
- }
- }
+image::~image()
+{
+ unload_from_gl();
+ delete[] pixels_;
+}
- png_read_image(pngObj, rows);
- png_read_end(pngObj, 0);
- context_ = SDL_CreateRGBSurfaceFrom
- (
- pixels_,
- width,
- height,
- bpp * channels,
- pitch,
+void image::set_as_icon() const
+{
+ backend backend;
+
+ SDL_Surface* context = SDL_CreateRGBSurfaceFrom
+ (
+ pixels_,
+ width_,
+ height_,
+ depth_,
+ pitch_,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
- 0x000000FF,
- 0x0000FF00,
- 0x00FF0000,
- 0xFF000000
+ 0x000000FF,
+ 0x0000FF00,
+ 0x00FF0000,
+ 0xFF000000
#else
- 0xFF000000,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF
+ 0xFF000000,
+ 0x00FF0000,
+ 0x0000FF00,
+ 0x000000FF
#endif
- );
-
- cleanup:
-
- delete[] rows;
- png_destroy_read_struct(pngObj ? &pngObj : 0,
- pngInfo ? &pngInfo : 0,
- pngInfoEnd ? &pngInfoEnd : 0);
- fclose(fp);
- }
-
-
- SDL_Surface* context_;
- char* pixels_;
-
- unsigned depth_;
- GLuint color_mode_;
+ );
- std::string comment_;
+ SDL_WM_SetIcon(context, 0);
-private:
-
- backend backend_;
-};
-
-
-image::image(const std::string& name) :
- // pass through
- impl_(image::impl::instance(name)) {}
+ SDL_FreeSurface(context);
+}
-bool image::is_valid() const
+bool image::tile_coordinates(int index, scalar coords[8]) const
{
- return impl_->context_;
+ // make sure the index represents a real tile
+ if (index < 0 && index >= tile_width_ * tile_height_) return false;
+
+ scalar w = 1.0 / scalar(tile_width_);
+ scalar h = 1.0 / scalar(tile_height_);
+
+ coords[0] = scalar(index % tile_width_) * w;
+ coords[1] = (scalar(tile_height_ - 1) - scalar(index / tile_width_)) * h;
+ coords[2] = coords[0] + w;
+ coords[3] = coords[1];
+ coords[4] = coords[2];
+ coords[5] = coords[1] + h;
+ coords[6] = coords[0];
+ coords[7] = coords[5];
+
+ return true;
}
-int image::width() const
-{
- return impl_->context_->w;
-}
-int image::height() const
+void image::bind() const
{
- return impl_->context_->h;
-}
+ ASSERT(video::current() && "should have a video context set");
-unsigned image::depth() const
-{
- return impl_->depth_;
+ if (object_ == 0)
+ {
+ upload_to_gl();
+ }
+ if (object_ != global_object_)
+ {
+ glBindTexture(GL_TEXTURE_2D, (GLuint)object_);
+ global_object_ = object_;
+ }
}
-unsigned image::pitch() const
+void image::reset_binding()
{
- return impl_->context_->pitch;
+ ASSERT(video::current() && "should have a video context set");
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+ global_object_ = 0;
}
-GLuint image::mode() const
+
+/*
+ * Upload the image to GL so that it will be accessible by a much more
+ * manageable handle and hopefully reside in video memory.
+ */
+void image::upload_to_gl() const
{
- return impl_->color_mode_;
+ if (object_)
+ {
+ // already loaded
+ return;
+ }
+
+ glGenTextures(1, (GLuint*)&object_);
+ glBindTexture(GL_TEXTURE_2D, (GLuint)object_);
+
+ GLuint mode;
+ if (channels_ == 3) mode = GL_RGB;
+ else mode = GL_RGBA;
+
+ glTexImage2D
+ //gluBuild2DMipmaps
+ (
+ GL_TEXTURE_2D,
+ 0,
+ mode,
+ //3,
+ width_,
+ height_,
+ 0,
+ mode,
+ GL_UNSIGNED_BYTE,
+ pixels_
+ );
+
+ set_properties();
+
+ // we want to know when the GL context is recreated
+ //dispatcher& dispatcher = dispatcher::global();
+ //new_context_ = dispatcher.add_target("video.newcontext",
+ //boost::bind(&image::context_recreated, this));
+ // FIXME this has const issues
}
-std::string image::comment() const
+void image::unload_from_gl() const
{
- return impl_->comment_;
+ if (object_)
+ {
+ if (object_ == global_object_)
+ {
+ global_object_ = 0;
+ }
+
+ glDeleteTextures(1, (GLuint*)&object_);
+ object_ = 0;
+ }
}
-const char* image::pixels() const
+void image::context_recreated()
{
- return impl_->pixels_;
+ object_ = global_object_ = 0;
+ upload_to_gl();
}
-char* image::pixels()
+/*
+ * Sets some texture properties such as the filters and external
+ * coordinate behavior.
+ */
+void image::set_properties() const
{
- return impl_->pixels_;
+ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_);
+ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_);
+ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_);
+ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_);
}
-void image::flip()
+void image::set_texture_info(const std::string& info)
{
- // pass through
- impl_->flip();
+ script script;
+ log::import(script);
+
+ script::slot g = script.globals();
+ g.set_field("CLAMP", GL_CLAMP);
+ g.set_field("REPEAT", GL_REPEAT);
+ g.set_field("LINEAR", GL_LINEAR);
+ g.set_field("NEAREST", GL_NEAREST);
+ g.set_field("LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR);
+ g.set_field("LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST);
+ g.set_field("NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR);
+ g.set_field("NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST);
+
+ if (script.do_string(info) != script::success)
+ {
+ std::string str;
+ script[-1].get(str);
+ log_warning(str);
+ }
+ else
+ {
+ log_info("loading texture information...");
+
+ script::slot globals = script.globals();
+ globals.get(tile_width_, "tiles_s");
+ globals.get(tile_height_, "tiles_t");
+ globals.get(min_filter_, "min_filter");
+ globals.get(mag_filter_, "mag_filter");
+ globals.get(wrap_s_, "wrap_s");
+ globals.get(wrap_t_, "wrap_t");
+ }
}
-void image::set_as_icon() const
+
+class image_resource_loader
{
- // pass through
- impl_->set_as_icon();
-}
+public:
+
+ image_resource_loader()
+ {
+ resource::register_type<image>("png");
+ }
+
+ ~image_resource_loader()
+ {
+ resource::unregister_type("png");
+ }
+};
+
+static image_resource_loader loader;
} // namespace moof
* Defines classes for loading and manipulating images.
*/
-#include <boost/shared_ptr.hpp>
+#include <boost/noncopyable.hpp>
-#include <moof/opengl.hh>
+#include <moof/dispatcher.hh>
+#include <moof/math.hh>
#include <moof/resource.hh>
namespace moof {
-class image;
-typedef boost::shared_ptr<image> image_ptr;
-
-class image : public resource
+class image : public boost::noncopyable
{
public:
- static image_ptr alloc(const std::string& name)
+ static const int no_tile = -1;
+
+
+ explicit image(const std::string& path);
+
+ ~image();
+
+ int width() const
{
- return image_ptr(new image(name));
+ return width_;
}
- explicit image(const std::string& name);
+ int height() const
+ {
+ return height_;
+ }
- bool is_valid() const;
+ int depth() const
+ {
+ return depth_;
+ }
- int width() const;
- int height() const;
+ int pitch() const
+ {
+ return pitch_;
+ }
- unsigned depth() const;
- unsigned pitch() const;
- GLuint mode() const;
+ int channels() const
+ {
+ return channels_;
+ }
- std::string comment() const;
- const char* pixels() const;
- char* pixels();
+ std::string comment() const
+ {
+ return comment_;
+ }
+
+ const char* pixels() const
+ {
+ return pixels_;
+ }
- void flip();
void set_as_icon() const;
+ /**
+ * Calculate texture coordinates for a tile at a certain index. Tiles
+ * are indexed start with zero as the top-left tile and moving across,
+ * then down.
+ * \param index The tile index.
+ * \param coords An array of scalars where the texture coordinates will
+ * be stored after this call. The first coordinate (u,v) will be in
+ * the first two places and so on until all four coordinates are
+ * stored, therefore requiring enough room for an array of eight
+ * scalars. The winding of the coordinates is always counter-clockwise
+ * (the GL default).
+ * \return True if index is valid, false otherwise.
+ */
+ bool tile_coordinates(int index, scalar coords[8]) const;
+
+
+ void bind() const;
+ static void reset_binding();
+
+
private:
- static FILE* open_file(std::string& name);
+ void upload_to_gl() const;
+ void unload_from_gl() const;
+ void context_recreated();
+ void set_properties() const;
+ void set_texture_info(const std::string& info);
- class impl;
- boost::shared_ptr<impl> impl_;
+
+ char* pixels_;
+
+ mutable unsigned object_;
+ static unsigned global_object_;
+
+ int width_;
+ int height_;
+ int depth_;
+ int pitch_;
+ int channels_;
+
+ std::string comment_;
+
+ unsigned min_filter_;
+ unsigned mag_filter_;
+ unsigned wrap_s_;
+ unsigned wrap_t_;
+ int tile_width_;
+ int tile_height_;
+
+ //mutable dispatcher::handle new_context_;
};
+typedef resource_handle<image> image_handle;
+
} // namespace moof
#include <moof/contact.hh>
#include <moof/drawable.hh>
+#include <moof/image.hh>
#include <moof/log.hh>
#include <moof/math.hh>
#include <moof/opengl.hh>
#include <moof/ray.hh>
#include <moof/shape.hh>
#include <moof/sphere.hh>
-#include <moof/texture.hh>
namespace moof {
void draw(scalar alpha = 0.0) const
{
- texture::reset_binding();
+ image::reset_binding();
glBegin(GL_LINES);
glVertex(a);
glVertex(b);
void draw(scalar alpha = 0.0) const
{
- texture::reset_binding();
+ image::reset_binding();
glBegin(GL_POLYGON);
for (int i = 0; i < D; ++i)
{
*/
#include <moof/drawable.hh>
+#include <moof/image.hh>
#include <moof/math.hh>
#include <moof/opengl.hh>
-#include <moof/texture.hh>
namespace moof {
vector end = point + 1000.0 * direction;
// FIXME: this is kinda cheesy
- moof::texture::reset_binding();
+ image::reset_binding();
glBegin(GL_LINES);
glVertex(point);
glVertex(end);
{
std::string extension = stlplus::extension_part(path);
- std::string path1 = find_file(path);
+ std::string path1 = path;
if (!find(path1))
{
log_error("trying to load missing resource:", path1);
bool resource::find(const std::string& path)
{
- std::string file = stlplus::lookup(path, search_paths_, ":");
- log_info("found file", file, "in", search_paths_);
- return !stlplus::lookup(path, search_paths_, ":").empty();
+ //std::string file = stlplus::lookup(path, search_paths_, ":");
+ //log_info("found file", file, "in", search_paths_);
+ //return !stlplus::lookup(path, search_paths_, ":").empty();
+ return find_file(path) != "";
}
std::string resource::find_file(const std::string& name)
{
- log_info("looking for", name, "in", search_paths_);
- return stlplus::lookup(name, search_paths_, ":");
+ //log_info("looking for", name, "in", search_paths_);
+ //return stlplus::lookup(name, search_paths_, ":");
+
+ std::vector<std::string> paths;
+ boost::split(paths, search_paths_, boost::is_any_of(":"));
+
+ std::vector<std::string>::iterator it;
+ for (it = paths.begin(); it != paths.end(); ++it)
+ {
+ *it += "/";
+ *it += name;
+ log_info("looking for", name, "in", *it);
+ if (stlplus::file_exists(*it)) return *it;
+ }
+
+ return std::string();
}
FILE* resource::open_file(const std::string& path, const std::string& mode)
{
- std::string file = stlplus::lookup(path, search_paths_, ":");
- return fopen(file.c_str(), mode.c_str());
+ return fopen(find_file(path).c_str(), mode.c_str());
}
resource_handle(resource_ptr ptr) :
resource_(ptr) {}
+ explicit resource_handle(const std::string& path) :
+ resource_(resource::load(path)) {}
+
/**
* Get whether or not the handle is dereferenceable to the type of this
#include <boost/algorithm/string.hpp>
#include <boost/cstdint.hpp>
+#include <boost/noncopyable.hpp>
#include <AL/al.h>
#include <AL/alc.h>
#include <vorbis/codec.h>
// SOUND RESOURCE
-class sound_resource
+class sound_resource : public boost::noncopyable
{
public:
}
- bool read(buffer& buf)
+ bool read(buffer& buf) const
{
if (buffer_)
{
}
- bool read(buffer& buf, uint64_t& sample)
+ bool read(buffer& buf, uint64_t& sample) const
{
if (ov_pcm_seek_lap(&file_, sample) != 0)
{
private:
- OggVorbis_File file_;
- buffer buffer_;
+ mutable OggVorbis_File file_;
+ mutable buffer buffer_;
};
void loop(bool looping);
- void listener_position(const vector3& position);
- void listener_velocity(const vector3& velocity);
- void listener_orientation(const vector3& forward,
- const vector3& up);
+ static void listener_position(const vector3& position);
+ static void listener_velocity(const vector3& velocity);
+ static void listener_orientation(const vector3& forward,
+ const vector3& up);
private:
--- /dev/null
+
+/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+**] All rights reserved.
+*
+* vi:ts=4 sw=4 tw=75
+*
+* Distributable under the terms and conditions of the 2-clause BSD license;
+* see the file COPYING for a complete text of the license.
+*
+**************************************************************************/
+
+#include <cstdio> // FILE
+#include <cstring> // strncmp
+#include <stdexcept>
+
+#include <boost/algorithm/string.hpp>
+#include <boost/bind.hpp>
+
+#include "dispatcher.hh"
+#include "log.hh"
+#include "opengl.hh"
+#include "sprite.hh"
+
+
+namespace moof {
+
+
+sprite::sprite(const std::string& path, int tile)
+{
+ image_ = resource::load(path);
+ image_->tile_coordinates(tile, tile_);
+}
+
+sprite::sprite(const image_handle& image, int tile) :
+ image_(image)
+{
+ image_->tile_coordinates(tile, tile_);
+}
+
+sprite::sprite(const sprite& sprite, int tile)
+{
+ // FIXME broken
+ image_ = sprite.image_;
+}
+
+
+void sprite::image(const std::string& path)
+{
+ image_ = resource::load(path);
+ // FIXME what about tiles?
+}
+
+void sprite::tile(int tile)
+{
+ if (image_) image_->tile_coordinates(tile, tile_);
+}
+
+
+void sprite::bind() const
+{
+ if (image_) image_->bind();
+}
+
+void sprite::reset_binding()
+{
+ image::reset_binding();
+}
+
+
+void sprite::draw(const vector3 vertices[4]) const
+{
+ bind();
+
+ glVertexPointer(3, GL_SCALAR, 0, vertices[0].data());
+ glTexCoordPointer(2, GL_SCALAR, 0, tile_);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+}
+
+
+/*
+ void min_filter(GLuint filter)
+ {
+ bind();
+ mMinFilter = filter;
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
+ }
+
+ void mag_filter(GLuint filter)
+ {
+ bind();
+ mMagFilter = filter;
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
+ }
+
+ void wrap_s(GLuint wrap)
+ {
+ bind();
+ mWrapS = wrap;
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
+ }
+
+ void wrap_t(GLuint wrap)
+ {
+ bind();
+ mWrapT = wrap;
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
+ }
+
+
+bool sprite::tile_coordinates(int index, scalar coords[8],
+ orientation orientation) const
+{
+ if (tile_coordinates(index, coords))
+ {
+ if (orientation & flip)
+ {
+ // this looks kinda weird, but it's just swapping in a way that
+ // doesn't require an intermediate variable
+ coords[1] = coords[5];
+ coords[5] = coords[3];
+ coords[3] = coords[7];
+ coords[7] = coords[5];
+ }
+ if (orientation & reverse)
+ {
+ coords[0] = coords[2];
+ coords[2] = coords[6];
+ coords[4] = coords[6];
+ coords[6] = coords[0];
+ }
+
+ return true;
+ }
+
+ return false;
+}
+*/
+
+
+} // namespace moof
+
--- /dev/null
+
+/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+**] All rights reserved.
+*
+* vi:ts=4 sw=4 tw=75
+*
+* Distributable under the terms and conditions of the 2-clause BSD license;
+* see the file COPYING for a complete text of the license.
+*
+**************************************************************************/
+
+#ifndef _MOOF_SPRITE_HH_
+#define _MOOF_SPRITE_HH_
+
+/**
+ * \file sprite.hh
+ * Image-loading and OpenGL texture loading.
+ */
+
+#include <string>
+
+#include <moof/image.hh>
+#include <moof/math.hh>
+
+
+namespace moof {
+
+
+class sprite
+{
+public:
+
+ sprite() {}
+ explicit sprite(const std::string& path, int tile = image::no_tile);
+ explicit sprite(const image_handle& image, int tile = image::no_tile);
+ explicit sprite(const sprite& sprite, int tile = image::no_tile);
+
+ void image(const std::string& path);
+ void tile(int tile);
+
+ void bind() const;
+ static void reset_binding();
+
+ void draw(const vector3 vertices[4]) const;
+
+
+private:
+
+ image_handle image_;
+ scalar tile_[8];
+};
+
+
+} // namespace moof
+
+#endif // _MOOF_SPRITE_HH_
+
+++ /dev/null
-
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
-**] All rights reserved.
-*
-* vi:ts=4 sw=4 tw=75
-*
-* Distributable under the terms and conditions of the 2-clause BSD license;
-* see the file COPYING for a complete text of the license.
-*
-**************************************************************************/
-
-#include <cstdio> // FILE
-#include <cstring> // strncmp
-#include <stdexcept>
-
-#include <boost/algorithm/string.hpp>
-#include <boost/bind.hpp>
-
-#include "dispatcher.hh"
-#include "manager.hh"
-#include "log.hh"
-#include "opengl.hh"
-#include "script.hh"
-#include "texture.hh"
-#include "video.hh"
-
-
-namespace moof {
-
-
-/**
- * The texture implementation just contains all the information about the
- * image which is worth having in memory. The image data itself is not
- * worth keeping in memory if the texture has been loaded to GL, but the
- * name of the resource is retained so that it can be reloaded if
- * necessary. The implementation is a manager so that multiple texture
- * objects can share the same internal objects and avoid having duplicate
- * textures loaded to GL.
- */
-
-class texture::impl : public manager<impl>
-{
-
- /**
- * Delete the texture (if it is loaded) from GL.
- */
-
- void unload_from_gl()
- {
- if (mObject)
- {
- if (mObject == gObject)
- {
- gObject = 0;
- }
-
- glDeleteTextures(1, &mObject);
- mObject = 0;
- }
- }
-
- /**
- * If the GL context was recreated, we need to reload the texture.
- * This may involve reading it from disk again, but hopefully the OS
- * was smart enough to cache it if the client has plenty of RAM.
- */
-
- void context_recreated()
- {
- mObject = gObject = 0;
- upload_to_gl();
- }
-
- /**
- * This is a helper method used by some of the texture loading code.
- * It returns the first power of two which is greater than the input
- * value.
- */
-
- static int power_of_two(int input)
- {
- int value = 1;
-
- while (value < input)
- {
- value <<= 1;
- }
- return value;
- }
-
-
- static void bind_script_constants(script& script)
- {
- script::slot g = script.globals();
-
- g.set_field("CLAMP", GL_CLAMP);
- g.set_field("REPEAT", GL_REPEAT);
- g.set_field("LINEAR", GL_LINEAR);
- g.set_field("NEAREST", GL_NEAREST);
- g.set_field("LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR);
- g.set_field("LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST);
- g.set_field("NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR);
- g.set_field("NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST);
- }
-
-public:
-
- /*
- * Construction is initialization.
- */
- impl() :
- mMinFilter(GL_NEAREST),
- mMagFilter(GL_NEAREST),
- mWrapS(GL_CLAMP),
- mWrapT(GL_CLAMP),
- mTilesS(1),
- mTilesT(1),
- mObject(0)
- {
- // make sure we have a video context
- video* video = video::current();
- ASSERT(video && "should have a video context set");
-
- // we want to know when the GL context is recreated
- dispatcher& dispatcher = dispatcher::global();
- mNewContextDispatch = dispatcher.add_target("video.newcontext",
- boost::bind(&impl::context_recreated, this));
- }
-
- ~impl()
- {
- unload_from_gl();
- }
-
-
- void init(const std::string& name)
- {
- std::string path(name);
-
- resource::find(path);
-
- mImage = image::alloc(path);
- if (!mImage->is_valid())
- {
- throw std::runtime_error("texture not found: " + name);
- }
-
- mImage->flip();
-
- script script;
-
- bind_script_constants(script);
- log::import(script);
-
- if (script.do_string(mImage->comment()) != script::success)
- {
- std::string str;
- script[-1].get(str);
- log_warning(str);
- }
- else
- {
- log_info("loading tiles from texture", path);
-
- script::slot globals = script.globals();
- globals.get(mTilesS, "tiles_s");
- globals.get(mTilesT, "tiles_t");
- globals.get(mMinFilter, "min_filter");
- globals.get(mMagFilter, "mag_filter");
- globals.get(mWrapS, "wrap_s");
- globals.get(mWrapT, "wrap_t");
- }
- }
-
-
- /*
- * Upload the image to GL so that it will be accessible by a much more
- * manageable handle and hopefully reside in video memory.
- */
- void upload_to_gl()
- {
- if (mObject)
- {
- // already loaded
- return;
- }
-
- glGenTextures(1, &mObject);
- glBindTexture(GL_TEXTURE_2D, mObject);
-
- glTexImage2D
- //gluBuild2DMipmaps
- (
- GL_TEXTURE_2D,
- 0,
- mImage->mode(),
- //3,
- mImage->width(),
- mImage->height(),
- 0,
- mImage->mode(),
- GL_UNSIGNED_BYTE,
- mImage->pixels()
- );
-
- set_properties();
- }
-
-
- /*
- * Sets some texture properties such as the filters and external
- * coordinate behavior.
- */
- void set_properties()
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
- }
-
- void min_filter(GLuint filter)
- {
- bind();
- mMinFilter = filter;
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
- }
-
- void mag_filter(GLuint filter)
- {
- bind();
- mMagFilter = filter;
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
- }
-
- void wrap_s(GLuint wrap)
- {
- bind();
- mWrapS = wrap;
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
- }
-
- void wrap_t(GLuint wrap)
- {
- bind();
- mWrapT = wrap;
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
- }
-
-
- void bind()
- {
- if (mObject == 0)
- {
- upload_to_gl();
- }
- if (mObject != gObject)
- {
- glBindTexture(GL_TEXTURE_2D, mObject);
- gObject = mObject;
- }
- }
-
-
- bool tile_coordinates(int index, scalar coords[8]) const
- {
- // make sure the index represents a real tile
- if (index < 0 && index >= mTilesS * mTilesT) return false;
-
- scalar w = 1.0 / scalar(mTilesS);
- scalar h = 1.0 / scalar(mTilesT);
-
- coords[0] = scalar(index % mTilesS) * w;
- coords[1] = (scalar(mTilesT - 1) - scalar(index / mTilesS)) * h;
- coords[2] = coords[0] + w;
- coords[3] = coords[1];
- coords[4] = coords[2];
- coords[5] = coords[1] + h;
- coords[6] = coords[0];
- coords[7] = coords[5];
-
- return true;
- }
-
- image_ptr mImage;
-
- GLuint mMinFilter; ///< Minification filter.
- GLuint mMagFilter; ///< Magnification filter.
- GLuint mWrapS; ///< Wrapping behavior horizontally.
- GLuint mWrapT; ///< Wrapping behavior vertically.
- int mTilesS;
- int mTilesT;
-
- GLuint mObject; ///< GL texture handle.
- static GLuint gObject; ///< Global GL texture handle.
-
- dispatcher::handle mNewContextDispatch;
-};
-
-GLuint texture::impl::gObject = 0;
-
-
-texture::texture(const std::string& name) : // FIXME: this is really weird
- image(name),
- // pass through
- impl_(texture::impl::instance(name)) {}
-
-
-/**
- * Bind the GL texture for mapping, etc.
- */
-
-void texture::bind() const
-{
- // pass through
- impl_->bind();
-}
-
-
-/**
- * Get the texture object, for the curious.
- */
-
-GLuint texture::object() const
-{
- // pass through
- return impl_->mObject;
-}
-
-
-void texture::reset_binding()
-{
- glBindTexture(GL_TEXTURE_2D, 0);
- impl::gObject = 0;
-}
-
-
-void texture::min_filter(GLuint filter)
-{
- // pass through
- impl_->min_filter(filter);
-}
-
-void texture::mag_filter(GLuint filter)
-{
- // pass through
- impl_->mag_filter(filter);
-}
-
-void texture::wrap_s(GLuint wrap)
-{
- // pass through
- impl_->wrap_s(wrap);
-}
-
-void texture::wrap_t(GLuint wrap)
-{
- // pass through
- impl_->wrap_t(wrap);
-}
-
-
-bool texture::tile_coordinates(int index, scalar coords[8]) const
-{
- // pass through
- return impl_->tile_coordinates(index, coords);
-}
-
-bool texture::tile_coordinates(int index, scalar coords[8],
- orientation orientation) const
-{
- if (tile_coordinates(index, coords))
- {
- if (orientation & flip)
- {
- // this looks kinda weird, but it's just swapping in a way that
- // doesn't require an intermediate variable
- coords[1] = coords[5];
- coords[5] = coords[3];
- coords[3] = coords[7];
- coords[7] = coords[5];
- }
- if (orientation & reverse)
- {
- coords[0] = coords[2];
- coords[2] = coords[6];
- coords[4] = coords[6];
- coords[6] = coords[0];
- }
-
- return true;
- }
-
- return false;
-}
-
-
-} // namespace moof
-
+++ /dev/null
-
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
-**] All rights reserved.
-*
-* vi:ts=4 sw=4 tw=75
-*
-* Distributable under the terms and conditions of the 2-clause BSD license;
-* see the file COPYING for a complete text of the license.
-*
-**************************************************************************/
-
-#ifndef _MOOF_TEXTURE_HH_
-#define _MOOF_TEXTURE_HH_
-
-/**
- * \file texture.hh
- * Image-loading and OpenGL texture loading.
- */
-
-#include <string>
-
-#include <boost/shared_ptr.hpp>
-
-#include <moof/image.hh>
-#include <moof/opengl.hh>
-
-
-namespace moof {
-
-
-class texture;
-typedef boost::shared_ptr<texture> texture_ptr;
-
-
-class texture : public image
-{
-public:
-
- static const int no_tile = -1;
-
- /**
- * Possible orientations for texture coordinates.
- */
- typedef enum
- {
- normal = 0, ///< Normal orientation.
- flip = 1, ///< Flip over a horizontal axis.
- reverse = 2, ///< Flip over a vertical axis.
- flip_and_reverse = 3 ///< Flip over both.
- } orientation;
-
-
- static texture_ptr alloc(const std::string& name)
- {
- return texture_ptr(new texture(name));
- }
-
- explicit texture(const std::string& name);
-
- void bind() const;
- GLuint object() const;
-
- static void reset_binding();
-
- void min_filter(GLuint filter);
- void mag_filter(GLuint filter);
- void wrap_s(GLuint wrap);
- void wrap_t(GLuint wrap);
-
-
- /**
- * Calculate texture coordinates for a tile at a certain index. Tiles
- * are indexed start with zero as the to-left tile and moving across,
- * then down.
- * \param index The tile index.
- * \param coords An array of scalars where the texture coordinates will
- * be stored after this call. The first coordinate (u,v) will be in
- * the first two places and so on until all four coordinates are
- * stored, therefore requiring enough room for an array of eight
- * scalars. The winding of the coordinates is always counter-clockwise
- * (the GL default).
- * \return True if index is valid, false otherwise.
- */
- bool tile_coordinates(int index, scalar coords[8]) const;
-
- /**
- * This version let's you specify an orientation that will be reflected
- * in the texture coordinates. This allows you to easily map a texture
- * backwards or upside-down.
- * \param what The orientation; can be flip, reverse, or
- * flip_and_reverse.
- * \return True if index is valid, false otherwise.
- */
- bool tile_coordinates(int index, scalar coords[8], orientation what) const;
-
-
-private:
-
- class impl;
- boost::shared_ptr<impl> impl_;
-};
-
-
-} // namespace moof
-
-#endif // _MOOF_TEXTURE_HH_
-
FILEVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,0
PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
-#ifdef NDEBUG
+#if NDEBUG
FILEFLAGS 0
#else
FILEFLAGS VS_FF_DEBUG