gosu 0.7.11 → 0.7.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/Gosu/Audio.hpp +33 -16
  2. data/Gosu/GraphicsBase.hpp +6 -1
  3. data/Gosu/Input.hpp +8 -2
  4. data/Gosu/Platform.hpp +63 -61
  5. data/Gosu/Window.hpp +11 -0
  6. data/GosuImpl/AudioFmod.cpp +89 -16
  7. data/GosuImpl/AudioSDL.cpp +59 -19
  8. data/GosuImpl/Graphics/BitmapUtils.cpp +3 -0
  9. data/GosuImpl/Graphics/Common.hpp +8 -3
  10. data/GosuImpl/Graphics/DrawOp.hpp +70 -7
  11. data/GosuImpl/Graphics/Graphics.cpp +34 -2
  12. data/GosuImpl/Graphics/TexChunk.cpp +7 -1
  13. data/GosuImpl/Graphics/Texture.cpp +31 -9
  14. data/GosuImpl/Iconv.hpp +3 -0
  15. data/GosuImpl/InputMac.mm +31 -10
  16. data/GosuImpl/InputWin.cpp +8 -0
  17. data/GosuImpl/InputX.cpp +64 -45
  18. data/GosuImpl/Math.cpp +1 -1
  19. data/GosuImpl/RubyGosu.swg +27 -7
  20. data/GosuImpl/RubyGosu_wrap.cxx +338 -205
  21. data/GosuImpl/Utility.cpp +1 -0
  22. data/GosuImpl/WindowMac.mm +29 -3
  23. data/GosuImpl/WindowWin.cpp +16 -5
  24. data/GosuImpl/WindowX.cpp +3 -3
  25. data/README.txt +7 -3
  26. data/Rakefile +2 -1
  27. data/mac/Gosu.icns +0 -0
  28. data/mac/Gosu.xcodeproj/jlnr.mode1v3 +74 -75
  29. data/mac/Gosu.xcodeproj/jlnr.pbxuser +731 -257
  30. data/mac/Gosu.xcodeproj/jlnr.perspectivev3 +1531 -0
  31. data/reference/Async_8hpp-source.html +1 -1
  32. data/reference/Audio_8hpp-source.html +68 -58
  33. data/reference/Audio_8hpp.html +1 -1
  34. data/reference/AutoLink_8hpp-source.html +1 -1
  35. data/reference/AutoLink_8hpp.html +1 -1
  36. data/reference/Bitmap_8hpp-source.html +1 -1
  37. data/reference/Bitmap_8hpp.html +1 -1
  38. data/reference/ButtonsMac_8hpp-source.html +1 -1
  39. data/reference/ButtonsWin_8hpp-source.html +1 -1
  40. data/reference/ButtonsX_8hpp-source.html +1 -1
  41. data/reference/Color_8hpp-source.html +1 -1
  42. data/reference/Color_8hpp.html +1 -1
  43. data/reference/Directories_8hpp-source.html +1 -1
  44. data/reference/Directories_8hpp.html +1 -1
  45. data/reference/Font_8hpp-source.html +1 -1
  46. data/reference/Font_8hpp.html +1 -1
  47. data/reference/Fwd_8hpp-source.html +1 -1
  48. data/reference/Fwd_8hpp.html +1 -1
  49. data/reference/Gosu_8hpp-source.html +1 -1
  50. data/reference/Gosu_8hpp.html +1 -1
  51. data/reference/GraphicsBase_8hpp-source.html +28 -26
  52. data/reference/GraphicsBase_8hpp.html +4 -1
  53. data/reference/Graphics_8hpp-source.html +1 -1
  54. data/reference/Graphics_8hpp.html +1 -1
  55. data/reference/IO_8hpp-source.html +1 -1
  56. data/reference/IO_8hpp.html +1 -1
  57. data/reference/ImageData_8hpp-source.html +1 -1
  58. data/reference/ImageData_8hpp.html +1 -1
  59. data/reference/Image_8hpp-source.html +1 -1
  60. data/reference/Image_8hpp.html +1 -1
  61. data/reference/Input_8hpp-source.html +19 -16
  62. data/reference/Input_8hpp.html +1 -1
  63. data/reference/Math_8hpp-source.html +1 -1
  64. data/reference/Math_8hpp.html +1 -1
  65. data/reference/Platform_8hpp-source.html +22 -20
  66. data/reference/Platform_8hpp.html +1 -1
  67. data/reference/RotFlip_8hpp-source.html +1 -1
  68. data/reference/RotFlip_8hpp.html +1 -1
  69. data/reference/Sockets_8hpp-source.html +1 -1
  70. data/reference/Sockets_8hpp.html +1 -1
  71. data/reference/TextInput_8hpp-source.html +1 -1
  72. data/reference/TextInput_8hpp.html +1 -1
  73. data/reference/Text_8hpp-source.html +1 -1
  74. data/reference/Text_8hpp.html +1 -1
  75. data/reference/Timing_8hpp-source.html +1 -1
  76. data/reference/Timing_8hpp.html +1 -1
  77. data/reference/Utility_8hpp-source.html +1 -1
  78. data/reference/Utility_8hpp.html +1 -1
  79. data/reference/WinUtility_8hpp-source.html +1 -1
  80. data/reference/WinUtility_8hpp.html +1 -1
  81. data/reference/Window_8hpp-source.html +67 -56
  82. data/reference/Window_8hpp.html +1 -1
  83. data/reference/annotated.html +1 -1
  84. data/reference/classGosu_1_1Audio-members.html +1 -1
  85. data/reference/classGosu_1_1Audio.html +1 -1
  86. data/reference/classGosu_1_1Bitmap-members.html +1 -1
  87. data/reference/classGosu_1_1Bitmap.html +1 -1
  88. data/reference/classGosu_1_1Buffer-members.html +1 -1
  89. data/reference/classGosu_1_1Buffer.html +1 -1
  90. data/reference/classGosu_1_1Button-members.html +1 -1
  91. data/reference/classGosu_1_1Button.html +1 -1
  92. data/reference/classGosu_1_1Color-members.html +1 -1
  93. data/reference/classGosu_1_1Color.html +1 -1
  94. data/reference/classGosu_1_1File-members.html +1 -1
  95. data/reference/classGosu_1_1File.html +1 -1
  96. data/reference/classGosu_1_1Font-members.html +1 -1
  97. data/reference/classGosu_1_1Font.html +1 -1
  98. data/reference/classGosu_1_1Graphics-members.html +1 -1
  99. data/reference/classGosu_1_1Graphics.html +1 -1
  100. data/reference/classGosu_1_1Image-members.html +1 -1
  101. data/reference/classGosu_1_1Image.html +1 -1
  102. data/reference/classGosu_1_1ImageData-members.html +1 -1
  103. data/reference/classGosu_1_1ImageData.html +1 -1
  104. data/reference/classGosu_1_1Input-members.html +2 -1
  105. data/reference/classGosu_1_1Input.html +34 -1
  106. data/reference/classGosu_1_1MessageSocket-members.html +1 -1
  107. data/reference/classGosu_1_1MessageSocket.html +1 -1
  108. data/reference/classGosu_1_1Resource-members.html +1 -1
  109. data/reference/classGosu_1_1Resource.html +1 -1
  110. data/reference/classGosu_1_1Sample-members.html +3 -3
  111. data/reference/classGosu_1_1Sample.html +23 -11
  112. data/reference/classGosu_1_1SampleInstance-members.html +4 -1
  113. data/reference/classGosu_1_1SampleInstance.html +11 -2
  114. data/reference/classGosu_1_1Song-members.html +5 -2
  115. data/reference/classGosu_1_1Song.html +78 -7
  116. data/reference/classGosu_1_1TextInput-members.html +1 -1
  117. data/reference/classGosu_1_1TextInput.html +1 -1
  118. data/reference/classGosu_1_1Window-members.html +1 -1
  119. data/reference/classGosu_1_1Window.html +1 -1
  120. data/reference/files.html +1 -1
  121. data/reference/functions.html +14 -6
  122. data/reference/functions_enum.html +1 -1
  123. data/reference/functions_func.html +14 -6
  124. data/reference/functions_vars.html +1 -1
  125. data/reference/hierarchy.html +1 -1
  126. data/reference/index.html +1 -1
  127. data/reference/namespaceGosu.html +20 -1
  128. data/reference/namespaceGosu_1_1Colors.html +1 -1
  129. data/reference/namespaceGosu_1_1Win.html +1 -1
  130. data/reference/namespacemembers.html +3 -1
  131. data/reference/namespacemembers_enum.html +1 -1
  132. data/reference/namespacemembers_eval.html +1 -1
  133. data/reference/namespacemembers_func.html +1 -1
  134. data/reference/namespacemembers_type.html +1 -1
  135. data/reference/namespacemembers_vars.html +3 -1
  136. data/reference/namespaces.html +1 -1
  137. data/windows/Gosu.sln +2 -2
  138. data/windows/Gosu.vcproj +8 -7
  139. data/windows/RubyGosu.vcproj +5 -5
  140. metadata +4 -3
  141. data/GosuImpl/Utility.cpp~RF6c566.TMP +0 -95
@@ -50,6 +50,12 @@ Gosu::Audio::~Audio() {
50
50
  mixerInitialized = false;
51
51
  }
52
52
 
53
+ bool Gosu::SampleInstance::alive() const
54
+ {
55
+ return !noSound && channelRegistry[handle] == extra &&
56
+ Mix_Playing(handle) == 1;
57
+ }
58
+
53
59
  Gosu::SampleInstance::SampleInstance(int handle, int extra)
54
60
  : handle(handle), extra(extra)
55
61
  {
@@ -57,26 +63,42 @@ Gosu::SampleInstance::SampleInstance(int handle, int extra)
57
63
 
58
64
  bool Gosu::SampleInstance::playing() const
59
65
  {
60
- return !noSound && channelRegistry[handle] == extra &&
61
- Mix_Playing(handle) == 1;
66
+ return alive() && !Mix_Paused(handle);
67
+ }
68
+
69
+ void Gosu::SampleInstance::resume()
70
+ {
71
+ if (alive())
72
+ Mix_Resume(handle);
73
+ }
74
+
75
+ void Gosu::SampleInstance::pause()
76
+ {
77
+ if (alive())
78
+ Mix_Pause(handle);
79
+ }
80
+
81
+ bool Gosu::SampleInstance::paused() const
82
+ {
83
+ return alive() && Mix_Paused(handle);
62
84
  }
63
85
 
64
86
  void Gosu::SampleInstance::stop()
65
87
  {
66
- if (playing())
88
+ if (alive())
67
89
  Mix_HaltChannel(handle);
68
90
  }
69
91
 
70
92
  void Gosu::SampleInstance::changeVolume(double volume)
71
93
  {
72
- if (playing())
94
+ if (alive())
73
95
  Mix_Volume(handle, clamp<int>(volume * 255, 0, 255));
74
96
  }
75
97
 
76
98
  void Gosu::SampleInstance::changePan(double pan)
77
99
  {
78
100
  int rightPan = clamp<int>(pan * 127, 0, 127);
79
- if (playing())
101
+ if (alive())
80
102
  Mix_SetPanning(handle, 254 - rightPan, rightPan);
81
103
  }
82
104
 
@@ -125,10 +147,11 @@ Gosu::Sample::Sample(Audio& audio, Reader reader) {
125
147
  Gosu::Sample::~Sample() {
126
148
  }
127
149
 
128
- Gosu::SampleInstance Gosu::Sample::play(double volume, double speed) const {
150
+ Gosu::SampleInstance Gosu::Sample::play(double volume, double speed,
151
+ bool looping) const {
129
152
  int channel;
130
153
 
131
- if (noSound || (channel = Mix_PlayChannel(-1, data->rep, 0)) == -1)
154
+ if (noSound || (channel = Mix_PlayChannel(-1, data->rep, looping ? -1 : 0)) == -1)
132
155
  return SampleInstance(-1, -1);
133
156
 
134
157
  int extra = ++channelRegistry[channel];
@@ -144,10 +167,10 @@ Gosu::SampleInstance Gosu::Sample::play(double volume, double speed) const {
144
167
  }
145
168
 
146
169
  Gosu::SampleInstance Gosu::Sample::playPan(double pan, double volume,
147
- double speed) const {
170
+ double speed, bool looping) const {
148
171
  int channel;
149
172
 
150
- if (noSound || (channel = Mix_PlayChannel(-1, data->rep, 0)) == -1)
173
+ if (noSound || (channel = Mix_PlayChannel(-1, data->rep, looping ? -1 : 0)) == -1)
151
174
  return SampleInstance(-1, -1);
152
175
 
153
176
  int extra = ++channelRegistry[channel];
@@ -215,30 +238,48 @@ Gosu::Song::~Song() {
215
238
  stop();
216
239
  }
217
240
 
218
- void Gosu::Song::play() {
241
+ Gosu::Song* Gosu::Song::currentSong() {
242
+ return curSong;
243
+ }
244
+
245
+ void Gosu::Song::play(bool looping) {
219
246
  if (noSound)
220
247
  return;
221
248
 
222
- if (curSong)
223
- curSong->stop();
224
-
225
- assert(curSong == 0);
249
+ if (curSong && curSong != this)
250
+ {
251
+ curSong->stop();
252
+ assert(curSong == 0);
253
+ }
226
254
 
227
- if (Mix_PlayMusic(data->music, 0) < 0)
255
+ if (Mix_PausedMusic())
256
+ Mix_ResumeMusic();
257
+ if (!playing() && Mix_PlayMusic(data->music, looping ? -1 : 0) < 0)
228
258
  throwLastSDLError();
229
- curSong = this;
230
259
  changeVolume(data->volume);
260
+ curSong = this;
261
+ }
262
+
263
+ void Gosu::Song::pause()
264
+ {
265
+ if (curSong == this)
266
+ Mix_PauseMusic();
267
+ }
268
+
269
+ bool Gosu::Song::paused() const
270
+ {
271
+ return curSong == this && Mix_PausedMusic();
231
272
  }
232
273
 
233
274
  void Gosu::Song::stop() {
234
- if (playing()) {
275
+ if (curSong == this) {
235
276
  Mix_HaltMusic();
236
277
  curSong = 0;
237
278
  }
238
279
  }
239
280
 
240
281
  bool Gosu::Song::playing() const {
241
- return curSong == this;
282
+ return curSong == this && !paused();
242
283
  }
243
284
 
244
285
  double Gosu::Song::volume() const {
@@ -252,4 +293,3 @@ void Gosu::Song::changeVolume(double volume) {
252
293
  Mix_VolumeMusic(trunc(data->volume * MIX_MAX_VOLUME));
253
294
  }
254
295
 
255
-
@@ -1,7 +1,9 @@
1
1
  #include <Gosu/Graphics.hpp>
2
2
  #include <Gosu/Bitmap.hpp>
3
3
  #include <Gosu/IO.hpp>
4
+ #include <Gosu/Platform.hpp>
4
5
 
6
+ #ifndef GOSU_IS_IPHONE
5
7
  Gosu::Bitmap Gosu::quickLoadBitmap(const std::wstring& filename)
6
8
  {
7
9
  Buffer buf;
@@ -19,6 +21,7 @@ Gosu::Bitmap Gosu::quickLoadBitmap(const std::wstring& filename)
19
21
  loadFromPNG(bmp, buf.frontReader());
20
22
  return bmp;
21
23
  }
24
+ #endif
22
25
 
23
26
  void Gosu::applyBorderFlags(Bitmap& dest, const Bitmap& source,
24
27
  unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
@@ -1,10 +1,15 @@
1
1
  #ifndef GOSUIMPL_GRAPHICS_COMMON_HPP
2
2
  #define GOSUIMPL_GRAPHICS_COMMON_HPP
3
3
 
4
- #ifdef WIN32
4
+ #include <Gosu/Platform.hpp>
5
+
6
+ #if defined(GOSU_IS_WIN)
5
7
  #include <windows.h>
6
- #endif
7
- #ifdef __APPLE__
8
+ #include <GL/gl.h>
9
+ #elif defined(GOSU_IS_IPHONE)
10
+ #include <OpenGLES/ES1/gl.h>
11
+ #include <OpenGLES/ES1/glext.h>
12
+ #elif defined(GOSU_IS_MAC)
8
13
  #include <OpenGL/gl.h>
9
14
  #else
10
15
  #include <GL/gl.h>
@@ -5,6 +5,7 @@
5
5
  #include <Gosu/Color.hpp>
6
6
  #include <GosuImpl/Graphics/Common.hpp>
7
7
  #include <GosuImpl/Graphics/TexChunk.hpp>
8
+ #include <boost/cstdint.hpp>
8
9
  #include <set>
9
10
 
10
11
  namespace Gosu
@@ -30,6 +31,7 @@ namespace Gosu
30
31
 
31
32
  DrawOp() { clipWidth = 0xffffffff; usedVertices = 0; chunk = 0; }
32
33
 
34
+ #ifndef GOSU_IS_IPHONE
33
35
  void perform() const
34
36
  {
35
37
  if (clipWidth != 0xffffffff)
@@ -59,7 +61,7 @@ namespace Gosu
59
61
  double left, top, right, bottom;
60
62
  if (chunk)
61
63
  chunk->getCoords(left, top, right, bottom);
62
-
64
+
63
65
  for (unsigned i = 0; i < usedVertices; i++)
64
66
  {
65
67
  glColor4f(vertices[i].c.red() / 255.0, vertices[i].c.green() / 255.0,
@@ -82,19 +84,78 @@ namespace Gosu
82
84
  }
83
85
  glVertex2d(vertices[i].x, vertices[i].y);
84
86
  }
85
-
87
+
86
88
  glEnd();
87
-
89
+
88
90
  if (chunk)
89
91
  glDisable(GL_TEXTURE_2D);
90
-
92
+
91
93
  if (clipWidth != 0xffffffff)
92
94
  glDisable(GL_SCISSOR_TEST);
93
95
  }
96
+ #else
97
+ void perform() const
98
+ {
99
+ static GLfloat spriteVertices[8];
100
+ static GLfloat spriteTexcoords[8];
101
+ static boost::uint32_t spriteColors[40];
102
+
103
+ // iPhone specific setup
104
+ static bool isSetup = false;
105
+ if (!isSetup)
106
+ {
107
+ // Sets up pointers and enables states needed for using vertex arrays and textures
108
+ glVertexPointer(2, GL_FLOAT, 0, spriteVertices);
109
+ glEnableClientState(GL_VERTEX_ARRAY);
110
+ glTexCoordPointer(2, GL_FLOAT, 0, spriteTexcoords);
111
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
112
+ glColorPointer(4, GL_UNSIGNED_BYTE, 0, spriteColors);
113
+ glEnableClientState(GL_COLOR_ARRAY);
114
+
115
+ isSetup = true;
116
+ }
117
+
118
+ if (mode == amAdditive)
119
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
120
+ else
121
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
122
+
123
+ if (chunk)
124
+ {
125
+ glEnable(GL_TEXTURE_2D);
126
+ glBindTexture(GL_TEXTURE_2D, chunk->texName());
127
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
128
+
129
+ double left, top, right, bottom;
130
+ chunk->getCoords(left, top, right, bottom);
131
+ spriteTexcoords[0] = left, spriteTexcoords[1] = top;
132
+ spriteTexcoords[2] = right, spriteTexcoords[3] = top;
133
+ spriteTexcoords[4] = left, spriteTexcoords[5] = bottom;
134
+ spriteTexcoords[6] = right, spriteTexcoords[7] = bottom;
135
+ }
136
+
137
+ for (int i = 0; i < usedVertices; ++i)
138
+ {
139
+ spriteVertices[i*2] = vertices[i].x;
140
+ spriteVertices[i*2+1] = vertices[i].y;
141
+ spriteColors[i] = vertices[i].c.abgr();
142
+ }
143
+
144
+ if (usedVertices == 2)
145
+ glDrawArrays(GL_LINES, 0, 2);
146
+ else if (usedVertices == 3)
147
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
148
+ else if (usedVertices == 4)
149
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
150
+
151
+ if (chunk)
152
+ glDisable(GL_TEXTURE_2D);
153
+ }
154
+ #endif
94
155
 
95
156
  bool operator<(const DrawOp& other) const
96
157
  {
97
- return z < other.z; // optimization starts TODAY
158
+ return z < other.z;
98
159
  }
99
160
  };
100
161
 
@@ -109,10 +170,9 @@ namespace Gosu
109
170
  : clipWidth(0xffffffff)
110
171
  {
111
172
  }
112
-
173
+
113
174
  void addDrawOp(DrawOp op, ZPos z)
114
175
  {
115
- op.z = z;
116
176
  if (clipWidth != 0xffffffff)
117
177
  {
118
178
  op.clipX = clipX;
@@ -120,6 +180,9 @@ namespace Gosu
120
180
  op.clipWidth = clipWidth;
121
181
  op.clipHeight = clipHeight;
122
182
  }
183
+ if (z == zImmediate)
184
+ return op.perform();
185
+ op.z = z;
123
186
  set.insert(op);
124
187
  }
125
188
 
@@ -34,14 +34,22 @@ Gosu::Graphics::Graphics(unsigned physWidth, unsigned physHeight, bool fullscree
34
34
  pimpl->physHeight = pimpl->virtHeight = physHeight;
35
35
  pimpl->factorX = pimpl->factorY = 1.0;
36
36
  pimpl->fullscreen = fullscreen;
37
-
37
+
38
38
  glMatrixMode(GL_PROJECTION);
39
39
  glLoadIdentity();
40
40
  glViewport(0, 0, pimpl->physWidth, pimpl->physHeight);
41
+ #ifdef GOSU_IS_IPHONE
42
+ glOrthof(0, pimpl->virtWidth, pimpl->virtHeight, 0, -1, 1);
43
+ #else
41
44
  glOrtho(0, pimpl->virtWidth, pimpl->virtHeight, 0, -1, 1);
42
-
45
+ #endif
46
+
43
47
  glMatrixMode(GL_MODELVIEW);
44
48
  glLoadIdentity();
49
+ #ifdef GOSU_IS_IPHONE
50
+ glTranslatef(physWidth, 0, 0);
51
+ glRotatef(90, 0, 0, 1);
52
+ #endif
45
53
 
46
54
  glEnable(GL_BLEND);
47
55
  }
@@ -93,8 +101,10 @@ void Gosu::Graphics::setResolution(unsigned virtualWidth, unsigned virtualHeight
93
101
 
94
102
  bool Gosu::Graphics::begin(Gosu::Color clearWithColor)
95
103
  {
104
+ #ifndef GOSU_IS_IPHONE
96
105
  // Flush leftover clippings
97
106
  endClipping();
107
+ #endif
98
108
 
99
109
  glClearColor(clearWithColor.red()/255.0,
100
110
  clearWithColor.green()/255.0,
@@ -130,13 +140,20 @@ void Gosu::Graphics::end()
130
140
 
131
141
  void Gosu::Graphics::beginGL()
132
142
  {
143
+ #ifdef GOSU_IS_IPHONE
144
+ throw std::logic_error("Custom OpenGL is unsupported on the iPhone");
145
+ #else
133
146
  pimpl->queue.performDrawOps();
134
147
  glPushAttrib(GL_ALL_ATTRIB_BITS);
135
148
  glDisable(GL_BLEND);
149
+ #endif
136
150
  }
137
151
 
138
152
  void Gosu::Graphics::endGL()
139
153
  {
154
+ #ifdef GOSU_IS_IPHONE
155
+ throw std::logic_error("Custom OpenGL is unsupported on the iPhone");
156
+ #else
140
157
  glPopAttrib();
141
158
 
142
159
  // Restore matrices.
@@ -149,10 +166,14 @@ void Gosu::Graphics::endGL()
149
166
  glMatrixMode(GL_MODELVIEW);
150
167
  glLoadIdentity();
151
168
  glEnable(GL_BLEND);
169
+ #endif
152
170
  }
153
171
 
154
172
  void Gosu::Graphics::beginClipping(int x, int y, unsigned width, unsigned height)
155
173
  {
174
+ #ifdef GOSU_IS_IPHONE
175
+ throw std::logic_error("Clipping is unsupported on the iPhone");
176
+ #else
156
177
  // In doubt, make the clipping region smaller than requested.
157
178
 
158
179
  int physX = static_cast<int>(std::ceil(x * factorX()));
@@ -161,11 +182,16 @@ void Gosu::Graphics::beginClipping(int x, int y, unsigned width, unsigned height
161
182
  unsigned physHeight = static_cast<unsigned>(height * factorY());
162
183
 
163
184
  pimpl->queue.beginClipping(physX, physY, physWidth, physHeight);
185
+ #endif
164
186
  }
165
187
 
166
188
  void Gosu::Graphics::endClipping()
167
189
  {
190
+ #ifdef GOSU_IS_IPHONE
191
+ throw std::logic_error("Clipping is unsupported on the iPhone");
192
+ #else
168
193
  pimpl->queue.endClipping();
194
+ #endif
169
195
  }
170
196
 
171
197
  void Gosu::Graphics::drawLine(double x1, double y1, Color c1,
@@ -231,8 +257,14 @@ void Gosu::Graphics::drawQuad(double x1, double y1, Color c1,
231
257
  op.usedVertices = 4;
232
258
  op.vertices[0] = DrawOp::Vertex(x1, y1, c1);
233
259
  op.vertices[1] = DrawOp::Vertex(x2, y2, c2);
260
+ // TODO: Should be harmonized
261
+ #ifdef GOSU_IS_IPHONE
262
+ op.vertices[2] = DrawOp::Vertex(x3, y3, c3);
263
+ op.vertices[3] = DrawOp::Vertex(x4, y4, c4);
264
+ #else
234
265
  op.vertices[3] = DrawOp::Vertex(x3, y3, c3);
235
266
  op.vertices[2] = DrawOp::Vertex(x4, y4, c4);
267
+ #endif
236
268
 
237
269
  pimpl->queue.addDrawOp(op, z);
238
270
  }
@@ -59,11 +59,17 @@ void Gosu::TexChunk::draw(double x1, double y1, Color c1,
59
59
  newDrawOp.usedVertices = 4;
60
60
  newDrawOp.vertices[0] = DrawOp::Vertex(x1, y1, c1);
61
61
  newDrawOp.vertices[1] = DrawOp::Vertex(x2, y2, c2);
62
+ // TODO: Should be harmonized
63
+ #ifdef GOSU_IS_IPHONE
64
+ newDrawOp.vertices[2] = DrawOp::Vertex(x3, y3, c3);
65
+ newDrawOp.vertices[3] = DrawOp::Vertex(x4, y4, c4);
66
+ #else
62
67
  newDrawOp.vertices[3] = DrawOp::Vertex(x3, y3, c3);
63
68
  newDrawOp.vertices[2] = DrawOp::Vertex(x4, y4, c4);
69
+ #endif
64
70
  newDrawOp.chunk = this;
65
71
  newDrawOp.mode = mode;
66
-
72
+
67
73
  queue->addDrawOp(newDrawOp, z);
68
74
  }
69
75
 
@@ -4,9 +4,17 @@
4
4
  #include <Gosu/Platform.hpp>
5
5
  #include <stdexcept>
6
6
 
7
+ #ifndef GL_BGRA
8
+ #define GL_BGRA 0x80E1
9
+ #endif
10
+
7
11
  // TODO: Not threadsafe.
8
12
  unsigned Gosu::Texture::maxTextureSize()
9
13
  {
14
+ #if defined(GOSU_IS_MAC)
15
+ // Includes the iPhone
16
+ return 1024;
17
+ #else
10
18
  const static unsigned MIN_SIZE = 256, MAX_SIZE = 1024;
11
19
 
12
20
  static unsigned size = 0;
@@ -17,12 +25,17 @@ unsigned Gosu::Texture::maxTextureSize()
17
25
  do
18
26
  {
19
27
  size *= 2;
20
- glTexImage2D(GL_PROXY_TEXTURE_2D, 0, 4, size * 2, size * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
28
+ #ifdef GOSU_IS_IPHONE
29
+ glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, size * 2, size * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
30
+ #else
31
+ glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_BGRA, size * 2, size * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
32
+ #endif
21
33
  glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
22
34
  } while (width != 0 && size < MAX_SIZE);
23
35
  }
24
-
36
+
25
37
  return size;
38
+ #endif
26
39
  }
27
40
 
28
41
  Gosu::Texture::Texture(unsigned size)
@@ -35,8 +48,13 @@ Gosu::Texture::Texture(unsigned size)
35
48
 
36
49
  // Create empty texture.
37
50
  glBindTexture(GL_TEXTURE_2D, name);
51
+ #ifndef GOSU_IS_IPHONE
38
52
  glTexImage2D(GL_TEXTURE_2D, 0, 4, allocator.width(), allocator.height(), 0,
39
53
  GL_RGBA, GL_UNSIGNED_BYTE, 0);
54
+ #else
55
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, allocator.width(), allocator.height(), 0,
56
+ GL_RGBA, GL_UNSIGNED_BYTE, 0);
57
+ #endif
40
58
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
41
59
  }
42
60
 
@@ -70,8 +88,8 @@ std::auto_ptr<Gosu::TexChunk>
70
88
 
71
89
  result.reset(new TexChunk(graphics, queue, ptr, block->left + padding, block->top + padding,
72
90
  block->width - 2 * padding, block->height - 2 * padding, padding));
73
-
74
- #ifdef __BIG_ENDIAN__
91
+
92
+ #if defined(__BIG_ENDIAN__)
75
93
  std::vector<unsigned> pixelData(srcWidth * srcHeight);
76
94
  for (unsigned y = 0; y < srcHeight; ++y)
77
95
  for (unsigned x = 0; x < srcWidth; ++x)
@@ -82,13 +100,17 @@ std::auto_ptr<Gosu::TexChunk>
82
100
  }
83
101
  const unsigned* texData = &pixelData[0];
84
102
  unsigned format = GL_RGBA;
85
- #else
86
- #ifndef GL_BGRA
87
- #define GL_BGRA 0x80E1
88
- #endif
103
+ #elif defined(GOSU_IS_IPHONE)
104
+ std::vector<unsigned> pixelData(srcWidth * srcHeight);
105
+ for (unsigned y = 0; y < srcHeight; ++y)
106
+ for (unsigned x = 0; x < srcWidth; ++x)
107
+ pixelData[y * srcWidth + x] = bmp.getPixel(x, y).abgr();
108
+ const unsigned* texData = &pixelData[0];
109
+ unsigned format = GL_RGBA;
110
+ #else
89
111
  const unsigned* texData = bmp.glCompatibleData();
90
112
  unsigned format = GL_BGRA;
91
- #endif
113
+ #endif
92
114
 
93
115
  glBindTexture(GL_TEXTURE_2D, name);
94
116
  glTexSubImage2D(GL_TEXTURE_2D, 0, block->left, block->top, block->width, block->height,