]>
Dogcows Code - chaz/yoink/blob - src/moof/sprite.cc
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
10 #include <cstdio> // FILE
11 #include <cstring> // strncmp
14 #include <boost/algorithm/string.hpp>
15 #include <boost/bind.hpp>
16 #include <stlplus/portability/file_system.hpp>
18 #include "dispatcher.hh"
27 sprite::sprite(const std::string
& name
, int tile
)
33 sprite::sprite(const image_handle
& image
, int tile
) :
39 sprite::sprite(const sprite
& sprite
, int tile
)
42 image_
= sprite
.image_
;
45 void sprite::image(const std::string
& name
)
47 image_
= resource::load(name
, "png");
50 void sprite::tile(int tile
)
52 if (image_
) image_
->tile_coordinates(tile
, tile_
);
55 void sprite::bind() const
57 if (image_
) image_
->bind();
60 void sprite::reset_binding()
62 image::reset_binding();
65 void sprite::draw(const vector3 vertices
[4]) const
69 glVertexPointer(3, GL_SCALAR
, 0, vertices
[0].data());
70 glTexCoordPointer(2, GL_SCALAR
, 0, tile_
);
72 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
76 void min_filter(GLuint filter)
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
83 void mag_filter(GLuint filter)
87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
90 void wrap_s(GLuint wrap)
94 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
97 void wrap_t(GLuint wrap)
101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
104 bool sprite::tile_coordinates(int index, scalar coords[8],
105 orientation orientation) const
107 if (tile_coordinates(index, coords))
109 if (orientation & flip)
111 // this looks kinda weird, but it's just swapping in a way that
112 // doesn't require an intermediate variable
113 coords[1] = coords[5];
114 coords[5] = coords[3];
115 coords[3] = coords[7];
116 coords[7] = coords[5];
118 if (orientation & reverse)
120 coords[0] = coords[2];
121 coords[2] = coords[6];
122 coords[4] = coords[6];
123 coords[6] = coords[0];
This page took 0.034096 seconds and 4 git commands to generate.