gosu 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/Gosu/Bitmap.hpp +3 -3
  3. data/Gosu/Directories.hpp +6 -3
  4. data/Gosu/Gosu.hpp +0 -1
  5. data/Gosu/GraphicsBase.hpp +12 -8
  6. data/Gosu/Input.hpp +5 -16
  7. data/Gosu/Platform.hpp +1 -0
  8. data/Gosu/Version.hpp +3 -5
  9. data/Gosu/Window.hpp +7 -8
  10. data/README.txt +3 -3
  11. data/ext/gosu/extconf.rb +17 -16
  12. data/ext/gosu/gosu_wrap.cxx +59 -58
  13. data/ext/gosu/gosu_wrap.h +1 -1
  14. data/rdoc/gosu.rb +285 -283
  15. data/src/{MacUtility.hpp → AppleUtility.hpp} +24 -42
  16. data/src/Audio/ALChannelManagement.hpp +1 -1
  17. data/src/Audio/{AudioOpenAL.cpp → Audio.cpp} +6 -7
  18. data/src/Audio/Audio.mm +1 -0
  19. data/src/Audio/AudioFile.hpp +2 -2
  20. data/src/Audio/AudioToolboxFile.hpp +5 -20
  21. data/src/Audio/OggFile.hpp +44 -56
  22. data/src/Audio/SndFile.hpp +2 -2
  23. data/src/Bitmap/Bitmap.cpp +98 -2
  24. data/src/Bitmap/BitmapIO.cpp +156 -0
  25. data/src/DirectoriesApple.mm +76 -0
  26. data/src/DirectoriesUnix.cpp +5 -12
  27. data/src/DirectoriesWin.cpp +5 -0
  28. data/src/Graphics/BlockAllocator.hpp +2 -2
  29. data/src/Graphics/ClipRectStack.hpp +2 -2
  30. data/src/Graphics/Common.hpp +2 -2
  31. data/src/Graphics/DrawOp.hpp +2 -2
  32. data/src/Graphics/DrawOpQueue.hpp +2 -2
  33. data/src/Graphics/Graphics.cpp +7 -2
  34. data/src/Graphics/LargeImageData.cpp +6 -6
  35. data/src/Graphics/LargeImageData.hpp +3 -3
  36. data/src/Graphics/Macro.hpp +2 -2
  37. data/src/Graphics/RenderState.hpp +2 -2
  38. data/src/Graphics/Resolution.cpp +1 -1
  39. data/src/Graphics/TexChunk.hpp +2 -2
  40. data/src/Graphics/Texture.cpp +21 -16
  41. data/src/Graphics/Texture.hpp +7 -5
  42. data/src/Graphics/TransformStack.hpp +2 -2
  43. data/src/Iconv.hpp +2 -2
  44. data/src/Input/Input.cpp +3 -1
  45. data/src/Input/{InputTouch.mm → InputUIKit.mm} +32 -26
  46. data/src/Input/TextInput.cpp +1 -1
  47. data/src/Text/FormattedString.hpp +2 -2
  48. data/src/Text/TextApple.mm +8 -8
  49. data/src/Text/TextMac.cpp +1 -1
  50. data/src/Text/TextUnix.cpp +1 -1
  51. data/src/UIKit/GosuAppDelegate.h +8 -0
  52. data/src/UIKit/GosuAppDelegate.mm +24 -0
  53. data/src/UIKit/GosuGLView.h +8 -0
  54. data/src/UIKit/GosuGLView.mm +130 -0
  55. data/src/UIKit/GosuViewController.h +13 -0
  56. data/src/UIKit/GosuViewController.mm +214 -0
  57. data/src/UtilityApple.mm +5 -18
  58. data/src/Window.cpp +1 -3
  59. data/src/WindowUIKit.mm +124 -0
  60. data/src/stb_image.h +6437 -0
  61. data/src/stb_image_write.h +730 -0
  62. data/src/stb_vorbis.c +5459 -0
  63. metadata +18 -26
  64. data/Gosu/Sockets.hpp +0 -156
  65. data/src/Audio/AudioOpenAL.mm +0 -1
  66. data/src/Bitmap/BitmapApple.mm +0 -226
  67. data/src/Bitmap/BitmapBMP.cpp +0 -79
  68. data/src/Bitmap/BitmapColorKey.cpp +0 -50
  69. data/src/Bitmap/BitmapFreeImage.cpp +0 -174
  70. data/src/Bitmap/BitmapGDIplus.cpp +0 -212
  71. data/src/Bitmap/BitmapUtils.cpp +0 -76
  72. data/src/DirectoriesMac.mm +0 -38
  73. data/src/DirectoriesTouch.mm +0 -38
  74. data/src/GosuView.hpp +0 -15
  75. data/src/GosuView.mm +0 -208
  76. data/src/Input/AccelerometerReader.hpp +0 -10
  77. data/src/Input/AccelerometerReader.mm +0 -31
  78. data/src/Sockets/CommSocket.cpp +0 -305
  79. data/src/Sockets/ListenerSocket.cpp +0 -59
  80. data/src/Sockets/MessageSocket.cpp +0 -128
  81. data/src/Sockets/Socket.cpp +0 -145
  82. data/src/Sockets/Socket.hpp +0 -66
  83. data/src/WindowTouch.mm +0 -243
  84. data/src/X11vroot.h +0 -118
@@ -10,27 +10,27 @@ namespace Gosu
10
10
  bool undocumentedRetrofication = false;
11
11
  }
12
12
 
13
- Gosu::Texture::Texture(unsigned size)
14
- : allocator(size, size)
13
+ Gosu::Texture::Texture(unsigned size, bool retro)
14
+ : allocator_(size, size), retro_(retro)
15
15
  {
16
16
  ensureCurrentContext();
17
17
 
18
18
  // Create texture name.
19
- glGenTextures(1, &name);
20
- if (name == static_cast<GLuint>(-1))
19
+ glGenTextures(1, &texName_);
20
+ if (texName_ == static_cast<GLuint>(-1))
21
21
  throw std::runtime_error("Couldn't create OpenGL texture");
22
22
 
23
23
  // Create empty texture.
24
- glBindTexture(GL_TEXTURE_2D, name);
24
+ glBindTexture(GL_TEXTURE_2D, texName_);
25
25
  #ifdef GOSU_IS_OPENGLES
26
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, allocator.width(), allocator.height(), 0,
26
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, allocator_.width(), allocator_.height(), 0,
27
27
  GL_RGBA, GL_UNSIGNED_BYTE, 0);
28
28
  #else
29
- glTexImage2D(GL_TEXTURE_2D, 0, 4, allocator.width(), allocator.height(), 0,
29
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, allocator_.width(), allocator_.height(), 0,
30
30
  GL_RGBA, GL_UNSIGNED_BYTE, 0);
31
31
  #endif
32
32
 
33
- if (undocumentedRetrofication)
33
+ if (retro || undocumentedRetrofication)
34
34
  {
35
35
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
36
36
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -54,17 +54,22 @@ Gosu::Texture::~Texture()
54
54
  {
55
55
  ensureCurrentContext();
56
56
 
57
- glDeleteTextures(1, &name);
57
+ glDeleteTextures(1, &texName_);
58
58
  }
59
59
 
60
60
  unsigned Gosu::Texture::size() const
61
61
  {
62
- return allocator.width(); // == height
62
+ return allocator_.width(); // == height
63
63
  }
64
64
 
65
65
  GLuint Gosu::Texture::texName() const
66
66
  {
67
- return name;
67
+ return texName_;
68
+ }
69
+
70
+ bool Gosu::Texture::retro() const
71
+ {
72
+ return retro_;
68
73
  }
69
74
 
70
75
  GOSU_UNIQUE_PTR<Gosu::TexChunk>
@@ -73,7 +78,7 @@ GOSU_UNIQUE_PTR<Gosu::TexChunk>
73
78
  GOSU_UNIQUE_PTR<Gosu::TexChunk> result;
74
79
 
75
80
  BlockAllocator::Block block;
76
- if (!allocator.alloc(bmp.width(), bmp.height(), block))
81
+ if (!allocator_.alloc(bmp.width(), bmp.height(), block))
77
82
  return result;
78
83
 
79
84
  result.reset(new TexChunk(ptr, block.left + padding, block.top + padding,
@@ -81,7 +86,7 @@ GOSU_UNIQUE_PTR<Gosu::TexChunk>
81
86
 
82
87
  ensureCurrentContext();
83
88
 
84
- glBindTexture(GL_TEXTURE_2D, name);
89
+ glBindTexture(GL_TEXTURE_2D, texName_);
85
90
  glTexSubImage2D(GL_TEXTURE_2D, 0, block.left, block.top, block.width, block.height,
86
91
  Color::GL_FORMAT, GL_UNSIGNED_BYTE, bmp.data());
87
92
 
@@ -90,12 +95,12 @@ GOSU_UNIQUE_PTR<Gosu::TexChunk>
90
95
 
91
96
  void Gosu::Texture::block(unsigned x, unsigned y, unsigned width, unsigned height)
92
97
  {
93
- allocator.block(x, y, width, height);
98
+ allocator_.block(x, y, width, height);
94
99
  }
95
100
 
96
101
  void Gosu::Texture::free(unsigned x, unsigned y, unsigned width, unsigned height)
97
102
  {
98
- allocator.free(x, y, width, height);
103
+ allocator_.free(x, y, width, height);
99
104
  }
100
105
 
101
106
  Gosu::Bitmap Gosu::Texture::toBitmap(unsigned x, unsigned y, unsigned width, unsigned height) const
@@ -106,7 +111,7 @@ Gosu::Bitmap Gosu::Texture::toBitmap(unsigned x, unsigned y, unsigned width, uns
106
111
  ensureCurrentContext();
107
112
 
108
113
  Gosu::Bitmap fullTexture(size(), size());
109
- glBindTexture(GL_TEXTURE_2D, name);
114
+ glBindTexture(GL_TEXTURE_2D, texName());
110
115
  glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, fullTexture.data());
111
116
  Gosu::Bitmap bitmap(width, height);
112
117
  bitmap.insert(fullTexture, -int(x), -int(y));
@@ -1,5 +1,5 @@
1
- #ifndef GOSUIMPL_GRAPHICS_TEXTURE_HPP
2
- #define GOSUIMPL_GRAPHICS_TEXTURE_HPP
1
+ #ifndef GOSU_SRC_GRAPHICS_TEXTURE_HPP
2
+ #define GOSU_SRC_GRAPHICS_TEXTURE_HPP
3
3
 
4
4
  #include <Gosu/Fwd.hpp>
5
5
  #include <Gosu/Bitmap.hpp>
@@ -13,14 +13,16 @@ namespace Gosu
13
13
  {
14
14
  class Texture
15
15
  {
16
- BlockAllocator allocator;
17
- GLuint name;
16
+ BlockAllocator allocator_;
17
+ GLuint texName_;
18
+ bool retro_;
18
19
 
19
20
  public:
20
- Texture(unsigned size);
21
+ Texture(unsigned size, bool retro);
21
22
  ~Texture();
22
23
  unsigned size() const;
23
24
  GLuint texName() const;
25
+ bool retro() const;
24
26
  GOSU_UNIQUE_PTR<TexChunk>
25
27
  tryAlloc(std::tr1::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding);
26
28
  void block(unsigned x, unsigned y, unsigned width, unsigned height);
@@ -1,5 +1,5 @@
1
- #ifndef GOSUIMPL_GRAPHICS_TRANSFORMSTACK_HPP
2
- #define GOSUIMPL_GRAPHICS_TRANSFORMSTACK_HPP
1
+ #ifndef GOSU_SRC_GRAPHICS_TRANSFORMSTACK_HPP
2
+ #define GOSU_SRC_GRAPHICS_TRANSFORMSTACK_HPP
3
3
 
4
4
  #include "Common.hpp"
5
5
  #include <cassert>
@@ -1,5 +1,5 @@
1
- #ifndef GOSUIMPL_ICONV_HPP
2
- #define GOSUIMPL_ICONV_HPP
1
+ #ifndef GOSU_SRC_ICONV_HPP
2
+ #define GOSU_SRC_ICONV_HPP
3
3
 
4
4
  #include <Gosu/Platform.hpp>
5
5
 
@@ -2,7 +2,7 @@
2
2
  #include <Gosu/TextInput.hpp>
3
3
  #include <Gosu/TR1.hpp>
4
4
  #include <Gosu/Utility.hpp>
5
- #include <SDL2/SDL.h>
5
+ #include <SDL.h>
6
6
  #include <cwctype>
7
7
  #include <cstdlib>
8
8
  #include <algorithm>
@@ -381,6 +381,8 @@ void Gosu::Input::setMousePosition(double x, double y)
381
381
  SDL_WarpMouseInWindow(pimpl->window,
382
382
  (x - pimpl->mouseOffsetX) / pimpl->mouseFactorX,
383
383
  (y - pimpl->mouseOffsetY) / pimpl->mouseFactorY);
384
+
385
+ pimpl->updateMousePosition();
384
386
  }
385
387
 
386
388
  void Gosu::Input::setMouseFactors(double factorX, double factorY,
@@ -1,8 +1,7 @@
1
1
  #include <Gosu/Input.hpp>
2
2
  #include <Gosu/TextInput.hpp>
3
3
 
4
- #include "MacUtility.hpp"
5
- #include "AccelerometerReader.hpp"
4
+ #include "AppleUtility.hpp"
6
5
  #import <UIKit/UIKit.h>
7
6
 
8
7
  struct Gosu::TextInput::Impl {};
@@ -20,7 +19,7 @@ struct Gosu::Input::Impl
20
19
  float factorX, factorY;
21
20
  float updateInterval;
22
21
 
23
- ObjRef<NSMutableSet> currentTouchesSet;
22
+ ObjCRef<NSMutableSet> currentTouchesSet;
24
23
  std::auto_ptr<Gosu::Touches> currentTouchesVector;
25
24
 
26
25
  Touch translateTouch(UITouch* uiTouch)
@@ -30,15 +29,6 @@ struct Gosu::Input::Impl
30
29
  touch.x *= factorX, touch.y *= factorY;
31
30
  return touch;
32
31
  }
33
-
34
- ObjRef<AccelerometerReader> accelerometerReader;
35
-
36
- float acceleration(int index)
37
- {
38
- if (accelerometerReader.get() == 0)
39
- accelerometerReader.reset([[AccelerometerReader alloc] initWithUpdateInterval: updateInterval]);
40
- return [accelerometerReader.obj() acceleration][index];
41
- }
42
32
  };
43
33
 
44
34
  Gosu::Input::Input(void* view, float updateInterval)
@@ -57,17 +47,33 @@ Gosu::Input::~Input()
57
47
 
58
48
  void Gosu::Input::feedTouchEvent(int type, void* touches)
59
49
  {
60
- NSSet* uiTouches = (NSSet*)touches;
50
+ NSSet *uiTouches = (NSSet *)touches;
61
51
 
62
52
  pimpl->currentTouchesVector.reset();
63
- std::tr1::function<void (Touch)>* f = &onTouchMoved;
64
- if (type == 0)
65
- [pimpl->currentTouchesSet.get() unionSet: uiTouches], f = &onTouchBegan;
66
- else if (type == 2)
67
- [pimpl->currentTouchesSet.get() minusSet: uiTouches], f = &onTouchEnded;
68
- for (UITouch* uiTouch in uiTouches)
69
- if (*f)
70
- (*f)(pimpl->translateTouch(uiTouch));
53
+
54
+ std::tr1::function<void (Touch)>* callback = nullptr;
55
+
56
+ if (type == 0) {
57
+ [pimpl->currentTouchesSet.get() unionSet:uiTouches];
58
+ callback = &onTouchBegan;
59
+ }
60
+ else if (type == 1) {
61
+ callback = &onTouchMoved;
62
+ }
63
+ else if (type == 2) {
64
+ [pimpl->currentTouchesSet.get() minusSet:uiTouches];
65
+ callback = &onTouchEnded;
66
+ }
67
+ else if (type == 3) {
68
+ [pimpl->currentTouchesSet.get() minusSet:uiTouches];
69
+ callback = &onTouchCancelled;
70
+ }
71
+
72
+ if (callback && *callback) {
73
+ for (UITouch *uiTouch in uiTouches) {
74
+ (*callback)(pimpl->translateTouch(uiTouch));
75
+ }
76
+ }
71
77
  }
72
78
 
73
79
  wchar_t Gosu::Input::idToChar(Button btn)
@@ -80,7 +86,7 @@ Gosu::Button Gosu::Input::charToId(wchar_t ch)
80
86
  return noButton;
81
87
  }
82
88
 
83
- bool Gosu::Input::down(Button btn) const
89
+ bool Gosu::Input::down(Button btn)
84
90
  {
85
91
  return false;
86
92
  }
@@ -120,17 +126,17 @@ const Gosu::Touches& Gosu::Input::currentTouches() const
120
126
 
121
127
  double Gosu::Input::accelerometerX() const
122
128
  {
123
- return pimpl->acceleration(0);
129
+ return 0;
124
130
  }
125
131
 
126
132
  double Gosu::Input::accelerometerY() const
127
133
  {
128
- return pimpl->acceleration(1);
134
+ return 0;
129
135
  }
130
136
 
131
137
  double Gosu::Input::accelerometerZ() const
132
138
  {
133
- return pimpl->acceleration(2);
139
+ return 0;
134
140
  }
135
141
 
136
142
  void Gosu::Input::update()
@@ -138,7 +144,7 @@ void Gosu::Input::update()
138
144
  // Check for dead touches and remove from vector if
139
145
  // necessary
140
146
 
141
- ObjRef<NSMutableSet> deadTouches;
147
+ ObjCRef<NSMutableSet> deadTouches;
142
148
 
143
149
  for (UITouch* touch in pimpl->currentTouchesSet.obj())
144
150
  {
@@ -1,7 +1,7 @@
1
1
  #include <Gosu/TextInput.hpp>
2
2
  #include <Gosu/Input.hpp>
3
3
  #include <Gosu/Utility.hpp>
4
- #include <SDL2/SDL.h>
4
+ #include <SDL.h>
5
5
  #include <cwctype>
6
6
 
7
7
  struct Gosu::TextInput::Impl
@@ -1,5 +1,5 @@
1
- #ifndef GOSUIMPL_GRAPHICS_TEXTFORMATTING
2
- #define GOSUIMPL_GRAPHICS_TEXTFORMATTING
1
+ #ifndef GOSU_SRC_GRAPHICS_TEXTFORMATTING
2
+ #define GOSU_SRC_GRAPHICS_TEXTFORMATTING
3
3
 
4
4
  #include <Gosu/Color.hpp>
5
5
  #include <Gosu/Utility.hpp>
@@ -6,7 +6,7 @@
6
6
  #include <Gosu/Bitmap.hpp>
7
7
  #include <Gosu/Utility.hpp>
8
8
  #include <Gosu/Math.hpp>
9
- #include "../MacUtility.hpp"
9
+ #include "../AppleUtility.hpp"
10
10
  #include <map>
11
11
  #include <cmath>
12
12
  using namespace std;
@@ -22,7 +22,7 @@ typedef NSFont OSXFont;
22
22
 
23
23
  namespace
24
24
  {
25
- using Gosu::ObjRef;
25
+ using Gosu::ObjCRef;
26
26
  using Gosu::CFRef;
27
27
 
28
28
  // If a font is a filename, loads the font and returns its family name that can be used
@@ -81,7 +81,7 @@ namespace
81
81
  OSXFont* result = usedFonts[make_pair(fontName, make_pair(fontFlags, height))];
82
82
  if (!result)
83
83
  {
84
- ObjRef<NSString> name([[NSString alloc] initWithUTF8String: Gosu::wstringToUTF8(fontName).c_str()]);
84
+ ObjCRef<NSString> name([[NSString alloc] initWithUTF8String: Gosu::wstringToUTF8(fontName).c_str()]);
85
85
  #ifdef GOSU_IS_IPHONE
86
86
  result = [OSXFont fontWithName: name.obj() size: height];
87
87
  #else
@@ -120,7 +120,7 @@ namespace
120
120
  nil];
121
121
  if (fontFlags & Gosu::ffUnderline)
122
122
  {
123
- Gosu::ObjRef<NSNumber> underline([[NSNumber alloc] initWithInt:NSUnderlineStyleSingle]);
123
+ Gosu::ObjCRef<NSNumber> underline([[NSNumber alloc] initWithInt:NSUnderlineStyleSingle]);
124
124
  [dict setValue: underline.obj() forKey:NSUnderlineStyleAttributeName];
125
125
  }
126
126
  return dict;
@@ -138,9 +138,9 @@ unsigned Gosu::textWidth(const wstring& text,
138
138
 
139
139
  // This will, of course, compute a too large size; fontHeight is in pixels,
140
140
  // the method expects point.
141
- ObjRef<NSString> string([[NSString alloc] initWithUTF8String: wstringToUTF8(text).c_str()]);
141
+ ObjCRef<NSString> string([[NSString alloc] initWithUTF8String: wstringToUTF8(text).c_str()]);
142
142
  #ifndef GOSU_IS_IPHONE
143
- ObjRef<NSDictionary> attributes(attributeDictionary(font, fontFlags));
143
+ ObjCRef<NSDictionary> attributes(attributeDictionary(font, fontFlags));
144
144
  NSSize size = [string.obj() sizeWithAttributes: attributes.get()];
145
145
  #else
146
146
  CGSize size = [string.obj() sizeWithFont: font];
@@ -158,11 +158,11 @@ void Gosu::drawText(Bitmap& bitmap, const wstring& text, int x, int y,
158
158
  throw std::invalid_argument("the argument to drawText cannot contain line breaks");
159
159
 
160
160
  OSXFont* font = getFont(fontName, fontFlags, fontHeight);
161
- ObjRef<NSString> string([[NSString alloc] initWithUTF8String: wstringToUTF8(text).c_str()]);
161
+ ObjCRef<NSString> string([[NSString alloc] initWithUTF8String: wstringToUTF8(text).c_str()]);
162
162
 
163
163
  // This will, of course, compute a too large size; fontHeight is in pixels, the method expects point.
164
164
  #ifndef GOSU_IS_IPHONE
165
- ObjRef<NSDictionary> attributes(attributeDictionary(font, fontFlags));
165
+ ObjCRef<NSDictionary> attributes(attributeDictionary(font, fontFlags));
166
166
  NSSize size = [string.obj() sizeWithAttributes: attributes.get()];
167
167
  #else
168
168
  CGSize size = [string.obj() sizeWithFont: font];
@@ -8,7 +8,7 @@
8
8
  #include <Gosu/Math.hpp>
9
9
  #include <Gosu/Utility.hpp>
10
10
  #include <Gosu/IO.hpp>
11
- #include "../MacUtility.hpp"
11
+ #include "../AppleUtility.hpp"
12
12
  #include <cmath>
13
13
  #include <stdexcept>
14
14
  #include <map>
@@ -5,7 +5,7 @@
5
5
  #include <pango/pango.h>
6
6
  #include <pango/pangoft2.h>
7
7
  #include <glib.h>
8
- #include <SDL2/SDL_ttf.h>
8
+ #include <SDL_ttf.h>
9
9
 
10
10
  #include <string>
11
11
  #include <cstring>
@@ -0,0 +1,8 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+
4
+ @interface GosuAppDelegate : UIResponder <UIApplicationDelegate>
5
+
6
+ @property (nonatomic, strong) UIWindow *window;
7
+
8
+ @end
@@ -0,0 +1,24 @@
1
+ #import "GosuAppDelegate.h"
2
+ #import <Gosu/Gosu.hpp>
3
+
4
+
5
+ @implementation GosuAppDelegate
6
+
7
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
8
+ {
9
+ self.window = (UIWindow *)windowInstance().UIWindow();
10
+ [self.window makeKeyAndVisible];
11
+
12
+ return YES;
13
+ }
14
+
15
+ @end
16
+
17
+
18
+ int main(int argc, char *argv[])
19
+ {
20
+ @autoreleasepool {
21
+ Gosu::useResourceDirectory();
22
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([GosuAppDelegate class]));
23
+ }
24
+ }
@@ -0,0 +1,8 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+
4
+ @interface GosuGLView : UIView
5
+
6
+ - (void)redrawGL:(void (^)())code;
7
+
8
+ @end
@@ -0,0 +1,130 @@
1
+ #import "GosuGLView.h"
2
+
3
+ #import <QuartzCore/QuartzCore.h>
4
+ #import <OpenGLES/EAGLDrawable.h>
5
+ #import <OpenGLES/EAGL.h>
6
+ #import <OpenGLES/ES1/gl.h>
7
+ #import <OpenGLES/ES1/glext.h>
8
+
9
+
10
+ static EAGLContext __weak *globalContext;
11
+
12
+
13
+ namespace Gosu
14
+ {
15
+ void ensureCurrentContext()
16
+ {
17
+ [EAGLContext setCurrentContext:globalContext];
18
+ }
19
+
20
+ int clipRectBaseFactor()
21
+ {
22
+ static int result = [UIScreen mainScreen].scale;
23
+ return result;
24
+ }
25
+ }
26
+
27
+
28
+ @implementation GosuGLView
29
+ {
30
+ EAGLContext *_context;
31
+
32
+ GLint _backingWidth;
33
+ GLint _backingHeight;
34
+
35
+ GLuint _viewRenderbuffer;
36
+ GLuint _viewFramebuffer;
37
+ }
38
+
39
+ + (Class)layerClass
40
+ {
41
+ return [CAEAGLLayer class];
42
+ }
43
+
44
+ - (id)initWithFrame:(CGRect)frame
45
+ {
46
+ if ((self = [super initWithFrame:frame])) {
47
+ [self initializeGosuGLView];
48
+ }
49
+
50
+ return self;
51
+ }
52
+
53
+ - (id)initWithCoder:(NSCoder *)aDecoder
54
+ {
55
+ if ((self = [super initWithCoder:aDecoder])) {
56
+ [self initializeGosuGLView];
57
+ }
58
+
59
+ return self;
60
+ }
61
+
62
+ - (void)initializeGosuGLView
63
+ {
64
+ CAEAGLLayer *layer = (CAEAGLLayer *)self.layer;
65
+ layer.opaque = YES;
66
+
67
+ globalContext = _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
68
+ [EAGLContext setCurrentContext:_context];
69
+
70
+ self.exclusiveTouch = YES;
71
+ self.multipleTouchEnabled = YES;
72
+ }
73
+
74
+ - (void)dealloc
75
+ {
76
+ [EAGLContext setCurrentContext:nil];
77
+ [_context release];
78
+ [super dealloc];
79
+ }
80
+
81
+ - (void)redrawGL:(void (^)())code
82
+ {
83
+ [EAGLContext setCurrentContext:_context];
84
+
85
+ glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer);
86
+
87
+ glViewport(0, 0, _backingWidth, _backingHeight);
88
+
89
+ if (code) {
90
+ code();
91
+ }
92
+
93
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer);
94
+
95
+ [_context presentRenderbuffer:GL_RENDERBUFFER_OES];
96
+ }
97
+
98
+ - (void)layoutSubviews
99
+ {
100
+ [EAGLContext setCurrentContext:_context];
101
+ [self destroyFramebuffer];
102
+ self.contentScaleFactor = Gosu::clipRectBaseFactor();
103
+ [self createFramebuffer];
104
+ }
105
+
106
+ - (BOOL)createFramebuffer
107
+ {
108
+ glGenFramebuffersOES(1, &_viewFramebuffer);
109
+ glGenRenderbuffersOES(1, &_viewRenderbuffer);
110
+
111
+ glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer);
112
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer);
113
+ [_context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer *)self.layer];
114
+ glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, _viewRenderbuffer);
115
+
116
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &_backingWidth);
117
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &_backingHeight);
118
+
119
+ return (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
120
+ }
121
+
122
+ - (void)destroyFramebuffer
123
+ {
124
+ glDeleteFramebuffersOES(1, &_viewFramebuffer);
125
+ _viewFramebuffer = 0;
126
+ glDeleteRenderbuffersOES(1, &_viewRenderbuffer);
127
+ _viewRenderbuffer = 0;
128
+ }
129
+
130
+ @end