]>
Dogcows Code - chaz/yoink/blob - src/moof/sprite.cc
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #include <cstdio> // FILE
13 #include <cstring> // strncmp
16 #include <boost/algorithm/string.hpp>
17 #include <boost/bind.hpp>
18 #include <stlplus/portability/file_system.hpp>
20 #include "dispatcher.hh"
29 sprite::sprite(const std::string
& name
, int tile
)
35 sprite::sprite(const image_handle
& image
, int tile
) :
41 sprite::sprite(const sprite
& sprite
, int tile
)
44 image_
= sprite
.image_
;
48 void sprite::image(const std::string
& name
)
50 image_
= resource::load(name
, "png");
53 void sprite::tile(int tile
)
55 if (image_
) image_
->tile_coordinates(tile
, tile_
);
59 void sprite::bind() const
61 if (image_
) image_
->bind();
64 void sprite::reset_binding()
66 image::reset_binding();
70 void sprite::draw(const vector3 vertices
[4]) const
74 glVertexPointer(3, GL_SCALAR
, 0, vertices
[0].data());
75 glTexCoordPointer(2, GL_SCALAR
, 0, tile_
);
77 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
82 void min_filter(GLuint filter)
86 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
89 void mag_filter(GLuint filter)
93 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
96 void wrap_s(GLuint wrap)
100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
103 void wrap_t(GLuint wrap)
107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
111 bool sprite::tile_coordinates(int index, scalar coords[8],
112 orientation orientation) const
114 if (tile_coordinates(index, coords))
116 if (orientation & flip)
118 // this looks kinda weird, but it's just swapping in a way that
119 // doesn't require an intermediate variable
120 coords[1] = coords[5];
121 coords[5] = coords[3];
122 coords[3] = coords[7];
123 coords[7] = coords[5];
125 if (orientation & reverse)
127 coords[0] = coords[2];
128 coords[2] = coords[6];
129 coords[4] = coords[6];
130 coords[6] = coords[0];
This page took 0.043956 seconds and 4 git commands to generate.