]>
Dogcows Code - chaz/yoink/blob - src/moof/sprite.cc
602fc2cbe4cfa6361f7629d7d7028f04114261a4
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>
17 #include <stlplus/portability/file_system.hpp>
19 #include "dispatcher.hh"
28 sprite::sprite(const std::string
& name
, int tile
)
34 sprite::sprite(const image_handle
& image
, int tile
) :
40 sprite::sprite(const sprite
& sprite
, int tile
)
43 image_
= sprite
.image_
;
46 void sprite::image(const std::string
& name
)
48 image_
= resource::load(name
, "png");
51 void sprite::tile(int tile
)
53 if (image_
) image_
->tile_coordinates(tile
, tile_
);
56 void sprite::bind() const
58 if (image_
) image_
->bind();
61 void sprite::reset_binding()
63 image::reset_binding();
66 void sprite::draw(const vector3 vertices
[4]) const
70 glVertexPointer(3, GL_SCALAR
, 0, vertices
[0].data());
71 glTexCoordPointer(2, GL_SCALAR
, 0, tile_
);
73 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
77 void min_filter(GLuint filter)
81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
84 void mag_filter(GLuint filter)
88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
91 void wrap_s(GLuint wrap)
95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
98 void wrap_t(GLuint wrap)
102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
105 bool sprite::tile_coordinates(int index, scalar coords[8],
106 orientation orientation) const
108 if (tile_coordinates(index, coords))
110 if (orientation & flip)
112 // this looks kinda weird, but it's just swapping in a way that
113 // doesn't require an intermediate variable
114 coords[1] = coords[5];
115 coords[5] = coords[3];
116 coords[3] = coords[7];
117 coords[7] = coords[5];
119 if (orientation & reverse)
121 coords[0] = coords[2];
122 coords[2] = coords[6];
123 coords[4] = coords[6];
124 coords[6] = coords[0];
This page took 0.035138 seconds and 4 git commands to generate.