X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fsprite.cc;fp=src%2Fmoof%2Fsprite.cc;h=7548ab0b8b7ae7b975b4f88bb1f66222240e241c;hp=0000000000000000000000000000000000000000;hb=382626aad0a683ed8642a6a807eea743db45f7f8;hpb=1da520638918096276158ecdfaeebc14a3d70be7 diff --git a/src/moof/sprite.cc b/src/moof/sprite.cc new file mode 100644 index 0000000..7548ab0 --- /dev/null +++ b/src/moof/sprite.cc @@ -0,0 +1,142 @@ + +/*] 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 "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 +