gosu 0.7.22 → 0.7.23
Sign up to get free protection for your applications and to get access to all the features.
- data/Gosu/Audio.hpp +2 -0
- data/Gosu/Fwd.hpp +0 -1
- data/Gosu/Gosu.hpp +1 -1
- data/Gosu/Graphics.hpp +12 -11
- data/Gosu/GraphicsBase.hpp +5 -0
- data/Gosu/Image.hpp +0 -14
- data/Gosu/Input.hpp +32 -18
- data/Gosu/Text.hpp +3 -2
- data/Gosu/Version.hpp +2 -2
- data/Gosu/Window.hpp +21 -8
- data/GosuImpl/Audio/AudioOpenAL.mm +74 -8
- data/GosuImpl/Graphics/Common.hpp +25 -1
- data/GosuImpl/Graphics/DrawOp.hpp +54 -222
- data/GosuImpl/Graphics/DrawOpQueue.hpp +127 -0
- data/GosuImpl/Graphics/FormattedString.hpp +63 -20
- data/GosuImpl/Graphics/GosuView.hpp +5 -8
- data/GosuImpl/Graphics/GosuView.mm +36 -65
- data/GosuImpl/Graphics/Graphics.cpp +121 -110
- data/GosuImpl/Graphics/Image.cpp +0 -51
- data/GosuImpl/Graphics/Macro.hpp +1 -0
- data/GosuImpl/Graphics/RenderState.hpp +107 -0
- data/GosuImpl/Graphics/TexChunk.cpp +1 -10
- data/GosuImpl/Graphics/Text.cpp +22 -10
- data/GosuImpl/Graphics/TextMac.cpp +2 -4
- data/GosuImpl/Graphics/TextTouch.mm +14 -21
- data/GosuImpl/Graphics/TextWin.cpp +5 -2
- data/GosuImpl/Graphics/Texture.cpp +11 -10
- data/GosuImpl/Graphics/Transform.cpp +3 -1
- data/GosuImpl/Input/AccelerometerReader.hpp +10 -0
- data/GosuImpl/Input/AccelerometerReader.mm +31 -0
- data/GosuImpl/InputMac.mm +51 -24
- data/GosuImpl/InputTouch.mm +112 -1
- data/GosuImpl/InputWin.cpp +27 -3
- data/GosuImpl/InputX.cpp +21 -0
- data/GosuImpl/MacUtility.hpp +33 -0
- data/GosuImpl/Orientation.hpp +15 -0
- data/GosuImpl/Orientation.mm +34 -0
- data/GosuImpl/RubyGosu.swg +7 -9
- data/GosuImpl/RubyGosu_wrap.cxx +328 -82
- data/GosuImpl/RubyGosu_wrap.h +3 -0
- data/GosuImpl/TextInputWin.cpp +2 -0
- data/GosuImpl/Utility.cpp +2 -0
- data/GosuImpl/WindowMac.mm +13 -19
- data/GosuImpl/WindowTouch.mm +44 -32
- data/GosuImpl/WindowWin.cpp +20 -12
- data/GosuImpl/WindowX.cpp +33 -23
- data/examples/CptnRuby.rb +8 -9
- data/lib/gosu.rb +0 -0
- data/lib/gosu/swig_patches.rb +0 -12
- data/linux/extconf.rb +2 -2
- metadata +11 -7
- data/Gosu/RotFlip.hpp +0 -125
- data/GosuImpl/Graphics/RotFlip.cpp +0 -184
data/GosuImpl/Graphics/Image.cpp
CHANGED
@@ -107,57 +107,6 @@ void Gosu::Image::drawRot(double x, double y, ZPos z,
|
|
107
107
|
c, z, mode);
|
108
108
|
}
|
109
109
|
|
110
|
-
void Gosu::Image::drawRotFlip(double x, double y, ZPos z,
|
111
|
-
RotFlip rf,
|
112
|
-
double factorX, double factorY,
|
113
|
-
Color c,
|
114
|
-
AlphaMode mode) const
|
115
|
-
{
|
116
|
-
drawRotFlipMod(x, y, z, rf, factorX, factorY, c, c, c, c, mode);
|
117
|
-
}
|
118
|
-
|
119
|
-
void Gosu::Image::drawRotFlipMod(double x, double y, ZPos z,
|
120
|
-
RotFlip rf,
|
121
|
-
double factorX, double factorY,
|
122
|
-
Color c1, Color c2, Color c3, Color c4,
|
123
|
-
AlphaMode mode) const
|
124
|
-
{
|
125
|
-
double offsetX;
|
126
|
-
double offsetY;
|
127
|
-
|
128
|
-
if (rf.rotated())
|
129
|
-
{
|
130
|
-
offsetX = height() * factorY / 2;
|
131
|
-
offsetY = width() * factorX / 2;
|
132
|
-
}
|
133
|
-
else
|
134
|
-
{
|
135
|
-
offsetX = width() * factorX / 2;
|
136
|
-
offsetY = height() * factorY / 2;
|
137
|
-
}
|
138
|
-
|
139
|
-
struct Point
|
140
|
-
{
|
141
|
-
double x, y;
|
142
|
-
};
|
143
|
-
|
144
|
-
Point corners[4] = { { x - offsetX, y - offsetY },
|
145
|
-
{ x + offsetX, y - offsetY },
|
146
|
-
{ x - offsetX, y + offsetY },
|
147
|
-
{ x + offsetX, y + offsetY } };
|
148
|
-
|
149
|
-
Point* vertices[4] =
|
150
|
-
{ &corners[rf.mapCorner(0)], &corners[rf.mapCorner(1)],
|
151
|
-
&corners[rf.mapCorner(2)], &corners[rf.mapCorner(3)] };
|
152
|
-
|
153
|
-
data->draw(
|
154
|
-
vertices[0]->x, vertices[0]->y, c1,
|
155
|
-
vertices[1]->x, vertices[1]->y, c2,
|
156
|
-
vertices[2]->x, vertices[2]->y, c3,
|
157
|
-
vertices[3]->x, vertices[3]->y, c4,
|
158
|
-
z, mode);
|
159
|
-
}
|
160
|
-
|
161
110
|
const Gosu::ImageData& Gosu::Image::getData() const
|
162
111
|
{
|
163
112
|
return *data;
|
data/GosuImpl/Graphics/Macro.hpp
CHANGED
@@ -0,0 +1,107 @@
|
|
1
|
+
#ifndef GOSUIMPL_GRAPHICS_RENDERSTATE_HPP
|
2
|
+
#define GOSUIMPL_GRAPHICS_RENDERSTATE_HPP
|
3
|
+
|
4
|
+
#include <GosuImpl/Graphics/Common.hpp>
|
5
|
+
|
6
|
+
class Gosu::RenderState
|
7
|
+
{
|
8
|
+
GLuint texName;
|
9
|
+
Transform* transform;
|
10
|
+
unsigned clipX, clipY, clipWidth, clipHeight;
|
11
|
+
AlphaMode mode;
|
12
|
+
|
13
|
+
public:
|
14
|
+
RenderState()
|
15
|
+
: texName(NO_TEXTURE), transform(0), clipWidth(NO_CLIPPING), mode(amDefault)
|
16
|
+
{
|
17
|
+
glMatrixMode(GL_MODELVIEW);
|
18
|
+
glPushMatrix();
|
19
|
+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
20
|
+
}
|
21
|
+
|
22
|
+
~RenderState()
|
23
|
+
{
|
24
|
+
setClipRect(NO_CLIPPING, NO_CLIPPING, NO_CLIPPING, NO_CLIPPING);
|
25
|
+
setTexName(NO_TEXTURE);
|
26
|
+
glPopMatrix();
|
27
|
+
}
|
28
|
+
|
29
|
+
void setTransform(Transform* newTransform)
|
30
|
+
{
|
31
|
+
if (newTransform == transform)
|
32
|
+
return;
|
33
|
+
|
34
|
+
glPopMatrix();
|
35
|
+
glPushMatrix();
|
36
|
+
#ifndef GOSU_IS_IPHONE
|
37
|
+
glMultMatrixd(newTransform->data());
|
38
|
+
#else
|
39
|
+
boost::array<float, 16> matrix;
|
40
|
+
matrix = *newTransform;
|
41
|
+
glMultMatrixf(matrix.data());
|
42
|
+
#endif
|
43
|
+
transform = newTransform;
|
44
|
+
}
|
45
|
+
|
46
|
+
void setTexName(GLuint newTexName)
|
47
|
+
{
|
48
|
+
if (newTexName == texName)
|
49
|
+
return;
|
50
|
+
|
51
|
+
if (newTexName != NO_TEXTURE)
|
52
|
+
{
|
53
|
+
if (texName == NO_TEXTURE)
|
54
|
+
glEnable(GL_TEXTURE_2D);
|
55
|
+
glBindTexture(GL_TEXTURE_2D, newTexName);
|
56
|
+
}
|
57
|
+
else if (texName != NO_TEXTURE)
|
58
|
+
glDisable(GL_TEXTURE_2D);
|
59
|
+
texName = newTexName;
|
60
|
+
}
|
61
|
+
|
62
|
+
void setClipRect(unsigned newClipX, unsigned newClipY,
|
63
|
+
unsigned newClipWidth, unsigned newClipHeight)
|
64
|
+
{
|
65
|
+
if (newClipWidth == NO_CLIPPING)
|
66
|
+
{
|
67
|
+
// Disable clipping
|
68
|
+
if (clipWidth != NO_CLIPPING)
|
69
|
+
{
|
70
|
+
glDisable(GL_SCISSOR_TEST);
|
71
|
+
clipWidth = NO_CLIPPING;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
else
|
75
|
+
{
|
76
|
+
// Enable clipping if off
|
77
|
+
if (clipWidth == NO_CLIPPING)
|
78
|
+
{
|
79
|
+
glEnable(GL_SCISSOR_TEST);
|
80
|
+
glScissor(clipX = newClipX, clipY = newClipY,
|
81
|
+
clipWidth = newClipWidth, clipHeight = newClipHeight);
|
82
|
+
}
|
83
|
+
// Adjust clipping if necessary
|
84
|
+
else if (clipX != newClipX || clipY != newClipY ||
|
85
|
+
clipWidth != newClipWidth || clipHeight != newClipHeight)
|
86
|
+
{
|
87
|
+
glScissor(clipX = newClipX, clipY = newClipY,
|
88
|
+
clipWidth = newClipWidth, clipHeight = newClipHeight);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
void setAlphaMode(AlphaMode newMode)
|
94
|
+
{
|
95
|
+
if (newMode == mode)
|
96
|
+
return;
|
97
|
+
mode = newMode;
|
98
|
+
if (mode == amAdditive)
|
99
|
+
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
100
|
+
else if (mode == amMultiply)
|
101
|
+
glBlendFunc(GL_DST_COLOR, GL_ZERO);
|
102
|
+
else
|
103
|
+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
104
|
+
}
|
105
|
+
};
|
106
|
+
|
107
|
+
#endif
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#include <GosuImpl/Graphics/TexChunk.hpp>
|
2
2
|
#include <GosuImpl/Graphics/Texture.hpp>
|
3
|
-
#include <GosuImpl/Graphics/
|
3
|
+
#include <GosuImpl/Graphics/DrawOpQueue.hpp>
|
4
4
|
#include <Gosu/Bitmap.hpp>
|
5
5
|
#include <Gosu/Graphics.hpp>
|
6
6
|
|
@@ -49,15 +49,6 @@ void Gosu::TexChunk::draw(double x1, double y1, Color c1,
|
|
49
49
|
|
50
50
|
reorderCoordinatesIfNecessary(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
|
51
51
|
|
52
|
-
x1 *= graphics->factorX();
|
53
|
-
y1 *= graphics->factorY();
|
54
|
-
x2 *= graphics->factorX();
|
55
|
-
y2 *= graphics->factorY();
|
56
|
-
x3 *= graphics->factorX();
|
57
|
-
y3 *= graphics->factorY();
|
58
|
-
x4 *= graphics->factorX();
|
59
|
-
y4 *= graphics->factorY();
|
60
|
-
|
61
52
|
newDrawOp.usedVertices = 4;
|
62
53
|
newDrawOp.vertices[0] = DrawOp::Vertex(x1, y1, c1);
|
63
54
|
newDrawOp.vertices[1] = DrawOp::Vertex(x2, y2, c2);
|
data/GosuImpl/Graphics/Text.cpp
CHANGED
@@ -56,7 +56,8 @@ namespace Gosu
|
|
56
56
|
unsigned usedLines, allocatedLines;
|
57
57
|
|
58
58
|
wstring fontName;
|
59
|
-
unsigned fontHeight
|
59
|
+
unsigned fontHeight;
|
60
|
+
int lineSpacing;
|
60
61
|
TextAlign align;
|
61
62
|
|
62
63
|
unsigned spaceWidth_;
|
@@ -68,14 +69,14 @@ namespace Gosu
|
|
68
69
|
{
|
69
70
|
allocatedLines += 10;
|
70
71
|
bmp.resize(bmp.width(),
|
71
|
-
|
72
|
+
fontHeight * allocatedLines + lineSpacing * (allocatedLines - 1),
|
72
73
|
Color::NONE);
|
73
74
|
}
|
74
75
|
}
|
75
76
|
|
76
77
|
public:
|
77
78
|
TextBlockBuilder(const wstring& fontName, unsigned fontHeight,
|
78
|
-
|
79
|
+
int lineSpacing, unsigned width, TextAlign align)
|
79
80
|
{
|
80
81
|
usedLines = 0;
|
81
82
|
allocatedLines = 10;
|
@@ -118,8 +119,9 @@ namespace Gosu
|
|
118
119
|
unsigned words = end - begin;
|
119
120
|
|
120
121
|
unsigned totalSpacing = 0;
|
121
|
-
|
122
|
-
|
122
|
+
if (begin < end)
|
123
|
+
for (Words::const_iterator i = begin; i != end - 1; ++i)
|
124
|
+
totalSpacing += i->spaceWidth;
|
123
125
|
|
124
126
|
// Where does the line start? (y)
|
125
127
|
unsigned top = (usedLines - 1) * (fontHeight + lineSpacing);
|
@@ -182,7 +184,7 @@ namespace Gosu
|
|
182
184
|
{
|
183
185
|
Bitmap result = bmp;
|
184
186
|
result.resize(result.width(),
|
185
|
-
usedLines * (
|
187
|
+
fontHeight * usedLines + lineSpacing * (usedLines - 1));
|
186
188
|
return result;
|
187
189
|
}
|
188
190
|
|
@@ -299,9 +301,12 @@ namespace Gosu
|
|
299
301
|
}
|
300
302
|
|
301
303
|
Gosu::Bitmap Gosu::createText(const std::wstring& text,
|
302
|
-
const std::wstring& fontName, unsigned fontHeight,
|
304
|
+
const std::wstring& fontName, unsigned fontHeight, int lineSpacing,
|
303
305
|
unsigned maxWidth, TextAlign align, unsigned fontFlags)
|
304
306
|
{
|
307
|
+
if (lineSpacing <= -static_cast<int>(fontHeight))
|
308
|
+
throw std::logic_error("negative line spacing of more than line height impossible");
|
309
|
+
|
305
310
|
FormattedString fs(boost::replace_all_copy(text, L"\r\n", L"\n"), fontFlags);
|
306
311
|
if (fs.length() == 0)
|
307
312
|
{
|
@@ -312,8 +317,7 @@ Gosu::Bitmap Gosu::createText(const std::wstring& text,
|
|
312
317
|
|
313
318
|
// Set up the builder object which will manage all the drawing and
|
314
319
|
// conversions for us.
|
315
|
-
TextBlockBuilder builder(fontName, fontHeight,
|
316
|
-
lineSpacing, maxWidth, align);
|
320
|
+
TextBlockBuilder builder(fontName, fontHeight, lineSpacing, maxWidth, align);
|
317
321
|
|
318
322
|
// Let the process* functions draw everything.
|
319
323
|
processText(builder, fs);
|
@@ -381,7 +385,15 @@ void Gosu::registerEntity(const std::wstring& name, const Gosu::Bitmap& replacem
|
|
381
385
|
entities[name].reset(new Bitmap(replacement));
|
382
386
|
}
|
383
387
|
|
388
|
+
bool Gosu::isEntity(const std::wstring& name)
|
389
|
+
{
|
390
|
+
return entities[name];
|
391
|
+
}
|
392
|
+
|
384
393
|
const Gosu::Bitmap& Gosu::entityBitmap(const std::wstring& name)
|
385
394
|
{
|
386
|
-
|
395
|
+
boost::shared_ptr<Gosu::Bitmap>& ptr = entities[name];
|
396
|
+
if (!ptr)
|
397
|
+
throw std::runtime_error("Unknown entity: " + Gosu::wstringToUTF8(name));
|
398
|
+
return *ptr;
|
387
399
|
}
|
@@ -223,8 +223,6 @@ void Gosu::drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
|
|
223
223
|
helper.context());
|
224
224
|
}
|
225
225
|
|
226
|
-
Bitmap wholeText;
|
227
|
-
wholeText.resize(width, fontHeight);
|
228
226
|
for (unsigned relY = 0; relY < fontHeight; ++relY)
|
229
227
|
for (unsigned relX = 0; relX < width; ++relX)
|
230
228
|
{
|
@@ -233,9 +231,9 @@ void Gosu::drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
|
|
233
231
|
#else
|
234
232
|
Color::Channel alpha = Color(buf[relY * width + relX]).alpha();
|
235
233
|
#endif
|
236
|
-
|
234
|
+
if (alpha != 0)
|
235
|
+
bitmap.setPixel(x + relX, y + relY, multiply(c, Color(alpha, 0xff, 0xff, 0xff)));
|
237
236
|
}
|
238
|
-
bitmap.insert(wholeText, x, y);
|
239
237
|
}
|
240
238
|
|
241
239
|
#endif
|
@@ -21,17 +21,9 @@ typedef NSFont OSXFont;
|
|
21
21
|
|
22
22
|
namespace
|
23
23
|
{
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
{
|
28
|
-
CFTypeRef ref;
|
29
|
-
public:
|
30
|
-
explicit CFScope(CFTypeRef ref) : ref(ref) {}
|
31
|
-
~CFScope() { CFRelease(ref); }
|
32
|
-
CFTypeRef get() { return ref; }
|
33
|
-
};
|
34
|
-
|
24
|
+
using Gosu::ObjRef;
|
25
|
+
using Gosu::CFRef;
|
26
|
+
|
35
27
|
// If a font is a filename, loads the font and returns its family name that can be used
|
36
28
|
// like any system font. Otherwise, just returns the family name.
|
37
29
|
std::wstring normalizeFont(const std::wstring& fontName)
|
@@ -49,32 +41,32 @@ namespace
|
|
49
41
|
if (familyOfFiles.count(fontName) > 0)
|
50
42
|
return familyOfFiles[fontName];
|
51
43
|
|
52
|
-
|
44
|
+
CFRef<CFStringRef> urlString(
|
53
45
|
CFStringCreateWithBytes(NULL,
|
54
46
|
reinterpret_cast<const UInt8*>(fontName.c_str()),
|
55
47
|
fontName.length() * sizeof(wchar_t),
|
56
48
|
kCFStringEncodingUTF32LE, NO));
|
57
|
-
|
58
|
-
CFURLCreateWithFileSystemPath(NULL, urlString.
|
49
|
+
CFRef<CFURLRef> url(
|
50
|
+
CFURLCreateWithFileSystemPath(NULL, urlString.obj(),
|
59
51
|
kCFURLPOSIXPathStyle, YES));
|
60
52
|
if (!url.get())
|
61
53
|
return familyOfFiles[fontName] = Gosu::defaultFontName();
|
62
54
|
|
63
|
-
|
64
|
-
CTFontManagerCreateFontDescriptorsFromURL(url.
|
55
|
+
CFRef<CFArrayRef> array(
|
56
|
+
CTFontManagerCreateFontDescriptorsFromURL(url.obj()));
|
65
57
|
|
66
|
-
if (array.get() == NULL || CFArrayGetCount(array.
|
67
|
-
!CTFontManagerRegisterFontsForURL(url.
|
58
|
+
if (array.get() == NULL || CFArrayGetCount(array.obj()) < 1 ||
|
59
|
+
!CTFontManagerRegisterFontsForURL(url.obj(),
|
68
60
|
kCTFontManagerScopeProcess, NULL))
|
69
61
|
return familyOfFiles[fontName] = Gosu::defaultFontName();
|
70
62
|
|
71
63
|
CTFontDescriptorRef ref =
|
72
64
|
(CTFontDescriptorRef)CFArrayGetValueAtIndex(array.get(), 0);
|
73
|
-
|
65
|
+
CFRef<CFStringRef> fontNameStr(
|
74
66
|
(CFStringRef)CTFontDescriptorCopyAttribute(ref, kCTFontFamilyNameAttribute));
|
75
67
|
|
76
68
|
const char* utf8FontName =
|
77
|
-
[(NSString*)fontNameStr.
|
69
|
+
[(NSString*)fontNameStr.obj() cStringUsingEncoding: NSUTF8StringEncoding];
|
78
70
|
return familyOfFiles[fontName] = Gosu::utf8ToWstring(utf8FontName);
|
79
71
|
#endif
|
80
72
|
}
|
@@ -88,7 +80,7 @@ namespace
|
|
88
80
|
OSXFont* result = usedFonts[make_pair(fontName, make_pair(fontFlags, height))];
|
89
81
|
if (!result)
|
90
82
|
{
|
91
|
-
|
83
|
+
ObjRef<NSString> name([[NSString alloc] initWithUTF8String: Gosu::wstringToUTF8(fontName).c_str()]);
|
92
84
|
#ifdef GOSU_IS_IPHONE
|
93
85
|
result = [OSXFont fontWithName: name.obj() size: height];
|
94
86
|
#else
|
@@ -184,6 +176,7 @@ void Gosu::drawText(Bitmap& bitmap, const wstring& text, int x, int y,
|
|
184
176
|
// Get the width and height of the image
|
185
177
|
Bitmap bmp;
|
186
178
|
bmp.resize(width, fontHeight);
|
179
|
+
bmp.insert(bitmap, -x, -y);
|
187
180
|
|
188
181
|
// Use a temporary context to draw the CGImage to the buffer.
|
189
182
|
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
@@ -109,10 +109,11 @@ namespace Gosu
|
|
109
109
|
fontName = customFonts[fontName];
|
110
110
|
}
|
111
111
|
|
112
|
-
|
112
|
+
static std::map<std::pair<std::wstring, unsigned>, HFONT> loadedFonts;
|
113
113
|
|
114
114
|
HFONT font;
|
115
|
-
|
115
|
+
std::pair<std::wstring, unsigned> key =
|
116
|
+
std::make_pair(fontName, fontHeight | fontFlags << 16);
|
116
117
|
if (loadedFonts.count(key) == 0)
|
117
118
|
{
|
118
119
|
LOGFONT logfont = { fontHeight, 0, 0, 0,
|
@@ -174,6 +175,8 @@ void Gosu::drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
|
|
174
175
|
{
|
175
176
|
Color pixel = c;
|
176
177
|
Color::Channel srcAlpha = GetPixel(helper.context(), relX, relY) & 0xff;
|
178
|
+
if (srcAlpha == 0)
|
179
|
+
continue;
|
177
180
|
pixel = multiply(c, Color(srcAlpha, 255, 255, 255));
|
178
181
|
if (pixel != 0 && x + relX >= 0 && x + relX < bitmap.width() &&
|
179
182
|
y + relY >= 0 && y + relY < bitmap.height())
|
@@ -9,12 +9,17 @@
|
|
9
9
|
#define GL_BGRA 0x80E1
|
10
10
|
#endif
|
11
11
|
|
12
|
-
// TODO:
|
12
|
+
// TODO: Move from Texture:: to local namespace and use MAX_TEXTURE_SIZE instead.
|
13
13
|
unsigned Gosu::Texture::maxTextureSize()
|
14
14
|
{
|
15
15
|
#if defined(GOSU_IS_MAC)
|
16
16
|
// Includes the iPhone
|
17
17
|
return 1024;
|
18
|
+
#elif defined(GOSU_IS_UNIX)
|
19
|
+
// Since we cannot get the max. texture size until after context creation, we have to
|
20
|
+
// just be pessimistic about it until Gosu is restructured to create the context
|
21
|
+
// earlier. Otherwise, libGL will segfault left and right.
|
22
|
+
return 512;
|
18
23
|
#else
|
19
24
|
const static unsigned MIN_SIZE = 256, MAX_SIZE = 1024;
|
20
25
|
|
@@ -35,7 +40,7 @@ unsigned Gosu::Texture::maxTextureSize()
|
|
35
40
|
#endif
|
36
41
|
}
|
37
42
|
|
38
|
-
|
43
|
+
const unsigned Gosu::MAX_TEXTURE_SIZE = Gosu::Texture::maxTextureSize();
|
39
44
|
|
40
45
|
namespace Gosu
|
41
46
|
{
|
@@ -147,18 +152,13 @@ void Gosu::Texture::free(unsigned x, unsigned y)
|
|
147
152
|
|
148
153
|
Gosu::Bitmap Gosu::Texture::toBitmap(unsigned x, unsigned y, unsigned width, unsigned height) const
|
149
154
|
{
|
150
|
-
#
|
151
|
-
|
152
|
-
#elif defined(GOSU_IS_IPHONE)
|
153
|
-
unsigned format = GL_RGBA;
|
155
|
+
#ifdef GOSU_IS_IPHONE
|
156
|
+
throw std::logic_error("Texture::toBitmap not supported on iOS");
|
154
157
|
#else
|
155
|
-
unsigned format = GL_BGRA;
|
156
|
-
#endif
|
157
|
-
|
158
158
|
Gosu::Bitmap fullTexture;
|
159
159
|
fullTexture.resize(size(), size());
|
160
160
|
glBindTexture(GL_TEXTURE_2D, name);
|
161
|
-
glGetTexImage(GL_TEXTURE_2D, 0,
|
161
|
+
glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, fullTexture.data());
|
162
162
|
Gosu::Bitmap bitmap;
|
163
163
|
bitmap.resize(width, height);
|
164
164
|
bitmap.insert(fullTexture, -int(x), -int(y));
|
@@ -174,4 +174,5 @@ Gosu::Bitmap Gosu::Texture::toBitmap(unsigned x, unsigned y, unsigned width, uns
|
|
174
174
|
#endif
|
175
175
|
|
176
176
|
return bitmap;
|
177
|
+
#endif
|
177
178
|
}
|