]> Dogcows Code - chaz/yoink/blob - src/moof/sprite.cc
7548ab0b8b7ae7b975b4f88bb1f66222240e241c
[chaz/yoink] / src / moof / sprite.cc
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
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.
9 *
10 **************************************************************************/
11
12 #include <cstdio> // FILE
13 #include <cstring> // strncmp
14 #include <stdexcept>
15
16 #include <boost/algorithm/string.hpp>
17 #include <boost/bind.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& path, int tile)
29 {
30 image_ = resource::load(path);
31 image_->tile_coordinates(tile, tile_);
32 }
33
34 sprite::sprite(const image_handle& image, int tile) :
35 image_(image)
36 {
37 image_->tile_coordinates(tile, tile_);
38 }
39
40 sprite::sprite(const sprite& sprite, int tile)
41 {
42 // FIXME broken
43 image_ = sprite.image_;
44 }
45
46
47 void sprite::image(const std::string& path)
48 {
49 image_ = resource::load(path);
50 // FIXME what about tiles?
51 }
52
53 void sprite::tile(int tile)
54 {
55 if (image_) image_->tile_coordinates(tile, tile_);
56 }
57
58
59 void sprite::bind() const
60 {
61 if (image_) image_->bind();
62 }
63
64 void sprite::reset_binding()
65 {
66 image::reset_binding();
67 }
68
69
70 void sprite::draw(const vector3 vertices[4]) const
71 {
72 bind();
73
74 glVertexPointer(3, GL_SCALAR, 0, vertices[0].data());
75 glTexCoordPointer(2, GL_SCALAR, 0, tile_);
76
77 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
78 }
79
80
81 /*
82 void min_filter(GLuint filter)
83 {
84 bind();
85 mMinFilter = filter;
86 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter);
87 }
88
89 void mag_filter(GLuint filter)
90 {
91 bind();
92 mMagFilter = filter;
93 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter);
94 }
95
96 void wrap_s(GLuint wrap)
97 {
98 bind();
99 mWrapS = wrap;
100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS);
101 }
102
103 void wrap_t(GLuint wrap)
104 {
105 bind();
106 mWrapT = wrap;
107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
108 }
109
110
111 bool sprite::tile_coordinates(int index, scalar coords[8],
112 orientation orientation) const
113 {
114 if (tile_coordinates(index, coords))
115 {
116 if (orientation & flip)
117 {
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];
124 }
125 if (orientation & reverse)
126 {
127 coords[0] = coords[2];
128 coords[2] = coords[6];
129 coords[4] = coords[6];
130 coords[6] = coords[0];
131 }
132
133 return true;
134 }
135
136 return false;
137 }
138 */
139
140
141 } // namespace moof
142
This page took 0.035336 seconds and 3 git commands to generate.