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