]> Dogcows Code - chaz/yoink/blob - src/moof/sprite.cc
pch support
[chaz/yoink] / src / moof / sprite.cc
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
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.
7 *
8 *****************************************************************************/
9
10 #include <cstdio> // FILE
11 #include <cstring> // strncmp
12 #include <stdexcept>
13
14 #include <boost/algorithm/string.hpp>
15 #include <boost/bind.hpp>
16
17 #include <stlplus/portability/file_system.hpp>
18
19 #include "dispatcher.hh"
20 #include "log.hh"
21 #include "opengl.hh"
22 #include "sprite.hh"
23
24
25 namespace moof {
26
27
28 sprite::sprite(const std::string& name, int tile)
29 {
30 image(name);
31 sprite::tile(tile);
32 }
33
34 sprite::sprite(const image_handle& image, int tile) :
35 image_(image)
36 {
37 sprite::tile(tile);
38 }
39
40 sprite::sprite(const sprite& sprite, int tile)
41 {
42 // FIXME broken
43 image_ = sprite.image_;
44 }
45
46 void sprite::image(const std::string& name)
47 {
48 image_ = resource::load(name, "png");
49 }
50
51 void sprite::tile(int tile)
52 {
53 if (image_) image_->tile_coordinates(tile, tile_);
54 }
55
56 void sprite::bind() const
57 {
58 if (image_) image_->bind();
59 }
60
61 void sprite::reset_binding()
62 {
63 image::reset_binding();
64 }
65
66 void sprite::draw(const vector3 vertices[4]) const
67 {
68 bind();
69
70 glVertexPointer(3, GL_SCALAR, 0, vertices[0].data());
71 glTexCoordPointer(2, GL_SCALAR, 0, tile_);
72
73 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
74 }
75
76 /*
77 void min_filter(GLuint filter)
78 {
79 bind();
80 mMinFilter = filter;
81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
82 }
83
84 void mag_filter(GLuint filter)
85 {
86 bind();
87 mMagFilter = filter;
88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
89 }
90
91 void wrap_s(GLuint wrap)
92 {
93 bind();
94 mWrapS = wrap;
95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
96 }
97
98 void wrap_t(GLuint wrap)
99 {
100 bind();
101 mWrapT = wrap;
102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
103 }
104
105 bool sprite::tile_coordinates(int index, scalar coords[8],
106 orientation orientation) const
107 {
108 if (tile_coordinates(index, coords))
109 {
110 if (orientation & flip)
111 {
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];
118 }
119 if (orientation & reverse)
120 {
121 coords[0] = coords[2];
122 coords[2] = coords[6];
123 coords[4] = coords[6];
124 coords[6] = coords[0];
125 }
126
127 return true;
128 }
129
130 return false;
131 }
132 */
133
134
135 } // namespace moof
136
This page took 0.036528 seconds and 4 git commands to generate.