LiteRGSS 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/LiteRGSS/Bitmap.cpp +316 -0
- data/ext/LiteRGSS/Bitmap.h +24 -0
- data/ext/LiteRGSS/BlendMode.cpp +202 -0
- data/ext/LiteRGSS/BlendMode.h +20 -0
- data/ext/LiteRGSS/CBitmap_Element.cpp +50 -0
- data/ext/LiteRGSS/CBitmap_Element.h +17 -0
- data/ext/LiteRGSS/CDrawable_Element.cpp +38 -0
- data/ext/LiteRGSS/CDrawable_Element.h +30 -0
- data/ext/LiteRGSS/CRect_Element.h +15 -0
- data/ext/LiteRGSS/CShaderSprite_Element.cpp +17 -0
- data/ext/LiteRGSS/CShaderSprite_Element.h +17 -0
- data/ext/LiteRGSS/CSprite_Element.cpp +15 -0
- data/ext/LiteRGSS/CSprite_Element.h +36 -0
- data/ext/LiteRGSS/CText_Element.cpp +12 -0
- data/ext/LiteRGSS/CText_Element.h +29 -0
- data/ext/LiteRGSS/CTone_Element.h +17 -0
- data/ext/LiteRGSS/CViewport_Element.cpp +224 -0
- data/ext/LiteRGSS/CViewport_Element.h +57 -0
- data/ext/LiteRGSS/Color.cpp +200 -0
- data/ext/LiteRGSS/Color.h +22 -0
- data/ext/LiteRGSS/Fonts.cpp +126 -0
- data/ext/LiteRGSS/Fonts.h +20 -0
- data/ext/LiteRGSS/Graphics.cpp +314 -0
- data/ext/LiteRGSS/Graphics.h +31 -0
- data/ext/LiteRGSS/Graphics.local.cpp +365 -0
- data/ext/LiteRGSS/Graphics.local.h +37 -0
- data/ext/LiteRGSS/Image.cpp +460 -0
- data/ext/LiteRGSS/Image.h +32 -0
- data/ext/LiteRGSS/Input.cpp +664 -0
- data/ext/LiteRGSS/Input.h +38 -0
- data/ext/LiteRGSS/LiteRGSS.cpp +34 -0
- data/ext/LiteRGSS/LiteRGSS.h +113 -0
- data/ext/LiteRGSS/Rect.cpp +324 -0
- data/ext/LiteRGSS/Rect.h +24 -0
- data/ext/LiteRGSS/Shader.cpp +279 -0
- data/ext/LiteRGSS/Shader.h +13 -0
- data/ext/LiteRGSS/ShaderSprite.cpp +78 -0
- data/ext/LiteRGSS/ShaderSprite.h +8 -0
- data/ext/LiteRGSS/Sprite.cpp +495 -0
- data/ext/LiteRGSS/Sprite.h +43 -0
- data/ext/LiteRGSS/Table.cpp +228 -0
- data/ext/LiteRGSS/Table.h +29 -0
- data/ext/LiteRGSS/Table32.cpp +228 -0
- data/ext/LiteRGSS/Table32.h +29 -0
- data/ext/LiteRGSS/Text.cpp +574 -0
- data/ext/LiteRGSS/Text.h +52 -0
- data/ext/LiteRGSS/Texture.hpp +735 -0
- data/ext/LiteRGSS/Tone.cpp +228 -0
- data/ext/LiteRGSS/Tone.h +22 -0
- data/ext/LiteRGSS/Viewport.cpp +491 -0
- data/ext/LiteRGSS/Viewport.h +33 -0
- data/ext/LiteRGSS/Yuki.cpp +29 -0
- data/ext/LiteRGSS/Yuki.h +8 -0
- data/ext/LiteRGSS/Yuki_Gif.cpp +218 -0
- data/ext/LiteRGSS/Yuki_Gif.h +25 -0
- data/ext/LiteRGSS/extconf.rb +8 -0
- data/ext/LiteRGSS/libnsgif.c +1169 -0
- data/ext/LiteRGSS/libnsgif.h +183 -0
- data/ext/LiteRGSS/libnsgif.hpp +184 -0
- data/ext/LiteRGSS/lodepng.cpp +6245 -0
- data/ext/LiteRGSS/lodepng.h +1769 -0
- data/ext/LiteRGSS/lzw.c +377 -0
- data/ext/LiteRGSS/lzw.h +105 -0
- data/ext/LiteRGSS/sf_Text2.cpp +690 -0
- data/ext/LiteRGSS/sf_Text2.hpp +549 -0
- data/ext/LiteRGSS/utils/log.h +21 -0
- metadata +112 -0
data/ext/LiteRGSS/Text.h
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#ifndef L_TEXT_HEADER
|
2
|
+
#define L_TEXT_HEADER
|
3
|
+
#include "CText_Element.h"
|
4
|
+
#include "Graphics.h"
|
5
|
+
|
6
|
+
VALUE rb_Text_Initialize(int argc, VALUE* argv, VALUE self);
|
7
|
+
VALUE rb_Text_Copy(VALUE self);
|
8
|
+
VALUE rb_Text_Dispose(VALUE self);
|
9
|
+
VALUE rb_Text_Disposed(VALUE self);
|
10
|
+
VALUE rb_Text_setPosition(VALUE self, VALUE x, VALUE y);
|
11
|
+
VALUE rb_Text_get_x(VALUE self);
|
12
|
+
VALUE rb_Text_set_x(VALUE self, VALUE val);
|
13
|
+
VALUE rb_Text_get_y(VALUE self);
|
14
|
+
VALUE rb_Text_set_y(VALUE self, VALUE val);
|
15
|
+
VALUE rb_Text_get_width(VALUE self);
|
16
|
+
VALUE rb_Text_set_width(VALUE self, VALUE val);
|
17
|
+
VALUE rb_Text_get_height(VALUE self);
|
18
|
+
VALUE rb_Text_set_height(VALUE self, VALUE val);
|
19
|
+
VALUE rb_Text_get_fill_color(VALUE self);
|
20
|
+
VALUE rb_Text_set_fill_color(VALUE self, VALUE val);
|
21
|
+
VALUE rb_Text_get_outline_color(VALUE self);
|
22
|
+
VALUE rb_Text_set_outline_color(VALUE self, VALUE val);
|
23
|
+
VALUE rb_Text_get_outline_thickness(VALUE self);
|
24
|
+
VALUE rb_Text_set_outline_thickness(VALUE self, VALUE val);
|
25
|
+
VALUE rb_Text_load_color(VALUE self, VALUE id);
|
26
|
+
VALUE rb_Text_get_align(VALUE self);
|
27
|
+
VALUE rb_Text_set_align(VALUE self, VALUE val);
|
28
|
+
VALUE rb_Text_get_size(VALUE self);
|
29
|
+
VALUE rb_Text_set_size(VALUE self, VALUE val);
|
30
|
+
VALUE rb_Text_set_Text(VALUE self, VALUE str);
|
31
|
+
VALUE rb_Text_get_Text(VALUE self);
|
32
|
+
VALUE rb_Text_DisposeFromViewport(VALUE self);
|
33
|
+
VALUE rb_Text_UpdateI(CText_Element* text);
|
34
|
+
VALUE rb_Text_get_visible(VALUE self);
|
35
|
+
VALUE rb_Text_set_visible(VALUE self, VALUE val);
|
36
|
+
VALUE rb_Text_set_num_char(VALUE self, VALUE val);
|
37
|
+
VALUE rb_Text_get_num_char(VALUE self);
|
38
|
+
VALUE rb_Text_set_draw_shadow(VALUE self, VALUE val);
|
39
|
+
VALUE rb_Text_get_draw_shadow(VALUE self);
|
40
|
+
VALUE rb_Text_getRealWidth(VALUE self);
|
41
|
+
VALUE rb_Text_getOpacity(VALUE self);
|
42
|
+
VALUE rb_Text_setOpacity(VALUE self, VALUE val);
|
43
|
+
VALUE rb_Text_get_text_width(VALUE self, VALUE val);
|
44
|
+
VALUE rb_Text_getZ(VALUE self);
|
45
|
+
VALUE rb_Text_setZ(VALUE self, VALUE val);
|
46
|
+
VALUE rb_Text_Index(VALUE self);
|
47
|
+
VALUE rb_Text_Viewport(VALUE self);
|
48
|
+
VALUE rb_Text_getItalic(VALUE self);
|
49
|
+
VALUE rb_Text_setItalic(VALUE self, VALUE val);
|
50
|
+
VALUE rb_Text_getBold(VALUE self);
|
51
|
+
VALUE rb_Text_setBold(VALUE self, VALUE val);
|
52
|
+
#endif
|
@@ -0,0 +1,735 @@
|
|
1
|
+
////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// SFML - Simple and Fast Multimedia Library
|
4
|
+
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
5
|
+
//
|
6
|
+
// This software is provided 'as-is', without any express or implied warranty.
|
7
|
+
// In no event will the authors be held liable for any damages arising from the use of this software.
|
8
|
+
//
|
9
|
+
// Permission is granted to anyone to use this software for any purpose,
|
10
|
+
// including commercial applications, and to alter it and redistribute it freely,
|
11
|
+
// subject to the following restrictions:
|
12
|
+
//
|
13
|
+
// 1. The origin of this software must not be misrepresented;
|
14
|
+
// you must not claim that you wrote the original software.
|
15
|
+
// If you use this software in a product, an acknowledgment
|
16
|
+
// in the product documentation would be appreciated but is not required.
|
17
|
+
//
|
18
|
+
// 2. Altered source versions must be plainly marked as such,
|
19
|
+
// and must not be misrepresented as being the original software.
|
20
|
+
//
|
21
|
+
// 3. This notice may not be removed or altered from any source distribution.
|
22
|
+
//
|
23
|
+
////////////////////////////////////////////////////////////
|
24
|
+
|
25
|
+
#ifndef SFML_TEXTURE_HPP
|
26
|
+
#define SFML_TEXTURE_HPP
|
27
|
+
|
28
|
+
////////////////////////////////////////////////////////////
|
29
|
+
// Headers
|
30
|
+
////////////////////////////////////////////////////////////
|
31
|
+
#include <SFML/Graphics/Export.hpp>
|
32
|
+
#include <SFML/Graphics/Image.hpp>
|
33
|
+
#include <SFML/Window/GlResource.hpp>
|
34
|
+
|
35
|
+
|
36
|
+
namespace sf
|
37
|
+
{
|
38
|
+
class InputStream;
|
39
|
+
class RenderTarget;
|
40
|
+
class RenderTexture;
|
41
|
+
class Text;
|
42
|
+
class Window;
|
43
|
+
class Text2;
|
44
|
+
|
45
|
+
////////////////////////////////////////////////////////////
|
46
|
+
/// \brief Image living on the graphics card that can be used for drawing
|
47
|
+
///
|
48
|
+
////////////////////////////////////////////////////////////
|
49
|
+
class SFML_GRAPHICS_API Texture : GlResource
|
50
|
+
{
|
51
|
+
public:
|
52
|
+
|
53
|
+
////////////////////////////////////////////////////////////
|
54
|
+
/// \brief Types of texture coordinates that can be used for rendering
|
55
|
+
///
|
56
|
+
////////////////////////////////////////////////////////////
|
57
|
+
enum CoordinateType
|
58
|
+
{
|
59
|
+
Normalized, ///< Texture coordinates in range [0 .. 1]
|
60
|
+
Pixels ///< Texture coordinates in range [0 .. size]
|
61
|
+
};
|
62
|
+
|
63
|
+
public:
|
64
|
+
|
65
|
+
////////////////////////////////////////////////////////////
|
66
|
+
/// \brief Default constructor
|
67
|
+
///
|
68
|
+
/// Creates an empty texture.
|
69
|
+
///
|
70
|
+
////////////////////////////////////////////////////////////
|
71
|
+
Texture();
|
72
|
+
|
73
|
+
////////////////////////////////////////////////////////////
|
74
|
+
/// \brief Copy constructor
|
75
|
+
///
|
76
|
+
/// \param copy instance to copy
|
77
|
+
///
|
78
|
+
////////////////////////////////////////////////////////////
|
79
|
+
Texture(const Texture& copy);
|
80
|
+
|
81
|
+
////////////////////////////////////////////////////////////
|
82
|
+
/// \brief Destructor
|
83
|
+
///
|
84
|
+
////////////////////////////////////////////////////////////
|
85
|
+
~Texture();
|
86
|
+
|
87
|
+
////////////////////////////////////////////////////////////
|
88
|
+
/// \brief Create the texture
|
89
|
+
///
|
90
|
+
/// If this function fails, the texture is left unchanged.
|
91
|
+
///
|
92
|
+
/// \param width Width of the texture
|
93
|
+
/// \param height Height of the texture
|
94
|
+
///
|
95
|
+
/// \return True if creation was successful
|
96
|
+
///
|
97
|
+
////////////////////////////////////////////////////////////
|
98
|
+
bool create(unsigned int width, unsigned int height);
|
99
|
+
|
100
|
+
////////////////////////////////////////////////////////////
|
101
|
+
/// \brief Load the texture from a file on disk
|
102
|
+
///
|
103
|
+
/// This function is a shortcut for the following code:
|
104
|
+
/// \code
|
105
|
+
/// sf::Image image;
|
106
|
+
/// image.loadFromFile(filename);
|
107
|
+
/// texture.loadFromImage(image, area);
|
108
|
+
/// \endcode
|
109
|
+
///
|
110
|
+
/// The \a area argument can be used to load only a sub-rectangle
|
111
|
+
/// of the whole image. If you want the entire image then leave
|
112
|
+
/// the default value (which is an empty IntRect).
|
113
|
+
/// If the \a area rectangle crosses the bounds of the image, it
|
114
|
+
/// is adjusted to fit the image size.
|
115
|
+
///
|
116
|
+
/// The maximum size for a texture depends on the graphics
|
117
|
+
/// driver and can be retrieved with the getMaximumSize function.
|
118
|
+
///
|
119
|
+
/// If this function fails, the texture is left unchanged.
|
120
|
+
///
|
121
|
+
/// \param filename Path of the image file to load
|
122
|
+
/// \param area Area of the image to load
|
123
|
+
///
|
124
|
+
/// \return True if loading was successful
|
125
|
+
///
|
126
|
+
/// \see loadFromMemory, loadFromStream, loadFromImage
|
127
|
+
///
|
128
|
+
////////////////////////////////////////////////////////////
|
129
|
+
bool loadFromFile(const std::string& filename, const IntRect& area = IntRect());
|
130
|
+
|
131
|
+
////////////////////////////////////////////////////////////
|
132
|
+
/// \brief Load the texture from a file in memory
|
133
|
+
///
|
134
|
+
/// This function is a shortcut for the following code:
|
135
|
+
/// \code
|
136
|
+
/// sf::Image image;
|
137
|
+
/// image.loadFromMemory(data, size);
|
138
|
+
/// texture.loadFromImage(image, area);
|
139
|
+
/// \endcode
|
140
|
+
///
|
141
|
+
/// The \a area argument can be used to load only a sub-rectangle
|
142
|
+
/// of the whole image. If you want the entire image then leave
|
143
|
+
/// the default value (which is an empty IntRect).
|
144
|
+
/// If the \a area rectangle crosses the bounds of the image, it
|
145
|
+
/// is adjusted to fit the image size.
|
146
|
+
///
|
147
|
+
/// The maximum size for a texture depends on the graphics
|
148
|
+
/// driver and can be retrieved with the getMaximumSize function.
|
149
|
+
///
|
150
|
+
/// If this function fails, the texture is left unchanged.
|
151
|
+
///
|
152
|
+
/// \param data Pointer to the file data in memory
|
153
|
+
/// \param size Size of the data to load, in bytes
|
154
|
+
/// \param area Area of the image to load
|
155
|
+
///
|
156
|
+
/// \return True if loading was successful
|
157
|
+
///
|
158
|
+
/// \see loadFromFile, loadFromStream, loadFromImage
|
159
|
+
///
|
160
|
+
////////////////////////////////////////////////////////////
|
161
|
+
bool loadFromMemory(const void* data, std::size_t size, const IntRect& area = IntRect());
|
162
|
+
|
163
|
+
////////////////////////////////////////////////////////////
|
164
|
+
/// \brief Load the texture from a custom stream
|
165
|
+
///
|
166
|
+
/// This function is a shortcut for the following code:
|
167
|
+
/// \code
|
168
|
+
/// sf::Image image;
|
169
|
+
/// image.loadFromStream(stream);
|
170
|
+
/// texture.loadFromImage(image, area);
|
171
|
+
/// \endcode
|
172
|
+
///
|
173
|
+
/// The \a area argument can be used to load only a sub-rectangle
|
174
|
+
/// of the whole image. If you want the entire image then leave
|
175
|
+
/// the default value (which is an empty IntRect).
|
176
|
+
/// If the \a area rectangle crosses the bounds of the image, it
|
177
|
+
/// is adjusted to fit the image size.
|
178
|
+
///
|
179
|
+
/// The maximum size for a texture depends on the graphics
|
180
|
+
/// driver and can be retrieved with the getMaximumSize function.
|
181
|
+
///
|
182
|
+
/// If this function fails, the texture is left unchanged.
|
183
|
+
///
|
184
|
+
/// \param stream Source stream to read from
|
185
|
+
/// \param area Area of the image to load
|
186
|
+
///
|
187
|
+
/// \return True if loading was successful
|
188
|
+
///
|
189
|
+
/// \see loadFromFile, loadFromMemory, loadFromImage
|
190
|
+
///
|
191
|
+
////////////////////////////////////////////////////////////
|
192
|
+
bool loadFromStream(InputStream& stream, const IntRect& area = IntRect());
|
193
|
+
|
194
|
+
////////////////////////////////////////////////////////////
|
195
|
+
/// \brief Load the texture from an image
|
196
|
+
///
|
197
|
+
/// The \a area argument can be used to load only a sub-rectangle
|
198
|
+
/// of the whole image. If you want the entire image then leave
|
199
|
+
/// the default value (which is an empty IntRect).
|
200
|
+
/// If the \a area rectangle crosses the bounds of the image, it
|
201
|
+
/// is adjusted to fit the image size.
|
202
|
+
///
|
203
|
+
/// The maximum size for a texture depends on the graphics
|
204
|
+
/// driver and can be retrieved with the getMaximumSize function.
|
205
|
+
///
|
206
|
+
/// If this function fails, the texture is left unchanged.
|
207
|
+
///
|
208
|
+
/// \param image Image to load into the texture
|
209
|
+
/// \param area Area of the image to load
|
210
|
+
///
|
211
|
+
/// \return True if loading was successful
|
212
|
+
///
|
213
|
+
/// \see loadFromFile, loadFromMemory
|
214
|
+
///
|
215
|
+
////////////////////////////////////////////////////////////
|
216
|
+
bool loadFromImage(const Image& image, const IntRect& area = IntRect());
|
217
|
+
|
218
|
+
////////////////////////////////////////////////////////////
|
219
|
+
/// \brief Return the size of the texture
|
220
|
+
///
|
221
|
+
/// \return Size in pixels
|
222
|
+
///
|
223
|
+
////////////////////////////////////////////////////////////
|
224
|
+
Vector2u getSize() const;
|
225
|
+
|
226
|
+
////////////////////////////////////////////////////////////
|
227
|
+
/// \brief Copy the texture pixels to an image
|
228
|
+
///
|
229
|
+
/// This function performs a slow operation that downloads
|
230
|
+
/// the texture's pixels from the graphics card and copies
|
231
|
+
/// them to a new image, potentially applying transformations
|
232
|
+
/// to pixels if necessary (texture may be padded or flipped).
|
233
|
+
///
|
234
|
+
/// \return Image containing the texture's pixels
|
235
|
+
///
|
236
|
+
/// \see loadFromImage
|
237
|
+
///
|
238
|
+
////////////////////////////////////////////////////////////
|
239
|
+
Image copyToImage() const;
|
240
|
+
|
241
|
+
////////////////////////////////////////////////////////////
|
242
|
+
/// \brief Update the whole texture from an array of pixels
|
243
|
+
///
|
244
|
+
/// The \a pixel array is assumed to have the same size as
|
245
|
+
/// the \a area rectangle, and to contain 32-bits RGBA pixels.
|
246
|
+
///
|
247
|
+
/// No additional check is performed on the size of the pixel
|
248
|
+
/// array, passing invalid arguments will lead to an undefined
|
249
|
+
/// behavior.
|
250
|
+
///
|
251
|
+
/// This function does nothing if \a pixels is null or if the
|
252
|
+
/// texture was not previously created.
|
253
|
+
///
|
254
|
+
/// \param pixels Array of pixels to copy to the texture
|
255
|
+
///
|
256
|
+
////////////////////////////////////////////////////////////
|
257
|
+
void update(const Uint8* pixels);
|
258
|
+
|
259
|
+
////////////////////////////////////////////////////////////
|
260
|
+
/// \brief Update a part of the texture from an array of pixels
|
261
|
+
///
|
262
|
+
/// The size of the \a pixel array must match the \a width and
|
263
|
+
/// \a height arguments, and it must contain 32-bits RGBA pixels.
|
264
|
+
///
|
265
|
+
/// No additional check is performed on the size of the pixel
|
266
|
+
/// array or the bounds of the area to update, passing invalid
|
267
|
+
/// arguments will lead to an undefined behavior.
|
268
|
+
///
|
269
|
+
/// This function does nothing if \a pixels is null or if the
|
270
|
+
/// texture was not previously created.
|
271
|
+
///
|
272
|
+
/// \param pixels Array of pixels to copy to the texture
|
273
|
+
/// \param width Width of the pixel region contained in \a pixels
|
274
|
+
/// \param height Height of the pixel region contained in \a pixels
|
275
|
+
/// \param x X offset in the texture where to copy the source pixels
|
276
|
+
/// \param y Y offset in the texture where to copy the source pixels
|
277
|
+
///
|
278
|
+
////////////////////////////////////////////////////////////
|
279
|
+
void update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y);
|
280
|
+
|
281
|
+
////////////////////////////////////////////////////////////
|
282
|
+
/// \brief Update a part of this texture from another texture
|
283
|
+
///
|
284
|
+
/// Although the source texture can be smaller than this texture,
|
285
|
+
/// this function is usually used for updating the whole texture.
|
286
|
+
/// The other overload, which has (x, y) additional arguments,
|
287
|
+
/// is more convenient for updating a sub-area of this texture.
|
288
|
+
///
|
289
|
+
/// No additional check is performed on the size of the passed
|
290
|
+
/// texture, passing a texture bigger than this texture
|
291
|
+
/// will lead to an undefined behavior.
|
292
|
+
///
|
293
|
+
/// This function does nothing if either texture was not
|
294
|
+
/// previously created.
|
295
|
+
///
|
296
|
+
/// \param texture Source texture to copy to this texture
|
297
|
+
///
|
298
|
+
////////////////////////////////////////////////////////////
|
299
|
+
void update(const Texture& texture);
|
300
|
+
|
301
|
+
////////////////////////////////////////////////////////////
|
302
|
+
/// \brief Update a part of this texture from another texture
|
303
|
+
///
|
304
|
+
/// No additional check is performed on the size of the texture,
|
305
|
+
/// passing an invalid combination of texture size and offset
|
306
|
+
/// will lead to an undefined behavior.
|
307
|
+
///
|
308
|
+
/// This function does nothing if either texture was not
|
309
|
+
/// previously created.
|
310
|
+
///
|
311
|
+
/// \param texture Source texture to copy to this texture
|
312
|
+
/// \param x X offset in this texture where to copy the source texture
|
313
|
+
/// \param y Y offset in this texture where to copy the source texture
|
314
|
+
///
|
315
|
+
////////////////////////////////////////////////////////////
|
316
|
+
void update(const Texture& texture, unsigned int x, unsigned int y);
|
317
|
+
|
318
|
+
////////////////////////////////////////////////////////////
|
319
|
+
/// \brief Update the texture from an image
|
320
|
+
///
|
321
|
+
/// Although the source image can be smaller than the texture,
|
322
|
+
/// this function is usually used for updating the whole texture.
|
323
|
+
/// The other overload, which has (x, y) additional arguments,
|
324
|
+
/// is more convenient for updating a sub-area of the texture.
|
325
|
+
///
|
326
|
+
/// No additional check is performed on the size of the image,
|
327
|
+
/// passing an image bigger than the texture will lead to an
|
328
|
+
/// undefined behavior.
|
329
|
+
///
|
330
|
+
/// This function does nothing if the texture was not
|
331
|
+
/// previously created.
|
332
|
+
///
|
333
|
+
/// \param image Image to copy to the texture
|
334
|
+
///
|
335
|
+
////////////////////////////////////////////////////////////
|
336
|
+
void update(const Image& image);
|
337
|
+
|
338
|
+
////////////////////////////////////////////////////////////
|
339
|
+
/// \brief Update a part of the texture from an image
|
340
|
+
///
|
341
|
+
/// No additional check is performed on the size of the image,
|
342
|
+
/// passing an invalid combination of image size and offset
|
343
|
+
/// will lead to an undefined behavior.
|
344
|
+
///
|
345
|
+
/// This function does nothing if the texture was not
|
346
|
+
/// previously created.
|
347
|
+
///
|
348
|
+
/// \param image Image to copy to the texture
|
349
|
+
/// \param x X offset in the texture where to copy the source image
|
350
|
+
/// \param y Y offset in the texture where to copy the source image
|
351
|
+
///
|
352
|
+
////////////////////////////////////////////////////////////
|
353
|
+
void update(const Image& image, unsigned int x, unsigned int y);
|
354
|
+
|
355
|
+
////////////////////////////////////////////////////////////
|
356
|
+
/// \brief Update the texture from the contents of a window
|
357
|
+
///
|
358
|
+
/// Although the source window can be smaller than the texture,
|
359
|
+
/// this function is usually used for updating the whole texture.
|
360
|
+
/// The other overload, which has (x, y) additional arguments,
|
361
|
+
/// is more convenient for updating a sub-area of the texture.
|
362
|
+
///
|
363
|
+
/// No additional check is performed on the size of the window,
|
364
|
+
/// passing a window bigger than the texture will lead to an
|
365
|
+
/// undefined behavior.
|
366
|
+
///
|
367
|
+
/// This function does nothing if either the texture or the window
|
368
|
+
/// was not previously created.
|
369
|
+
///
|
370
|
+
/// \param window Window to copy to the texture
|
371
|
+
///
|
372
|
+
////////////////////////////////////////////////////////////
|
373
|
+
void update(const Window& window);
|
374
|
+
|
375
|
+
////////////////////////////////////////////////////////////
|
376
|
+
/// \brief Update a part of the texture from the contents of a window
|
377
|
+
///
|
378
|
+
/// No additional check is performed on the size of the window,
|
379
|
+
/// passing an invalid combination of window size and offset
|
380
|
+
/// will lead to an undefined behavior.
|
381
|
+
///
|
382
|
+
/// This function does nothing if either the texture or the window
|
383
|
+
/// was not previously created.
|
384
|
+
///
|
385
|
+
/// \param window Window to copy to the texture
|
386
|
+
/// \param x X offset in the texture where to copy the source window
|
387
|
+
/// \param y Y offset in the texture where to copy the source window
|
388
|
+
///
|
389
|
+
////////////////////////////////////////////////////////////
|
390
|
+
void update(const Window& window, unsigned int x, unsigned int y);
|
391
|
+
|
392
|
+
////////////////////////////////////////////////////////////
|
393
|
+
/// \brief Enable or disable the smooth filter
|
394
|
+
///
|
395
|
+
/// When the filter is activated, the texture appears smoother
|
396
|
+
/// so that pixels are less noticeable. However if you want
|
397
|
+
/// the texture to look exactly the same as its source file,
|
398
|
+
/// you should leave it disabled.
|
399
|
+
/// The smooth filter is disabled by default.
|
400
|
+
///
|
401
|
+
/// \param smooth True to enable smoothing, false to disable it
|
402
|
+
///
|
403
|
+
/// \see isSmooth
|
404
|
+
///
|
405
|
+
////////////////////////////////////////////////////////////
|
406
|
+
void setSmooth(bool smooth);
|
407
|
+
|
408
|
+
////////////////////////////////////////////////////////////
|
409
|
+
/// \brief Tell whether the smooth filter is enabled or not
|
410
|
+
///
|
411
|
+
/// \return True if smoothing is enabled, false if it is disabled
|
412
|
+
///
|
413
|
+
/// \see setSmooth
|
414
|
+
///
|
415
|
+
////////////////////////////////////////////////////////////
|
416
|
+
bool isSmooth() const;
|
417
|
+
|
418
|
+
////////////////////////////////////////////////////////////
|
419
|
+
/// \brief Enable or disable conversion from sRGB
|
420
|
+
///
|
421
|
+
/// When providing texture data from an image file or memory, it can
|
422
|
+
/// either be stored in a linear color space or an sRGB color space.
|
423
|
+
/// Most digital images account for gamma correction already, so they
|
424
|
+
/// would need to be "uncorrected" back to linear color space before
|
425
|
+
/// being processed by the hardware. The hardware can automatically
|
426
|
+
/// convert it from the sRGB color space to a linear color space when
|
427
|
+
/// it gets sampled. When the rendered image gets output to the final
|
428
|
+
/// framebuffer, it gets converted back to sRGB.
|
429
|
+
///
|
430
|
+
/// After enabling or disabling sRGB conversion, make sure to reload
|
431
|
+
/// the texture data in order for the setting to take effect.
|
432
|
+
///
|
433
|
+
/// This option is only useful in conjunction with an sRGB capable
|
434
|
+
/// framebuffer. This can be requested during window creation.
|
435
|
+
///
|
436
|
+
/// \param sRgb True to enable sRGB conversion, false to disable it
|
437
|
+
///
|
438
|
+
/// \see isSrgb
|
439
|
+
///
|
440
|
+
////////////////////////////////////////////////////////////
|
441
|
+
void setSrgb(bool sRgb);
|
442
|
+
|
443
|
+
////////////////////////////////////////////////////////////
|
444
|
+
/// \brief Tell whether the texture source is converted from sRGB or not
|
445
|
+
///
|
446
|
+
/// \return True if the texture source is converted from sRGB, false if not
|
447
|
+
///
|
448
|
+
/// \see setSrgb
|
449
|
+
///
|
450
|
+
////////////////////////////////////////////////////////////
|
451
|
+
bool isSrgb() const;
|
452
|
+
|
453
|
+
////////////////////////////////////////////////////////////
|
454
|
+
/// \brief Enable or disable repeating
|
455
|
+
///
|
456
|
+
/// Repeating is involved when using texture coordinates
|
457
|
+
/// outside the texture rectangle [0, 0, width, height].
|
458
|
+
/// In this case, if repeat mode is enabled, the whole texture
|
459
|
+
/// will be repeated as many times as needed to reach the
|
460
|
+
/// coordinate (for example, if the X texture coordinate is
|
461
|
+
/// 3 * width, the texture will be repeated 3 times).
|
462
|
+
/// If repeat mode is disabled, the "extra space" will instead
|
463
|
+
/// be filled with border pixels.
|
464
|
+
/// Warning: on very old graphics cards, white pixels may appear
|
465
|
+
/// when the texture is repeated. With such cards, repeat mode
|
466
|
+
/// can be used reliably only if the texture has power-of-two
|
467
|
+
/// dimensions (such as 256x128).
|
468
|
+
/// Repeating is disabled by default.
|
469
|
+
///
|
470
|
+
/// \param repeated True to repeat the texture, false to disable repeating
|
471
|
+
///
|
472
|
+
/// \see isRepeated
|
473
|
+
///
|
474
|
+
////////////////////////////////////////////////////////////
|
475
|
+
void setRepeated(bool repeated);
|
476
|
+
|
477
|
+
////////////////////////////////////////////////////////////
|
478
|
+
/// \brief Tell whether the texture is repeated or not
|
479
|
+
///
|
480
|
+
/// \return True if repeat mode is enabled, false if it is disabled
|
481
|
+
///
|
482
|
+
/// \see setRepeated
|
483
|
+
///
|
484
|
+
////////////////////////////////////////////////////////////
|
485
|
+
bool isRepeated() const;
|
486
|
+
|
487
|
+
////////////////////////////////////////////////////////////
|
488
|
+
/// \brief Generate a mipmap using the current texture data
|
489
|
+
///
|
490
|
+
/// Mipmaps are pre-computed chains of optimized textures. Each
|
491
|
+
/// level of texture in a mipmap is generated by halving each of
|
492
|
+
/// the previous level's dimensions. This is done until the final
|
493
|
+
/// level has the size of 1x1. The textures generated in this process may
|
494
|
+
/// make use of more advanced filters which might improve the visual quality
|
495
|
+
/// of textures when they are applied to objects much smaller than they are.
|
496
|
+
/// This is known as minification. Because fewer texels (texture elements)
|
497
|
+
/// have to be sampled from when heavily minified, usage of mipmaps
|
498
|
+
/// can also improve rendering performance in certain scenarios.
|
499
|
+
///
|
500
|
+
/// Mipmap generation relies on the necessary OpenGL extension being
|
501
|
+
/// available. If it is unavailable or generation fails due to another
|
502
|
+
/// reason, this function will return false. Mipmap data is only valid from
|
503
|
+
/// the time it is generated until the next time the base level image is
|
504
|
+
/// modified, at which point this function will have to be called again to
|
505
|
+
/// regenerate it.
|
506
|
+
///
|
507
|
+
/// \return True if mipmap generation was successful, false if unsuccessful
|
508
|
+
///
|
509
|
+
////////////////////////////////////////////////////////////
|
510
|
+
bool generateMipmap();
|
511
|
+
|
512
|
+
////////////////////////////////////////////////////////////
|
513
|
+
/// \brief Overload of assignment operator
|
514
|
+
///
|
515
|
+
/// \param right Instance to assign
|
516
|
+
///
|
517
|
+
/// \return Reference to self
|
518
|
+
///
|
519
|
+
////////////////////////////////////////////////////////////
|
520
|
+
Texture& operator =(const Texture& right);
|
521
|
+
|
522
|
+
////////////////////////////////////////////////////////////
|
523
|
+
/// \brief Swap the contents of this texture with those of another
|
524
|
+
///
|
525
|
+
/// \param right Instance to swap with
|
526
|
+
///
|
527
|
+
////////////////////////////////////////////////////////////
|
528
|
+
void swap(Texture& right);
|
529
|
+
|
530
|
+
////////////////////////////////////////////////////////////
|
531
|
+
/// \brief Get the underlying OpenGL handle of the texture.
|
532
|
+
///
|
533
|
+
/// You shouldn't need to use this function, unless you have
|
534
|
+
/// very specific stuff to implement that SFML doesn't support,
|
535
|
+
/// or implement a temporary workaround until a bug is fixed.
|
536
|
+
///
|
537
|
+
/// \return OpenGL handle of the texture or 0 if not yet created
|
538
|
+
///
|
539
|
+
////////////////////////////////////////////////////////////
|
540
|
+
unsigned int getNativeHandle() const;
|
541
|
+
|
542
|
+
////////////////////////////////////////////////////////////
|
543
|
+
/// \brief Bind a texture for rendering
|
544
|
+
///
|
545
|
+
/// This function is not part of the graphics API, it mustn't be
|
546
|
+
/// used when drawing SFML entities. It must be used only if you
|
547
|
+
/// mix sf::Texture with OpenGL code.
|
548
|
+
///
|
549
|
+
/// \code
|
550
|
+
/// sf::Texture t1, t2;
|
551
|
+
/// ...
|
552
|
+
/// sf::Texture::bind(&t1);
|
553
|
+
/// // draw OpenGL stuff that use t1...
|
554
|
+
/// sf::Texture::bind(&t2);
|
555
|
+
/// // draw OpenGL stuff that use t2...
|
556
|
+
/// sf::Texture::bind(NULL);
|
557
|
+
/// // draw OpenGL stuff that use no texture...
|
558
|
+
/// \endcode
|
559
|
+
///
|
560
|
+
/// The \a coordinateType argument controls how texture
|
561
|
+
/// coordinates will be interpreted. If Normalized (the default), they
|
562
|
+
/// must be in range [0 .. 1], which is the default way of handling
|
563
|
+
/// texture coordinates with OpenGL. If Pixels, they must be given
|
564
|
+
/// in pixels (range [0 .. size]). This mode is used internally by
|
565
|
+
/// the graphics classes of SFML, it makes the definition of texture
|
566
|
+
/// coordinates more intuitive for the high-level API, users don't need
|
567
|
+
/// to compute normalized values.
|
568
|
+
///
|
569
|
+
/// \param texture Pointer to the texture to bind, can be null to use no texture
|
570
|
+
/// \param coordinateType Type of texture coordinates to use
|
571
|
+
///
|
572
|
+
////////////////////////////////////////////////////////////
|
573
|
+
static void bind(const Texture* texture, CoordinateType coordinateType = Normalized);
|
574
|
+
|
575
|
+
////////////////////////////////////////////////////////////
|
576
|
+
/// \brief Get the maximum texture size allowed
|
577
|
+
///
|
578
|
+
/// This maximum size is defined by the graphics driver.
|
579
|
+
/// You can expect a value of 512 pixels for low-end graphics
|
580
|
+
/// card, and up to 8192 pixels or more for newer hardware.
|
581
|
+
///
|
582
|
+
/// \return Maximum size allowed for textures, in pixels
|
583
|
+
///
|
584
|
+
////////////////////////////////////////////////////////////
|
585
|
+
static unsigned int getMaximumSize();
|
586
|
+
|
587
|
+
private:
|
588
|
+
|
589
|
+
friend class Text;
|
590
|
+
friend class Text2;
|
591
|
+
friend class RenderTexture;
|
592
|
+
friend class RenderTarget;
|
593
|
+
|
594
|
+
////////////////////////////////////////////////////////////
|
595
|
+
/// \brief Get a valid image size according to hardware support
|
596
|
+
///
|
597
|
+
/// This function checks whether the graphics driver supports
|
598
|
+
/// non power of two sizes or not, and adjusts the size
|
599
|
+
/// accordingly.
|
600
|
+
/// The returned size is greater than or equal to the original size.
|
601
|
+
///
|
602
|
+
/// \param size size to convert
|
603
|
+
///
|
604
|
+
/// \return Valid nearest size (greater than or equal to specified size)
|
605
|
+
///
|
606
|
+
////////////////////////////////////////////////////////////
|
607
|
+
static unsigned int getValidSize(unsigned int size);
|
608
|
+
|
609
|
+
////////////////////////////////////////////////////////////
|
610
|
+
/// \brief Invalidate the mipmap if one exists
|
611
|
+
///
|
612
|
+
/// This also resets the texture's minifying function.
|
613
|
+
/// This function is mainly for internal use by RenderTexture.
|
614
|
+
///
|
615
|
+
////////////////////////////////////////////////////////////
|
616
|
+
void invalidateMipmap();
|
617
|
+
|
618
|
+
////////////////////////////////////////////////////////////
|
619
|
+
// Member data
|
620
|
+
////////////////////////////////////////////////////////////
|
621
|
+
Vector2u m_size; ///< Public texture size
|
622
|
+
Vector2u m_actualSize; ///< Actual texture size (can be greater than public size because of padding)
|
623
|
+
unsigned int m_texture; ///< Internal texture identifier
|
624
|
+
bool m_isSmooth; ///< Status of the smooth filter
|
625
|
+
bool m_sRgb; ///< Should the texture source be converted from sRGB?
|
626
|
+
bool m_isRepeated; ///< Is the texture in repeat mode?
|
627
|
+
mutable bool m_pixelsFlipped; ///< To work around the inconsistency in Y orientation
|
628
|
+
bool m_fboAttachment; ///< Is this texture owned by a framebuffer object?
|
629
|
+
bool m_hasMipmap; ///< Has the mipmap been generated?
|
630
|
+
Uint64 m_cacheId; ///< Unique number that identifies the texture to the render target's cache
|
631
|
+
};
|
632
|
+
|
633
|
+
} // namespace sf
|
634
|
+
|
635
|
+
|
636
|
+
#endif // SFML_TEXTURE_HPP
|
637
|
+
|
638
|
+
////////////////////////////////////////////////////////////
|
639
|
+
/// \class sf::Texture
|
640
|
+
/// \ingroup graphics
|
641
|
+
///
|
642
|
+
/// sf::Texture stores pixels that can be drawn, with a sprite
|
643
|
+
/// for example. A texture lives in the graphics card memory,
|
644
|
+
/// therefore it is very fast to draw a texture to a render target,
|
645
|
+
/// or copy a render target to a texture (the graphics card can
|
646
|
+
/// access both directly).
|
647
|
+
///
|
648
|
+
/// Being stored in the graphics card memory has some drawbacks.
|
649
|
+
/// A texture cannot be manipulated as freely as a sf::Image,
|
650
|
+
/// you need to prepare the pixels first and then upload them
|
651
|
+
/// to the texture in a single operation (see Texture::update).
|
652
|
+
///
|
653
|
+
/// sf::Texture makes it easy to convert from/to sf::Image, but
|
654
|
+
/// keep in mind that these calls require transfers between
|
655
|
+
/// the graphics card and the central memory, therefore they are
|
656
|
+
/// slow operations.
|
657
|
+
///
|
658
|
+
/// A texture can be loaded from an image, but also directly
|
659
|
+
/// from a file/memory/stream. The necessary shortcuts are defined
|
660
|
+
/// so that you don't need an image first for the most common cases.
|
661
|
+
/// However, if you want to perform some modifications on the pixels
|
662
|
+
/// before creating the final texture, you can load your file to a
|
663
|
+
/// sf::Image, do whatever you need with the pixels, and then call
|
664
|
+
/// Texture::loadFromImage.
|
665
|
+
///
|
666
|
+
/// Since they live in the graphics card memory, the pixels of a texture
|
667
|
+
/// cannot be accessed without a slow copy first. And they cannot be
|
668
|
+
/// accessed individually. Therefore, if you need to read the texture's
|
669
|
+
/// pixels (like for pixel-perfect collisions), it is recommended to
|
670
|
+
/// store the collision information separately, for example in an array
|
671
|
+
/// of booleans.
|
672
|
+
///
|
673
|
+
/// Like sf::Image, sf::Texture can handle a unique internal
|
674
|
+
/// representation of pixels, which is RGBA 32 bits. This means
|
675
|
+
/// that a pixel must be composed of 8 bits red, green, blue and
|
676
|
+
/// alpha channels -- just like a sf::Color.
|
677
|
+
///
|
678
|
+
/// Usage example:
|
679
|
+
/// \code
|
680
|
+
/// // This example shows the most common use of sf::Texture:
|
681
|
+
/// // drawing a sprite
|
682
|
+
///
|
683
|
+
/// // Load a texture from a file
|
684
|
+
/// sf::Texture texture;
|
685
|
+
/// if (!texture.loadFromFile("texture.png"))
|
686
|
+
/// return -1;
|
687
|
+
///
|
688
|
+
/// // Assign it to a sprite
|
689
|
+
/// sf::Sprite sprite;
|
690
|
+
/// sprite.setTexture(texture);
|
691
|
+
///
|
692
|
+
/// // Draw the textured sprite
|
693
|
+
/// window.draw(sprite);
|
694
|
+
/// \endcode
|
695
|
+
///
|
696
|
+
/// \code
|
697
|
+
/// // This example shows another common use of sf::Texture:
|
698
|
+
/// // streaming real-time data, like video frames
|
699
|
+
///
|
700
|
+
/// // Create an empty texture
|
701
|
+
/// sf::Texture texture;
|
702
|
+
/// if (!texture.create(640, 480))
|
703
|
+
/// return -1;
|
704
|
+
///
|
705
|
+
/// // Create a sprite that will display the texture
|
706
|
+
/// sf::Sprite sprite(texture);
|
707
|
+
///
|
708
|
+
/// while (...) // the main loop
|
709
|
+
/// {
|
710
|
+
/// ...
|
711
|
+
///
|
712
|
+
/// // update the texture
|
713
|
+
/// sf::Uint8* pixels = ...; // get a fresh chunk of pixels (the next frame of a movie, for example)
|
714
|
+
/// texture.update(pixels);
|
715
|
+
///
|
716
|
+
/// // draw it
|
717
|
+
/// window.draw(sprite);
|
718
|
+
///
|
719
|
+
/// ...
|
720
|
+
/// }
|
721
|
+
///
|
722
|
+
/// \endcode
|
723
|
+
///
|
724
|
+
/// Like sf::Shader that can be used as a raw OpenGL shader,
|
725
|
+
/// sf::Texture can also be used directly as a raw texture for
|
726
|
+
/// custom OpenGL geometry.
|
727
|
+
/// \code
|
728
|
+
/// sf::Texture::bind(&texture);
|
729
|
+
/// ... render OpenGL geometry ...
|
730
|
+
/// sf::Texture::bind(NULL);
|
731
|
+
/// \endcode
|
732
|
+
///
|
733
|
+
/// \see sf::Sprite, sf::Image, sf::RenderTexture
|
734
|
+
///
|
735
|
+
////////////////////////////////////////////////////////////
|