gosu 0.8.7.2 → 0.9.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +29 -0
  3. data/Gosu/Audio.hpp +1 -0
  4. data/Gosu/Font.hpp +8 -4
  5. data/Gosu/Graphics.hpp +28 -18
  6. data/Gosu/GraphicsBase.hpp +17 -13
  7. data/Gosu/Image.hpp +54 -45
  8. data/Gosu/Input.hpp +5 -5
  9. data/Gosu/Version.hpp +3 -3
  10. data/Gosu/Window.hpp +1 -8
  11. data/README.txt +25 -0
  12. data/ext/gosu/gosu_wrap.cxx +1495 -1275
  13. data/ext/gosu/gosu_wrap.h +2 -2
  14. data/lib/gosu/patches.rb +71 -35
  15. data/lib/gosu/preview.rb +9 -142
  16. data/lib/gosu/swig_patches.rb +20 -10
  17. data/rdoc/gosu.rb +1185 -0
  18. data/src/Bitmap/BitmapUtils.cpp +9 -9
  19. data/src/Graphics/Common.hpp +3 -1
  20. data/src/Graphics/Graphics.cpp +100 -38
  21. data/src/Graphics/Image.cpp +57 -15
  22. data/src/Graphics/LargeImageData.cpp +9 -10
  23. data/src/Graphics/LargeImageData.hpp +1 -1
  24. data/src/Graphics/TexChunk.cpp +5 -6
  25. data/src/Graphics/TexChunk.hpp +1 -4
  26. data/src/Graphics/Texture.cpp +10 -3
  27. data/src/Graphics/Texture.hpp +1 -2
  28. data/src/Iconv.hpp +2 -2
  29. data/src/Input/Input.cpp +25 -9
  30. data/src/Input/InputTouch.mm +5 -3
  31. data/src/Text/Font.cpp +13 -8
  32. data/src/Window.cpp +66 -37
  33. data/src/WindowTouch.mm +3 -3
  34. metadata +79 -92
  35. data/examples/ChipmunkIntegration.rb +0 -275
  36. data/examples/CptnRuby.rb +0 -223
  37. data/examples/GosuZen.rb +0 -68
  38. data/examples/MoreChipmunkAndRMagick.rb +0 -155
  39. data/examples/OpenGLIntegration.rb +0 -226
  40. data/examples/RMagickIntegration.rb +0 -417
  41. data/examples/TextInput.rb +0 -154
  42. data/examples/Tutorial.rb +0 -131
  43. data/examples/media/Beep.wav +0 -0
  44. data/examples/media/CptnRuby Gem.png +0 -0
  45. data/examples/media/CptnRuby Map.txt +0 -25
  46. data/examples/media/CptnRuby Tileset.png +0 -0
  47. data/examples/media/CptnRuby.png +0 -0
  48. data/examples/media/Cursor.png +0 -0
  49. data/examples/media/Earth.png +0 -0
  50. data/examples/media/Explosion.wav +0 -0
  51. data/examples/media/Landscape.svg +0 -10
  52. data/examples/media/LargeStar.png +0 -0
  53. data/examples/media/Smoke.png +0 -0
  54. data/examples/media/Soldier.png +0 -0
  55. data/examples/media/Space.png +0 -0
  56. data/examples/media/Star.png +0 -0
  57. data/examples/media/Starfighter.bmp +0 -0
@@ -6,9 +6,8 @@
6
6
  #include <cmath>
7
7
  using namespace std;
8
8
 
9
- Gosu::LargeImageData::LargeImageData(Graphics& graphics,
10
- const Bitmap& source, unsigned partWidth, unsigned partHeight,
11
- unsigned borderFlags)
9
+ Gosu::LargeImageData::LargeImageData(const Bitmap& source,
10
+ unsigned partWidth, unsigned partHeight, unsigned flags)
12
11
  {
13
12
  fullWidth = source.width();
14
13
  fullHeight = source.height();
@@ -32,19 +31,19 @@ Gosu::LargeImageData::LargeImageData(Graphics& graphics,
32
31
  if (y == partsY - 1 && source.height() % partHeight != 0)
33
32
  srcHeight = source.height() % partHeight;
34
33
 
35
- unsigned localBorderFlags = bfTileable;
34
+ unsigned localFlags = ifTileable;
36
35
  if (x == 0)
37
- localBorderFlags = (localBorderFlags & ~bfTileableLeft) | (borderFlags & bfTileableLeft);
36
+ localFlags = (localFlags & ~ifTileableLeft) | (flags & ifTileableLeft);
38
37
  if (x == partsX - 1)
39
- localBorderFlags = (localBorderFlags & ~bfTileableRight) | (borderFlags & bfTileableRight);
38
+ localFlags = (localFlags & ~ifTileableRight) | (flags & ifTileableRight);
40
39
  if (y == 0)
41
- localBorderFlags = (localBorderFlags & ~bfTileableTop) | (borderFlags & bfTileableTop);
40
+ localFlags = (localFlags & ~ifTileableTop) | (flags & ifTileableTop);
42
41
  if (y == partsY - 1)
43
- localBorderFlags = (localBorderFlags & ~bfTileableBottom) | (borderFlags & bfTileableBottom);
42
+ localFlags = (localFlags & ~ifTileableBottom) | (flags & ifTileableBottom);
44
43
 
45
- parts[y * partsX + x].reset(graphics.createImage(source,
44
+ parts[y * partsX + x].reset(Graphics::createImage(source,
46
45
  x * partWidth, y * partHeight, srcWidth, srcHeight,
47
- localBorderFlags).release());
46
+ localFlags).release());
48
47
  }
49
48
  }
50
49
 
@@ -16,7 +16,7 @@ namespace Gosu
16
16
  std::vector<std::tr1::shared_ptr<ImageData> > parts;
17
17
 
18
18
  public:
19
- LargeImageData(Graphics& graphics, const Bitmap& source,
19
+ LargeImageData(const Bitmap& source,
20
20
  unsigned partWidth, unsigned partHeight, unsigned borderFlags);
21
21
 
22
22
  int width() const;
@@ -14,16 +14,15 @@ void Gosu::TexChunk::setTexInfo()
14
14
  info.bottom = (y + h) / textureSize;
15
15
  }
16
16
 
17
- Gosu::TexChunk::TexChunk(Graphics& graphics, DrawOpQueueStack& queues,
18
- std::tr1::shared_ptr<Texture> texture, int x, int y, int w, int h, int padding)
19
- : graphics(graphics), queues(queues), texture(texture), x(x), y(y), w(w), h(h), padding(padding)
17
+ Gosu::TexChunk::TexChunk(std::tr1::shared_ptr<Texture> texture,
18
+ int x, int y, int w, int h, int padding)
19
+ : texture(texture), x(x), y(y), w(w), h(h), padding(padding)
20
20
  {
21
21
  setTexInfo();
22
22
  }
23
23
 
24
24
  Gosu::TexChunk::TexChunk(const TexChunk& parentChunk, int x, int y, int w, int h)
25
- : graphics(parentChunk.graphics), queues(parentChunk.queues), texture(parentChunk.texture),
26
- x(parentChunk.x + x), y(parentChunk.y + y), w(w), h(h), padding(0)
25
+ : texture(parentChunk.texture), x(parentChunk.x + x), y(parentChunk.y + y), w(w), h(h), padding(0)
27
26
  {
28
27
  setTexInfo();
29
28
  texture->block(this->x, this->y, this->w, this->h);
@@ -63,7 +62,7 @@ void Gosu::TexChunk::draw(double x1, double y1, Color c1,
63
62
  op.bottom = info.bottom;
64
63
 
65
64
  op.z = z;
66
- queues.back().scheduleDrawOp(op);
65
+ Graphics::scheduleDrawOp(op);
67
66
  }
68
67
 
69
68
  const Gosu::GLTexInfo* Gosu::TexChunk::glTexInfo() const
@@ -11,8 +11,6 @@
11
11
 
12
12
  class Gosu::TexChunk : public Gosu::ImageData
13
13
  {
14
- Graphics& graphics;
15
- DrawOpQueueStack& queues;
16
14
  std::tr1::shared_ptr<Texture> texture;
17
15
  int x, y, w, h, padding;
18
16
 
@@ -22,8 +20,7 @@ class Gosu::TexChunk : public Gosu::ImageData
22
20
  void setTexInfo();
23
21
 
24
22
  public:
25
- TexChunk(Graphics& graphics, DrawOpQueueStack& queues,
26
- std::tr1::shared_ptr<Texture> texture, int x, int y, int w, int h, int padding);
23
+ TexChunk(std::tr1::shared_ptr<Texture> texture, int x, int y, int w, int h, int padding);
27
24
  TexChunk(const TexChunk& parentChunk, int x, int y, int w, int h);
28
25
  ~TexChunk();
29
26
 
@@ -13,6 +13,8 @@ namespace Gosu
13
13
  Gosu::Texture::Texture(unsigned size)
14
14
  : allocator(size, size)
15
15
  {
16
+ ensureCurrentContext();
17
+
16
18
  // Create texture name.
17
19
  glGenTextures(1, &name);
18
20
  if (name == static_cast<GLuint>(-1))
@@ -50,6 +52,8 @@ Gosu::Texture::Texture(unsigned size)
50
52
 
51
53
  Gosu::Texture::~Texture()
52
54
  {
55
+ ensureCurrentContext();
56
+
53
57
  glDeleteTextures(1, &name);
54
58
  }
55
59
 
@@ -64,8 +68,7 @@ GLuint Gosu::Texture::texName() const
64
68
  }
65
69
 
66
70
  GOSU_UNIQUE_PTR<Gosu::TexChunk>
67
- Gosu::Texture::tryAlloc(Graphics& graphics, DrawOpQueueStack& queues,
68
- std::tr1::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding)
71
+ Gosu::Texture::tryAlloc(std::tr1::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding)
69
72
  {
70
73
  GOSU_UNIQUE_PTR<Gosu::TexChunk> result;
71
74
 
@@ -73,9 +76,11 @@ GOSU_UNIQUE_PTR<Gosu::TexChunk>
73
76
  if (!allocator.alloc(bmp.width(), bmp.height(), block))
74
77
  return result;
75
78
 
76
- result.reset(new TexChunk(graphics, queues, ptr, block.left + padding, block.top + padding,
79
+ result.reset(new TexChunk(ptr, block.left + padding, block.top + padding,
77
80
  block.width - 2 * padding, block.height - 2 * padding, padding));
78
81
 
82
+ ensureCurrentContext();
83
+
79
84
  glBindTexture(GL_TEXTURE_2D, name);
80
85
  glTexSubImage2D(GL_TEXTURE_2D, 0, block.left, block.top, block.width, block.height,
81
86
  Color::GL_FORMAT, GL_UNSIGNED_BYTE, bmp.data());
@@ -98,6 +103,8 @@ Gosu::Bitmap Gosu::Texture::toBitmap(unsigned x, unsigned y, unsigned width, uns
98
103
  #ifdef GOSU_IS_OPENGLES
99
104
  throw std::logic_error("Texture::toBitmap not supported on iOS");
100
105
  #else
106
+ ensureCurrentContext();
107
+
101
108
  Gosu::Bitmap fullTexture(size(), size());
102
109
  glBindTexture(GL_TEXTURE_2D, name);
103
110
  glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, fullTexture.data());
@@ -22,8 +22,7 @@ namespace Gosu
22
22
  unsigned size() const;
23
23
  GLuint texName() const;
24
24
  GOSU_UNIQUE_PTR<TexChunk>
25
- tryAlloc(Graphics& graphics, DrawOpQueueStack& queues,
26
- std::tr1::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding);
25
+ tryAlloc(std::tr1::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding);
27
26
  void block(unsigned x, unsigned y, unsigned width, unsigned height);
28
27
  void free(unsigned x, unsigned y, unsigned width, unsigned height);
29
28
  Gosu::Bitmap toBitmap(unsigned x, unsigned y, unsigned width, unsigned height) const;
@@ -1,5 +1,5 @@
1
- #ifndef GOSIMPL_ICONV_HPP
2
- #define GOSIMPL_ICONV_HPP
1
+ #ifndef GOSUIMPL_ICONV_HPP
2
+ #define GOSUIMPL_ICONV_HPP
3
3
 
4
4
  #include <Gosu/Platform.hpp>
5
5
 
@@ -3,14 +3,30 @@
3
3
  #include <Gosu/TR1.hpp>
4
4
  #include <Gosu/Utility.hpp>
5
5
  #include <SDL2/SDL.h>
6
- #include <algorithm>
7
6
  #include <cwctype>
7
+ #include <cstdlib>
8
+ #include <algorithm>
9
+
10
+ namespace
11
+ {
12
+ void requireSDLVideo()
13
+ {
14
+ static bool initializedSDLVideo = false;
15
+ if (!initializedSDLVideo)
16
+ {
17
+ SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER);
18
+ std::atexit(SDL_Quit);
19
+ initializedSDLVideo = true;
20
+ }
21
+ }
22
+
23
+ std::tr1::array<bool, Gosu::numButtons> buttonStates { { false } };
24
+ }
8
25
 
9
26
  struct Gosu::Input::Impl
10
27
  {
11
28
  Input& input;
12
29
  TextInput* textInput;
13
- std::tr1::array<bool, Gosu::numButtons> buttonStates;
14
30
  double mouseX, mouseY;
15
31
  double mouseFactorX, mouseFactorY;
16
32
  double mouseOffsetX, mouseOffsetY;
@@ -18,8 +34,6 @@ struct Gosu::Input::Impl
18
34
  Impl(Input& input)
19
35
  : input(input), textInput(NULL)
20
36
  {
21
- std::fill(buttonStates.begin(), buttonStates.end(), false);
22
-
23
37
  mouseFactorX = mouseFactorY = 1;
24
38
  mouseOffsetX = mouseOffsetY = 0;
25
39
  }
@@ -225,7 +239,7 @@ private:
225
239
  Gosu::Input::Input()
226
240
  : pimpl(new Impl(*this))
227
241
  {
228
- SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
242
+ requireSDLVideo();
229
243
 
230
244
  pimpl->initializeGamepads();
231
245
  }
@@ -233,8 +247,6 @@ Gosu::Input::Input()
233
247
  Gosu::Input::~Input()
234
248
  {
235
249
  pimpl->releaseGamepads();
236
-
237
- SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
238
250
  }
239
251
 
240
252
  bool Gosu::Input::feedSDLEvent(void* event)
@@ -281,6 +293,8 @@ bool Gosu::Input::feedSDLEvent(void* event)
281
293
 
282
294
  wchar_t Gosu::Input::idToChar(Button btn)
283
295
  {
296
+ requireSDLVideo();
297
+
284
298
  if (btn.id() > kbRangeEnd)
285
299
  return 0;
286
300
 
@@ -312,6 +326,8 @@ wchar_t Gosu::Input::idToChar(Button btn)
312
326
 
313
327
  Gosu::Button Gosu::Input::charToId(wchar_t ch)
314
328
  {
329
+ requireSDLVideo();
330
+
315
331
  std::wstring string(1, ch);
316
332
  SDL_Keycode keycode = SDL_GetKeyFromName(wstringToUTF8(string).c_str());
317
333
 
@@ -323,12 +339,12 @@ Gosu::Button Gosu::Input::charToId(wchar_t ch)
323
339
  }
324
340
  }
325
341
 
326
- bool Gosu::Input::down(Gosu::Button btn) const
342
+ bool Gosu::Input::down(Gosu::Button btn)
327
343
  {
328
344
  if (btn == noButton || btn.id() >= numButtons)
329
345
  return false;
330
346
 
331
- return pimpl->buttonStates[btn.id()];
347
+ return buttonStates[btn.id()];
332
348
  }
333
349
 
334
350
  double Gosu::Input::mouseX() const
@@ -2,7 +2,7 @@
2
2
  #include <Gosu/TextInput.hpp>
3
3
 
4
4
  #include "MacUtility.hpp"
5
- #include "Input/AccelerometerReader.hpp"
5
+ #include "AccelerometerReader.hpp"
6
6
  #import <UIKit/UIKit.h>
7
7
 
8
8
  struct Gosu::TextInput::Impl {};
@@ -26,7 +26,7 @@ struct Gosu::Input::Impl
26
26
  Touch translateTouch(UITouch* uiTouch)
27
27
  {
28
28
  CGPoint point = [uiTouch locationInView: view];
29
- Touch touch = { uiTouch, point.x, point.y };
29
+ Touch touch = { uiTouch, (float)point.x, (float)point.y };
30
30
  touch.x *= factorX, touch.y *= factorY;
31
31
  return touch;
32
32
  }
@@ -100,9 +100,11 @@ void Gosu::Input::setMousePosition(double x, double y) {
100
100
  pimpl->mouseY = y;
101
101
  }
102
102
 
103
- void Gosu::Input::setMouseFactors(double factorX, double factorY) {
103
+ void Gosu::Input::setMouseFactors(double factorX, double factorY, double offsetX, double offsetY) {
104
104
  pimpl->factorX = factorX;
105
105
  pimpl->factorY = factorY;
106
+
107
+ // TODO - use offset
106
108
  }
107
109
 
108
110
  const Gosu::Touches& Gosu::Input::currentTouches() const
@@ -12,7 +12,6 @@ using namespace std;
12
12
 
13
13
  struct Gosu::Font::Impl
14
14
  {
15
- Graphics* graphics;
16
15
  wstring name;
17
16
  unsigned height, flags;
18
17
 
@@ -49,7 +48,7 @@ struct Gosu::Font::Impl
49
48
  {
50
49
  tr1::shared_ptr<Image>& ptr = entityCache[fs.entityAt(i)];
51
50
  if (!ptr)
52
- ptr.reset(new Image(*graphics, entityBitmap(fs.entityAt(i)), false));
51
+ ptr.reset(new Image(entityBitmap(fs.entityAt(i)), ifSmooth));
53
52
  return *ptr;
54
53
  }
55
54
 
@@ -68,7 +67,7 @@ struct Gosu::Font::Impl
68
67
 
69
68
  Bitmap bitmap(charWidth, height);
70
69
  drawText(bitmap, charString, 0, 0, Color::WHITE, name, height, flags);
71
- info.image.reset(new Image(*graphics, bitmap));
70
+ info.image.reset(new Image(bitmap));
72
71
  info.factor = 0.5;
73
72
  return *info.image;
74
73
  }
@@ -81,11 +80,9 @@ struct Gosu::Font::Impl
81
80
  }
82
81
  };
83
82
 
84
- Gosu::Font::Font(Graphics& graphics, const wstring& fontName, unsigned fontHeight,
85
- unsigned fontFlags)
83
+ Gosu::Font::Font(unsigned fontHeight, const wstring& fontName, unsigned fontFlags)
86
84
  : pimpl(new Impl)
87
85
  {
88
- pimpl->graphics = &graphics;
89
86
  pimpl->name = fontName;
90
87
  pimpl->height = fontHeight * 2;
91
88
  pimpl->flags = fontFlags;
@@ -164,7 +161,15 @@ void Gosu::Font::setImage(wchar_t wc, unsigned fontFlags, const Image& image)
164
161
  void Gosu::Font::drawRot(const wstring& text, double x, double y, ZPos z, double angle,
165
162
  double factorX, double factorY, Color c, AlphaMode mode) const
166
163
  {
167
- pimpl->graphics->pushTransform(rotate(angle, x, y));
164
+ Gosu::Graphics::pushTransform(rotate(angle, x, y));
168
165
  draw(text, x, y, z, factorX, factorY, c, mode);
169
- pimpl->graphics->popTransform();
166
+ Gosu::Graphics::popTransform();
167
+ }
168
+
169
+ // Deprecated constructors
170
+
171
+ Gosu::Font::Font(Graphics& graphics, const wstring& fontName, unsigned fontHeight,
172
+ unsigned fontFlags)
173
+ {
174
+ Font(fontHeight, fontName, fontFlags).pimpl.swap(pimpl);
170
175
  }
@@ -1,4 +1,5 @@
1
1
  #include <Gosu/Gosu.hpp>
2
+ #include "Graphics/Common.hpp"
2
3
  #include <SDL2/SDL.h>
3
4
  #include <cstdlib>
4
5
  #include <memory>
@@ -18,12 +19,56 @@ namespace Gosu
18
19
  const char *error = SDL_GetError();
19
20
  throw std::runtime_error(operation + ": " + (error ? error : "(unknown error)"));
20
21
  }
22
+
23
+ SDL_Window* sharedWindow()
24
+ {
25
+ static SDL_Window *window = 0;
26
+ if (window == 0)
27
+ {
28
+ if (SDL_Init(SDL_INIT_VIDEO) < 0)
29
+ throwSDLError("Could not initialize SDL Video");
30
+
31
+ atexit(SDL_Quit);
32
+
33
+ Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
34
+
35
+ #if SDL_VERSION_ATLEAST(2, 0, 1)
36
+ flags |= SDL_WINDOW_ALLOW_HIGHDPI;
37
+ #endif
38
+
39
+ window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64, flags);
40
+ if (window == 0)
41
+ throwSDLError("Could not create window");
42
+ }
43
+ return window;
44
+ }
45
+
46
+ SDL_GLContext sharedGLContext()
47
+ {
48
+ static SDL_GLContext context = 0;
49
+ if (context == 0)
50
+ {
51
+ #ifdef GOSU_IS_OPENGLES
52
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
53
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
54
+ #endif
55
+
56
+ context = SDL_GL_CreateContext(sharedWindow());
57
+
58
+ if (context == 0)
59
+ throwSDLError("Could not create OpenGL context");
60
+ }
61
+ return context;
62
+ }
63
+
64
+ void ensureCurrentContext()
65
+ {
66
+ SDL_GL_MakeCurrent(sharedWindow(), sharedGLContext());
67
+ }
21
68
  }
22
69
 
23
70
  struct Gosu::Window::Impl
24
71
  {
25
- SDL_Window *window;
26
- SDL_GLContext context;
27
72
  double updateInterval;
28
73
 
29
74
  std::auto_ptr<Graphics> graphics;
@@ -33,8 +78,6 @@ struct Gosu::Window::Impl
33
78
  Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double updateInterval)
34
79
  : pimpl(new Impl)
35
80
  {
36
- if (SDL_Init(SDL_INIT_VIDEO) < 0)
37
- throwSDLError("Could not initialize SDL Video");
38
81
 
39
82
  int actualWidth = width;
40
83
  int actualHeight = height;
@@ -68,34 +111,22 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double up
68
111
  }
69
112
  }
70
113
 
71
- Uint32 flags = SDL_WINDOW_OPENGL;
72
- #if SDL_VERSION_ATLEAST(2, 0, 1)
73
- flags |= SDL_WINDOW_ALLOW_HIGHDPI;
74
- #endif
75
- if (fullscreen) {
76
- flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
77
- }
78
-
79
- pimpl->window = SDL_CreateWindow("",
80
- SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
81
- actualWidth, actualHeight, flags);
82
- if (! pimpl->window)
83
- throwSDLError("Could not open window");
84
-
85
- #ifdef GOSU_IS_OPENGLES
86
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
87
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
88
- #endif
89
-
90
- #if SDL_VERSION_ATLEAST(2, 0, 1)
91
- SDL_GL_GetDrawableSize(pimpl->window, &actualWidth, &actualHeight);
92
- #endif
114
+ // TODO - it would be better/enough to only do this in show()
93
115
 
94
- pimpl->context = SDL_GL_CreateContext(pimpl->window);
95
- if (! pimpl->context)
96
- throwSDLError("Could not create OpenGL context");
116
+ SDL_SetWindowTitle(sharedWindow(), "");
117
+ SDL_SetWindowSize(sharedWindow(), actualWidth, actualHeight);
118
+ SDL_SetWindowPosition(sharedWindow(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
119
+ if (fullscreen)
120
+ {
121
+ SDL_SetWindowFullscreen(sharedWindow(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
122
+ }
123
+ SDL_ShowWindow(sharedWindow());
124
+
125
+ #if SDL_VERSION_ATLEAST(2, 0, 1)
126
+ SDL_GL_GetDrawableSize(sharedWindow(), &actualWidth, &actualHeight);
127
+ #endif
97
128
 
98
- SDL_GL_MakeCurrent(pimpl->window, pimpl->context);
129
+ ensureCurrentContext();
99
130
  SDL_GL_SetSwapInterval(1);
100
131
 
101
132
  pimpl->graphics.reset(new Graphics(actualWidth, actualHeight, fullscreen));
@@ -109,21 +140,18 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double up
109
140
 
110
141
  Gosu::Window::~Window()
111
142
  {
112
- SDL_GL_DeleteContext(pimpl->context);
113
- SDL_DestroyWindow(pimpl->window);
114
-
115
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
143
+ SDL_HideWindow(sharedWindow());
116
144
  }
117
145
 
118
146
  std::wstring Gosu::Window::caption() const
119
147
  {
120
- return utf8ToWstring(SDL_GetWindowTitle(pimpl->window));
148
+ return utf8ToWstring(SDL_GetWindowTitle(sharedWindow()));
121
149
  }
122
150
 
123
151
  void Gosu::Window::setCaption(const std::wstring& caption)
124
152
  {
125
153
  std::string utf8 = wstringToUTF8(caption);
126
- SDL_SetWindowTitle(pimpl->window, utf8.c_str());
154
+ SDL_SetWindowTitle(sharedWindow(), utf8.c_str());
127
155
  }
128
156
 
129
157
  double Gosu::Window::updateInterval() const
@@ -162,13 +190,14 @@ void Gosu::Window::show()
162
190
  SDL_ShowCursor(needsCursor());
163
191
 
164
192
  if (needsRedraw()) {
193
+ ensureCurrentContext();
165
194
  if (graphics().begin()) {
166
195
  draw();
167
196
  graphics().end();
168
197
  FPS::registerFrame();
169
198
  }
170
199
 
171
- SDL_GL_SwapWindow(pimpl->window);
200
+ SDL_GL_SwapWindow(sharedWindow());
172
201
 
173
202
  if (GosusDarkSide::oncePerTick) GosusDarkSide::oncePerTick();
174
203
  }