From 2627c3579fd51f96d3bb286f9980b9a3fece6b16 Mon Sep 17 00:00:00 2001 From: Jonathan De Wachter Date: Sun, 29 Dec 2013 20:22:07 +0100 Subject: [PATCH] Forgot to initialize the EGL display --- src/SFML/Window/EglContext.cpp | 33 +++++++++++++++++++++++++++-- src/SFML/Window/Unix/GlxContext.cpp | 2 +- src/SFML/Window/iOS/EaglContext.mm | 2 +- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/SFML/Window/EglContext.cpp b/src/SFML/Window/EglContext.cpp index 093fc6fd2..bc7ecb91c 100644 --- a/src/SFML/Window/EglContext.cpp +++ b/src/SFML/Window/EglContext.cpp @@ -36,6 +36,35 @@ #include #endif +namespace +{ + EGLDisplay getInitializedDisplay() + { +#if defined(SFML_SYSTEM_LINUX) + + static EGLDisplay display = EGL_NO_DISPLAY; + + if (display == EGL_NO_DISPLAY) + { + eglCheck(eglGetDisplay(EGL_DEFAULT_DISPLAY)); + eglCheck(eglInitialize(display, NULL, NULL)); + } + + return display; + +#elif defined(SFML_SYSTEM_ANDROID) + + // On Android, its native activity handles this for us + sf::priv::ActivityStates* states = sf::priv::getActivity(NULL); + sf::Lock lock(states->mutex); + + return states->display; + +#endif + } +} + + namespace sf { namespace priv @@ -47,7 +76,7 @@ m_context (EGL_NO_CONTEXT), m_surface (EGL_NO_SURFACE) { // Get the intialized EGL display - m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + m_display = getInitializedDisplay(); // Create the EGL surface const EGLint attribs[] = { @@ -90,7 +119,7 @@ m_surface (EGL_NO_SURFACE) #endif // Get the intialized EGL display - m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + m_display = getInitializedDisplay(); // Create the EGL surface const EGLint attribs[] = { diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index 405c57a8a..a5c91df39 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -165,7 +165,7 @@ XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPe XVisualInfo* visuals = XGetVisualInfo(display, 0, NULL, &count); if (visuals) { - // Evaluate all the returned visuals, and pick the best one1 + // Evaluate all the returned visuals, and pick the best one int bestScore = 0xFFFF; XVisualInfo bestVisual; for (int i = 0; i < count; ++i) diff --git a/src/SFML/Window/iOS/EaglContext.mm b/src/SFML/Window/iOS/EaglContext.mm index 9ce0c0e5f..758bbac21 100644 --- a/src/SFML/Window/iOS/EaglContext.mm +++ b/src/SFML/Window/iOS/EaglContext.mm @@ -83,7 +83,7 @@ m_depthbuffer (0), m_vsyncEnabled(false), m_clock () { - // This constructor shoult never be used by implementation + // This constructor should never be used by implementation err() << "Calling bad EaglContext constructor, please contact your developer :)" << std::endl; }