/*] 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 // FILE #include // strncmp #include #include #include #include #include "dispatcher.hh" #include "log.hh" #include "opengl.hh" #include "sprite.hh" namespace moof { sprite::sprite(const std::string& name, int tile) { image(name); sprite::tile(tile); } sprite::sprite(const image_handle& image, int tile) : image_(image) { sprite::tile(tile); } sprite::sprite(const sprite& sprite, int tile) { // FIXME broken image_ = sprite.image_; } void sprite::image(const std::string& name) { image_ = resource::load(name, "png"); } 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